Break On
Dim $SO
$SO = SetOption('Explicit', 'On')
$SO = SetOption('NoMacrosInStrings', 'On')
DIM $strWks, $strProfReg, $arrProfs, $strProf
DIM $strSID, $strPath, $strUser, $strFile, $intRetCode
$strWks = ""
While $strWks == ""
? "Please enter the name of the workstation you wish to delete profiles from: "
Gets $strWks
Loop
$strWks = Trim($strWks)
$strFile = "C:\Documents and Settings\" + @userid + "\Desktop\" + $strWks + "_profiles.ini"
; Enumerate the keys under:
; \\$strWks\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList
; The local administrator key ends with "-500"
$strProfReg = "\\" + $strWks + "\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
$arrProfs = ArrayEnumKey($strProfReg)
For Each $strProf In $arrProfs
If Len($strProf) > 8
; Local accounts are short. System is S-1-5-18, etc.
; Grab the last portion of the SID (after the last hyphen).
$strSID = Right($strProf,Len($strProf)-InStrRev($strProf,"-"))
If $strSid <> "500"
$strPath = ExpandEnvironmentVars(ReadValue($strProfReg + "\" + $strProf, "ProfileImagePath"))
$strUser = Right($strPath,Len($strPath)-InStrRev($strPath,"\"))
If Left($strUser,4) <> "SMSC"
; Don't want to delete the SMS accounts.
; Which should leave us with the accounts we do want to delete.
$intRetCode = WriteProfileStrin($strFile,SIDtoName($strProf),"Path",$strPath)
? "Deleting files for " + SIDtoName($strProf)
? "Deleting path " + $strPath
DelDir($strPath)
; The directory is now gone, delete the registry key.
$intRetCode = DelKey($strProfReg + "\" + $strProf)
? @SERROR
If $intRetCode <> 0
? There was a problem deleting the regsitry key:
? $strProfReg + "\" + $strProf
? "The error code is: " + $intRetCode
EndIf
EndIf
EndIf
EndIf
Next
;
Function ArrayEnumKey($strRegKey)
Dim $intIndex, $arrOfKeys[0], $strKey
If KeyExist($strRegKey)
$intIndex = 0
$strKey = EnumKey($strRegKey,$intIndex)
While @Error = 0
ReDim Preserve $arrOfKeys[$intIndex]
$arrOfKeys[$intIndex] = $strKey
$intIndex = $intIndex + 1
$strKey = EnumKey($strRegKey,$intIndex)
Loop
$ArrayEnumKey = $arrOfKeys
Else
$ArrayEnumKey = ""
EndIf
EndFunction
;
Function DelDir($strPath)
Dim $strFilename
$strFilename = Dir($strPath + "\*.*")
While $strFilename <> "" And @Error = 0
If $strFilename <> "." And $strFilename <> ".."
If (GetFileAttr($strPath + "\" + $strFilename) & 16)
DelDir($strPath + "\" + $strFilename)
SetFileAttr($strPath + "\" + $strFilename, 128)
Rd $strPath + "\" + $strFilename
Else
SetFileAttr($strPath + "\" + $strFilename, 128)
Del $strPath + "\" + $strFilename
EndIf
EndIf
$strFilename = Dir()
Loop
; At this point, the directory should be empty. We just need to delete it now.
Rd $strPath
EndFunction