Ghost1987 Posted April 6, 2009 Posted April 6, 2009 (edited) Use command line to delete user profile. DeleteProfile.au3 "UserName" If you plan to use this winapi function, be very careful, if $sProfilePath is NULL, it will delete whole %SystemDrive%. This behavior is very strange, because documentation states that if you pass NULL as ProfilePath, function will acquire ProfilePath from registry but this never occurs. expandcollapse popup#NoTrayIcon #include <Security.au3> If $CmdLine[0] == 1 Then Local $UserName = $CmdLine[1] Else Exit EndIf Local $aSID = _Security__LookupAccountName($UserName) If $aSID[2] == 1 Then Local $sProfilePath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" & $aSID[0], "ProfileImagePath") Local $aProfilePath = StringSplit($sProfilePath, '\', 0) $sProfilePath = "" For $i=1 to $aProfilePath[0] Local $EnvVarTestStart = StringMid($aProfilePath[$i], 1, 1) Local $EnvVarTestEnd = StringMid($aProfilePath[$i], StringLen($aProfilePath[$i]), 1) If $EnvVarTestStart == "%" And $EnvVarTestEnd == "%" Then $aProfilePath[$i] = StringTrimLeft($aProfilePath[$i], 1) $aProfilePath[$i] = StringTrimRight($aProfilePath[$i], 1) $aProfilePath[$i] = EnvGet($aProfilePath[$i]) EndIf $sProfilePath &= $aProfilePath[$i] & "\" Next $sProfilePath = StringTrimRight($sProfilePath, 1) If StringLen($sProfilePath) <> 0 Or $sProfilePath <> EnvGet("AllUsersProfile") Or $sProfilePath <> EnvGet("AppData") Or $sProfilePath <> EnvGet("CommonProgramFiles") Or $sProfilePath <> EnvGet("ProgramFiles") Or $sProfilePath <> EnvGet("SystemRoot") Or $sProfilePath <> EnvGet("SystemDrive") Then Local $aRet = _DeleteProfile($aSID[0], $sProfilePath, @ComputerName) Else Exit EndIf Else Exit EndIf Exit Func _DeleteProfile($sSID, $sProfilePath, $sComputerName) Local $aRet = DllCall("Userenv.dll", "int", "DeleteProfile", _ "str", $sSID, "str", $sProfilePath, "str", $sComputerName) If $aRet[0] <> 0 Then Return True Else Return False EndIf EndFunc ;_DeleteProfile Edited April 6, 2009 by Ghost1987
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now