Skip navigation

JSI Tip 5346. How do I retrieve a user's ProfileImagePath in batch?


When a user logs onto a Windows NT-based computer (Windows NT 4.0, Windows 2000, and Windows XP),
their local profile is stored at the location specified in the registry at:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\<SID>\ProfileImagePath.

I used this information to allow a user to:

use their domain profile while logged on locally to Windows 2000 or Windows XP

use their domain profile while logged on locally to Windows NT 4.0

to make a program available to all users

to recovery a lost local profile.

Microsoft used this information to alter the location of the user's local profile.

Using REG.EXE on Windows 2000, from the Windows 2000 Support Tools, or REG.EXE built into Windows XP,
and UserSID.bat, I have scripted ProfileImagePath.bat, to retrieve the location of a user's local profile.
The syntax for using ProfileImagePath.bat is:

call profileimagepath \\DC_or_Local UserName \\Local_Computer

where:

\\DC_or_Local is either a domain controller, if you want the domain SID, or the local workstation, if the UserName is local.

UserName is the User Account whose SID you want.

\\Local_Computer is the local computer that contains the user profile.

ProfileImagePath.bat returns the ProfileImagePath environment variable, %ProfileImagePath%.

ProfileImagePath.bat contains:

@echo off
If \{%3\}==\{\} goto syntax
if not exist %1\c$ goto syntax
if not exist %3\c$ goto syntax
call UserSid %1 %2
for /f "Skip=3 Tokens=2*" %%i in ('reg QUERY "%3\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\%sid%" /v ProfileImagePath') do set ProfileImagePath=%%j
goto :EOF
:syntax
@echo Syntax call ProfileImagePath \\DC_or_Local UserName Local_Computer
NOTE: If you wanted to change the location of the local profile, you would:
reg ADD "\\Local_Computer\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\%sid%" /v ProfileImagePath /t REG_EXPAND_SZ /d "<new location>" /f>nul 2>&1


Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish