Q. How can a batch determine if the current user is using a temporary profile?

Using REG.EXE, built into Windows XP, Windows Server 2003, Windows Vista, and later operating systems, or installed from the Windows 2000 Support Tools, information from tip 11125 ยป What is the meaning the State Value Name in a user's registry profile, and GetUserSID.bat, I have scripted IsProfileTemp.bat to determine if the current user has logged on with a temporary profile.

The syntax for using IsProfileTemp.bat is:

\[call\] IsProfileTemp YorN

Where YorN is a call directed environment variable that will contain a Y if the current user's profile is temporary, or an N if it is not temporary.

IsProfileTemp.bat contains:

@echo off
if \{%1\}==\{\} @echo Syntax: IsProfileTemp YorN&goto :EOF
setlocal
set YorN=Y
call GetUserSID SID
if "%SID%" EQU "NONE" goto finish
set key="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\%SID%"
set /a State=0x800
for /f "Tokens=2*" %%a in ('reg query %key% /V State^|find "REG_DWORD"') do (
 set /a State=%%b
)
set /a ans="%state%&0x800"
if %ans% NEQ 2048 set YorN=N
:finish
endlocal&set %1=%YorN%


Please or Register to post comments.

Upcoming Training

Mastering System Center 2012

During over 6 hours of training you can join John Savill from your computer as he will walk you through the key components and capabilities of System Center 2012, what’s involved in using the components, and the benefit they can bring to your environment.

Register Now

Current Issue

May 2013 - The NameTranslate object is useful when you need to translate Active Directory object names between different formats, but it's awkward to use from PowerShell. Here's a PowerShell script that eliminates the awkwardness.

CURRENT ISSUE / ARCHIVE / SUBSCRIBE

Windows Forums

Get answers to questions, share tips, and engage with the Windows Community in our Forums.