#166047 - 2006-08-17 03:10 PM
Re: Determine Profile Path
|
Benny69
Moderator
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
not sure why you would need the domain or sid, is there a reason you can't use %UserProfile%
|
Top
|
|
|
|
#166050 - 2006-08-17 05:02 PM
Re: Determine Profile Path
|
BradV
Seasoned Scripter
Registered: 2006-08-16
Posts: 686
Loc: Maryland, USA
|
Thanks for he reply Les. I guess I should have been more precise.
I incorrectly used SID. At my current location "SID" means login name. The domain comes into effect since this site had many domains. I can determine a login server given the domain, I'm just trying to figure out from there how to determine the server and share where the user's profile resides given his login name.
Thanks!
|
Top
|
|
|
|
#166051 - 2006-08-17 05:40 PM
Re: Determine Profile Path
|
sixdoubleo
Starting to like KiXtart
Registered: 2004-02-06
Posts: 118
Loc: California, US
|
I assume you're referring to the users ROAMING profile path as opposed to their local profile path.
Use something like this...
$objUser = GetObject("WinNT://MyDomain/BJones,user") ? $objUser.Profile
If all you need is the profile path, this method is fine. If you plan to read/manipulate various Active Directory attributes, you'll want to use "LDAP://" calls rather than the WinNT:// calls.
|
Top
|
|
|
|
#166052 - 2006-08-17 05:50 PM
Re: Determine Profile Path
|
Les
KiX Master
Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
|
OK, then given Domain\UserID you can translate that to LDAP nomenclature and then using LDAP, query it from AD. I presume there are trusts between domains.
I slightly modified Howard's TranslateName()UDF to use an optional parm being UserID and with that I can pull the details I want from AD. I don't use profiles so cannot provide tested code but here is an untested example of pulling profilepath. Code:
BREAK ON $users = GetObject("LDAP://ou=Users,ou=bla,ou=bla,dc=yada,dc=local") $Users.filter = Split('user')
for each $user in $users if $user.profilepath <> "" ? "Current path for " +$user.name " is: " +$user.profilepath endif next
|
Top
|
|
|
|
#166054 - 2006-08-17 06:01 PM
Re: Determine Profile Path
|
sixdoubleo
Starting to like KiXtart
Registered: 2004-02-06
Posts: 118
Loc: California, US
|
Quote:
Hmmm... I never thought of using the WinNT provider.
Yeah "Profile" was a supported attribute in the NT Domain world so it's part of the user object...AD or NT. I haven't had any problems reading it with WinNT:// and for a quick lookup without having to grab DN's and whatnot, I usually try to use it.
But if I was going to WRITE it, I think I'd go through LDAP. I have no basis for this suggestion other than "it would make me feel better".
|
Top
|
|
|
|
#166057 - 2006-08-17 10:54 PM
Re: Determine Profile Path
|
ChristopheM
Hey THIS is FUN
Registered: 2002-05-13
Posts: 309
Loc: STRASBOURG, France
|
I am not sure that the .profile property is correct in any case !!!
suppose the following situation :
- a user called "userID"
- an NT workstation with NT installed in c:\winnt
- an XP workstation with XP installed in c:\windows
if the user connects on the NT workstation, usually, the profile is c:\winnt\profiles\userID. if the user connects on the XP workstation, usually, the profile is c:\documents and settings\userID.
now, suppose that a local account also called userID exist on each workstation and connects before the domain account, when the domain account connects, the profile can be c:\winnt\profiles\userid.001, c:\documents and settings\userid. or something else.
with all theses cases, i don't think that the WINNT provider gives a good answer in any cases.
to detect a user profile on a workstation, you need the user's SID and the computername. Then, look at the registry key : \\computername\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\. If this key exists, read the value ProfileImagePath and now you have the local user's profile.
_________________________
Christophe
|
Top
|
|
|
|
#166058 - 2006-08-17 11:00 PM
Re: Determine Profile Path
|
sixdoubleo
Starting to like KiXtart
Registered: 2004-02-06
Posts: 118
Loc: California, US
|
Quote:
I am not sure that the .profile property is correct in any case !!!
suppose the following situation :
- a user called "userID"
- an NT workstation with NT installed in c:\winnt
- an XP workstation with XP installed in c:\windows
if the user connects on the NT workstation, usually, the profile is c:\winnt\profiles\userID. if the user connects on the XP workstation, usually, the profile is c:\documents and settings\userID.
now, suppose that a local account also called userID exist on each workstation and connects before the domain account, when the domain account connects, the profile can be c:\winnt\profiles\userid.001, c:\documents and settings\userid.<domain> or something else.
with all theses cases, i don't think that the WINNT provider gives a good answer in any cases.
to detect a user profile on a workstation, you need the user's SID and the computername. Then, look at the registry key : \\computername\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\<sid>. If this key exists, read the value ProfileImagePath and now you have the local user's profile.
Good points.
However, you must differentiate whether you're looking for the user's roaming profile or the local profile. In this particular case, BradV is looking for the roaming profile. In that case, WinNT or LDAP will return the correct roaming profile.
Now, if you're looking to know the location of the user's LOCAL profile, it seems to me you'd almost always be working within the context of the user's logon. In which case you simply use the %USERPROFILE% environment variable. It always returns the correct dirctory regardless of OS version, duplicate account names, etc.
You don't even worry about c:\winnt, c:\documents and settings, SIDs, .001's, .002's, and so on.
So if you're wanting to drop something on the current user's desktop, it's always COPY $MyShortcut %USERPROFILE%\Desktop (or whatever).
(Unless of course you're not dealing with the CURRENT user. But any time I'm dealing with profiles offline, it's always the roaming. Although I do have a desktop cleanup script for cleaning copies of unused local profiles where I used a technique similar to yours. I don't think that's what the OP wanted though. I could be wrong.)
Edited by sixdoubleo (2006-08-17 11:27 PM)
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 466 anonymous users online.
|
|
|