|
#include <ButtonConstants.au3> |
|
#include <GUIConstantsEx.au3> |
|
#include <GUIListBox.au3> |
|
#include <WindowsConstants.au3> |
|
#include <GuiListView.au3> |
|
#include <ListviewConstants.au3> |
|
#include <Array.au3> |
|
|
|
#RequireAdmin |
|
|
|
Const $REG_KEY_ProfileList = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" |
|
|
|
Dim $DomainProfileCount = 0 |
|
|
|
$FRM_Main = GUICreate("Domain User Profile Deleter", 600, 435, -1, -1) |
|
$LV_user_accounts = GUICtrlCreateListView("SID|Profile Path", 0, 0, 600, 383, $LVS_NOSORTHEADER, _ |
|
BitOR($LVS_EX_CHECKBOXES, $LVS_EX_HEADERDRAGDROP, $LVS_EX_FULLROWSELECT)) |
|
|
|
For $i = 1 To 9999 |
|
$sid = RegEnumKey($REG_KEY_ProfileList, $i) |
|
If @error Then ExitLoop |
|
|
|
; Account is a domain account if the value 'Guid' exists. |
|
If StringLeft($sid, 9) = "S-1-5-21-" And RegRead($REG_KEY_ProfileList & "\" & $sid, "Guid") <> "" Then |
|
GUICtrlCreateListViewItem($sid & "|" & RegRead($REG_KEY_ProfileList & "\" & $sid, "ProfileImagePath"), $LV_user_accounts) |
|
$DomainProfileCount += 1 |
|
EndIf |
|
Next |
|
|
|
$BTN_Delete = GUICtrlCreateButton("Delete Selected", 465, 400, 125, 25) |
|
|
|
; Autosize the columns |
|
If $DomainProfileCount > 0 Then |
|
_GUICtrlListView_SetColumnWidth($LV_user_accounts, 0, $LVSCW_AUTOSIZE) |
|
_GUICtrlListView_SetColumnWidth($LV_user_accounts, 1, $LVSCW_AUTOSIZE) |
|
EndIf |
|
|
|
GUISetState(@SW_SHOW) |
|
|
|
While 1 |
|
$nMsg = GUIGetMsg() |
|
Switch $nMsg |
|
Case $GUI_EVENT_CLOSE |
|
Exit |
|
|
|
Case $Btn_Delete |
|
$todelete = False |
|
$require_restart = False |
|
$delete_prompt = "Are you sure you want to delete the following profiles?" |
|
$failed_delete_prompt = "The following profiles were not successfully deleted." & @CRLF & "Please delete them manually after a system restart:" |
|
|
|
; Generate confirmation prompt message (list of paths) |
|
For $i = 0 to $DomainProfileCount |
|
If _GUICtrlListView_GetItemChecked($LV_user_accounts, $i) Then |
|
$todelete = True |
|
$delete = StringSplit(_GUICtrlListView_GetItemTextString($LV_user_accounts, $i), "|") |
|
$delete_prompt &= @CRLF & $delete[2] |
|
EndIf |
|
Next |
|
|
|
If $todelete Then |
|
; Confirmation prompt |
|
$msgbox_response = MsgBox(BitOR($MB_ICONQUESTION, $MB_YESNO), "Delete Accounts", $delete_prompt) |
|
|
|
If $msgbox_response = $IDYES Then |
|
; Start deleting selected profiles |
|
For $i = 0 to $DomainProfileCount |
|
If _GUICtrlListView_GetItemChecked($LV_user_accounts, $i) Then |
|
$delete = StringSplit(_GUICtrlListView_GetItemTextString($LV_user_accounts, $i), "|") |
|
|
|
; Delete registry entry |
|
RegDelete($REG_KEY_ProfileList & "\" & $delete[1]) |
|
|
|
; Delete profile folder |
|
RunWait(@ComSpec & " /c " & "rmdir" & ' "' & $delete[2] & '"' & ' /s /q') |
|
|
|
; Check if successfully deleted |
|
If FileExists($delete[2]) Then |
|
$require_restart = True |
|
$failed_delete_prompt &= @CRLF & $delete[2] |
|
EndIf |
|
EndIf |
|
Next |
|
|
|
If $require_restart Then |
|
MsgBox($MB_ICONWARNING, "Delete Accounts", $failed_delete_prompt) |
|
Else |
|
MsgBox($MB_ICONINFORMATION, "Delete Accounts", "The selected profiles have been deleted successfully.") |
|
EndIf |
|
|
|
Exit(0) |
|
EndIf |
|
Else |
|
MsgBox($MB_ICONINFORMATION, "Delete Accounts", "No accounts selected. Nothing Deleted.") |
|
EndIf |
|
|
|
EndSwitch |
|
WEnd |