Windows Remove Temporary Profiles

Scripts and guide by Soren Birk.

This scripts checks for temporary profiles in the registry and deletes them, if any found.

Tested with:

  • OPSI
  • Winst
  • Windows 7, 64-Bit


  ├ registrylogo.png
  └ once.ins


; Author Soren Birk
requiredWinstVersion >= ""
DefVar $ProductId$
DefVar $UserProfileName$
DefVar $SID$
DefStringList $SIDcmd$
DefStringList $UserProfileNamesList$
set $UserProfileNamesList$ = getOutStreamFromSection ('DosInAnIcon_list_profiledir')
; ----------------------------------------------------------------
; - Please edit these values                                     -
; ----------------------------------------------------------------
Set $ProductId$       = "remove-temp-profiles"
; ----------------------------------------------------------------
comment "Show product logo"
ShowBitmap "%ScriptPath%\registrylogo.png" "Remove temporary profiles"
Message "Removing temporary profiles ..."
comment "Removing .bak-files"
ChangeDirectory "%SCRIPTPATH%"
for %prof% in $UserProfileNamesList$ do sub_remove_bak
@echo off
dir "%ProfileDir%" /b /ad
Set $UserProfileName$ = "%prof%"
if not ($UserProfileName$ = "") and not ($UserProfileName$ = "All Users") and not ($UserProfileName$ = "Public") and not ($UserProfileName$ = "LocalService") and not ($UserProfileName$ = "NetworkService")
	Set $SIDcmd$ = getOutStreamFromSection ('DosInAnIcon_getuser')
	Set $SID$ = trim(takeFirstStringContaining($SIDcmd$,"S-"))
	comment "Removing .bak-file for " + $UserProfileName$ + " if it exists..."
wmic useraccount where name='$UserProfileName$' get sid
Deletekey [HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$SID$.bak]

QR Code
QR Code userspace:windows_remove_temporary_profile (generated for current page)