JSI Tip 6360. How can I remove old profiles from my workstations?

If your users have roaming profiles, you can cause the locally cached copy of their profile to be deleted when the user logs off. You can implement either of the following to accomplish this:

How do I use Group Policy to delete locally cached copies of roaming profiles?

Roaming profiles consume disk space.

If you didn't initially configure any of the above, you may have some locally cached copies on your hard disk. You can use Delprof.exe to delete these locally cached profiles.

If your users don't have roaming profiles, a local profile is created when a user logs on. If many users log on to a workstation, these profile accumulate over time. In a computer lab environment, you can have hundreds of profiles that may never be used again.

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

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\\ProfileImagePath.

Using REG.EXE on Windows 2000, from the Windows 2000 Support Tools, or REG.EXE built into Windows XP, and JSIDateM, the general purpose date math routine, I have scripted DelProfile.bat to remove old profiles. The general syntax for using DelProfile.bat is:

DelProfile Age \[KeepUserName\]


Age is the number of days since the user logged on. If the profile access date is newer than Today - Age, it will not be deleted. Age may be 0, but leading zeros in the number of days is not allowed. If a user logged on 10 days ago and hasn't logged off, an Age of 10 would delete their profile. Dates are assumed to be in the MM/DD/YYYY format.

KeepUserName is an optional parameter that specifies a UserName that should not be deleted.

NOTE: Built-in user names are not deleted, nor are IIS's IUSER_xxxxx and IWAMxxxxx accounts.

NOTE: You run DelProfile.bat on the workstation you wish to clean up, or you can use tip 4195 on your workstation to run it for all the workstations in your domain, or you can use PsExec on your workstation to run it for specific workstations in your domain or peer-to-peer network.

DelPofile.bat contains:

@echo off
set keep=$$$$$$$$
if \{%1\}

\{\} goto syntax set older=%1 if "%older%" EQU "0" goto OK if "%older:~0,1%" LEQ "0" goto syntax if "%older:~0,1%" GTR "9" goto syntax :OK if not \{%2\}

\{\} set keep=%2 set bypass=N set pipkey=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileListregedit /a %TEMP%\profilelist.reg "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\ProfileList" set today=%date% if "%today:~0,1%" GTR "9" set today=%date:~4% set today=%today:/=% set today=%today:~4,4%%today:~0,4% set todayyy=%today:~0,4% set todaymm=%today:~4,2% set todaydd=%today:~6,2% call jsidatem %todayyy% %todaymm% %todaydd% - %older% for /f "Skip=5 Tokens=7 Delims=\\]" %%a in ('type %TEMP%\profilelist.reg') do set sid=%%a&call :getpip endlocal goto :EOF :syntax @echo Syntax: DelProfile NNdays \[KeepUserName\] endlocal goto :EOF :IIIS set bypass=N If /i %1 EQU "%keep%" set bypass=Y&goto :EOF set param=%1 set param=%param:"=% If "%param:~0,5%" EQU "IUSR_" set bypass=Y&goto :EOF If "%param:~0,5%" EQU "IWAM_" set bypass=Y&goto :EOF goto :EOF :getpip for /f "Tokens=8 Delims=-" %%b in ('@echo %sid%') do set admin=%%b if "%admin%"

"" goto :EOF if "%admin%"

"500" goto :EOF for /f "Skip=3 Tokens=2*" %%b in ('reg QUERY "%pipkey%%sid%" /v ProfileImagePath') do call set pip=%%c for /f "Tokens=2-5 Delims=\" %%b in ('@echo %pip%') do set usr1=%%b&set usr2=%%c&set usr3=%%d&set usr4=%%e if not "%usr4%"

"" call :IIIS "%usr4%"&if "%bypass%" EQU "Y" goto :EOF if not "%usr3%"

"" call :IIIS "%usr3%"&if "%bypass%" EQU "Y" goto :EOF if not "%usr2%"

"" call :IIIS "%usr2%"&if "%bypass%" EQU "Y" goto :EOF if not "%usr1%"

"" call :IIIS "%usr1%"&if "%bypass%" EQU "Y" goto :EOF for /f "Tokens=1,4" %%b in ('dir "%pip%\ntuser.dat" /4 /a /tW ^|Findstr /I /L "NTUSER.DAT"') do set dstring=%%b set dstring=%dstring:/=% set dstring=%dstring:~4,4%%dstring:~0,4% if "%dstring%" GTR "%AYMD%" goto :EOF @echo Delete "%pip%" reg DELETE "%pipkey%%sid%" /f RD "%pip%" /s /q

Hide 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.