Page 1 of 1 1
Topic Options
#166046 - 2006-08-17 02:47 PM Determine Profile Path
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 686
Loc: Maryland, USA
Hi everyone! I appologize if this is available somewhere, but I've searched and just can't seem to find it.

Given a domain name and a SID, I'm trying to determine how to retrieve the profile path of that user in that domain.

If anyone has any ideas, I'd appreciate hearing them!

Thanks!

Top
#166047 - 2006-08-17 03:10 PM Re: Determine Profile Path
Benny69 Offline
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%
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#166048 - 2006-08-17 03:54 PM Re: Determine Profile Path
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 686
Loc: Maryland, USA
The user isn't logged in. I'm trying to right some scripts to assist a help desk. An example would be if a user's profile was corrupt and needed to be rebuilt and they had no idea what printers or persistent network connections they had. I want to retrieve their profile path so that I may grab their ntuser.dat file and temporarily mount it to the local registry and access their printer and drive mapping information.

Does that make a little more sense?

Top
#166049 - 2006-08-17 04:36 PM Re: Determine Profile Path
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Not sure where and why the domain name comes into play but the SIDtoName() function should translate the SID based on current domain and trusts. From there a simple LDAP query should get you the path.
Top
#166050 - 2006-08-17 05:02 PM Re: Determine Profile Path
BradV Offline
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 Offline
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 Offline
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
#166053 - 2006-08-17 05:52 PM Re: Determine Profile Path
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Hmmm... I never thought of using the WinNT provider.
Top
#166054 - 2006-08-17 06:01 PM Re: Determine Profile Path
sixdoubleo Offline
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
#166055 - 2006-08-17 06:16 PM Re: Determine Profile Path
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Well... I am so used to pulling stuff from AD using LDAP queries that I usually have the DN in hand anyway. There are so many things that LDAP can do that WinNT cannot even if this is not one of them.
Top
#166056 - 2006-08-17 07:28 PM Re: Determine Profile Path
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 686
Loc: Maryland, USA
The WinNT works fine! I'll have to try the LDAP implementation also.

Thanks!!!!

Top
#166057 - 2006-08-17 10:54 PM Re: Determine Profile Path
ChristopheM Offline
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 Offline
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
#166059 - 2006-08-18 01:23 PM Re: Determine Profile Path
ChristopheM Offline
Hey THIS is FUN
*****

Registered: 2002-05-13
Posts: 309
Loc: STRASBOURG, France
OK for theses points but %userprofile% can be used only in the user context.

first point : if you want to do something remotely, %userprofile% is YOUR profile, not the user's one.
second point : BradV said that the user is not logged on so there is no %userprofile% !!!
third point : to modify the roaming profile, it is absolute necessary to be sure that the user is not logged on because if he is, when he disconnects, the local profile is reloaded to the central point and remote modifications are overwritten !!!
_________________________
Christophe

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 466 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.064 seconds in which 0.025 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org