Skip to content

Commit 4354c21

Browse files
authored
Update RegCleaner.au3
1 parent 9fac232 commit 4354c21

1 file changed

Lines changed: 88 additions & 80 deletions

File tree

bin/RegCleaner.au3

Lines changed: 88 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -4,94 +4,102 @@
44
#include <GuiListView.au3>
55
#include <MsgBoxConstants.au3>
66

7-
; === Configuration ===
8-
Local $sSearchTerm = "NetWebView2"
9-
Local $aTargets[2] = ["HKEY_LOCAL_MACHINE64\SOFTWARE\Classes", "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Classes"]
10-
11-
; GUICreate
12-
Local $iWidth = @DesktopWidth * 0.7 , $iHeight = @DesktopHeight * 0.9
13-
Local $hGUI = GUICreate("NetWebView2 - Registry Deep Cleaner", $iWidth, $iHeight)
14-
GUISetFont(9, 400, 0, "Segoe UI")
15-
$iWidth -= 20
16-
$iHeight -= 90
17-
Local $idListView = GUICtrlCreateListView("Registry Key Path|Details", 10, 10, $iWidth, $iHeight, $LVS_REPORT + $LVS_SHOWSELALWAYS)
18-
_GUICtrlListView_SetExtendedListViewStyle($idListView, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))
19-
_GUICtrlListView_SetColumnWidth($idListView, 0, $iWidth * 0.6)
20-
_GUICtrlListView_SetColumnWidth($idListView, 1, $iWidth * 0.4)
21-
$iHeight += 20
22-
Local $idStatus = GUICtrlCreateLabel("Scanning registry... please wait...", 10, $iHeight, $iWidth - 210 - 10, 20)
23-
$iHeight += 20
24-
Local $idBtnCancel = GUICtrlCreateButton("Cancel", $iWidth - 100, $iHeight, 100, 40)
25-
Local $idBtnDelete = GUICtrlCreateButton("Delete Selected", $iWidth - 210, $iHeight, 100, 40)
26-
GUISetState(@SW_SHOW)
27-
28-
; Scan
29-
Local $iTotalFound = 0
30-
For $sRoot In $aTargets
31-
_Registry_Scan_Recursive($sRoot, $sSearchTerm, $idListView, $iTotalFound)
32-
Next
33-
GUICtrlSetData($idStatus, "Scan complete. Found " & $iTotalFound & " keys.")
34-
35-
While 1
36-
Switch GUIGetMsg()
37-
Case $GUI_EVENT_CLOSE, $idBtnCancel
38-
Exit
39-
40-
Case $idBtnDelete
41-
Local $iCheckedCount = 0
42-
; Count checked items first
43-
For $i = 0 To _GUICtrlListView_GetItemCount($idListView) - 1
44-
If _GUICtrlListView_GetItemChecked($idListView, $i) Then $iCheckedCount += 1
45-
Next
46-
47-
If $iCheckedCount = 0 Then
48-
MsgBox($MB_ICONEXCLAMATION, "Nothing selected", "Please check the keys you want to remove.")
49-
ContinueLoop
50-
EndIf
51-
52-
If MsgBox($MB_YESNO + $MB_ICONWARNING, "Confirm Deletion", "Are you sure you want to delete the " & $iCheckedCount & " selected keys?") = $IDYES Then
53-
_Delete_Checked_Items($idListView)
54-
MsgBox($MB_ICONINFORMATION, "Done", "Cleanup finished successfully.")
55-
Exit
56-
EndIf
57-
EndSwitch
58-
WEnd
7+
_Cleaner()
8+
9+
Func _Cleaner()
10+
; === Configuration ===
11+
Local $sSearchTerm = "NetWebView2"
12+
Local $aTargets[2] = ["HKEY_LOCAL_MACHINE64\SOFTWARE\Classes", "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Classes"]
13+
14+
; GUICreate
15+
Local $iWidth = @DesktopWidth * 0.7, $iHeight = @DesktopHeight * 0.9
16+
Local $hGUI = GUICreate("NetWebView2 - Registry Deep Cleaner", $iWidth, $iHeight)
17+
#forceref $hGUI
18+
19+
GUISetFont(9, 400, 0, "Segoe UI")
20+
$iWidth -= 20
21+
$iHeight -= 90
22+
Local $idListView = GUICtrlCreateListView("Registry Key Path|Details", 10, 10, $iWidth, $iHeight, $LVS_REPORT + $LVS_SHOWSELALWAYS)
23+
_GUICtrlListView_SetExtendedListViewStyle($idListView, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))
24+
_GUICtrlListView_SetColumnWidth($idListView, 0, $iWidth * 0.6)
25+
_GUICtrlListView_SetColumnWidth($idListView, 1, $iWidth * 0.4)
26+
$iHeight += 20
27+
Local $idStatus = GUICtrlCreateLabel("Scanning registry... please wait...", 10, $iHeight, $iWidth - 210 - 10, 20)
28+
$iHeight += 20
29+
Local $idBtnCancel = GUICtrlCreateButton("Cancel", $iWidth - 100, $iHeight, 100, 40)
30+
Local $idBtnDelete = GUICtrlCreateButton("Delete Selected", $iWidth - 210, $iHeight, 100, 40)
31+
GUISetState(@SW_SHOW)
32+
33+
; Scan
34+
Local $iTotalFound = 0
35+
For $sRoot In $aTargets
36+
__Registry_Scan_Recursive($sRoot, $sSearchTerm, $idListView, $iTotalFound, $idStatus)
37+
Next
38+
GUICtrlSetData($idStatus, "Scan complete. Found " & $iTotalFound & " keys.")
39+
40+
While 1
41+
Switch GUIGetMsg()
42+
Case $GUI_EVENT_CLOSE, $idBtnCancel
43+
Exit
44+
45+
Case $idBtnDelete
46+
Local $iCheckedCount = 0
47+
; Count checked items first
48+
For $i = 0 To _GUICtrlListView_GetItemCount($idListView) - 1
49+
If _GUICtrlListView_GetItemChecked($idListView, $i) Then $iCheckedCount += 1
50+
Next
51+
52+
If $iCheckedCount = 0 Then
53+
MsgBox($MB_ICONEXCLAMATION, "Nothing selected", "Please check the keys you want to remove.")
54+
ContinueLoop
55+
EndIf
56+
57+
If MsgBox($MB_YESNO + $MB_ICONWARNING, "Confirm Deletion", "Are you sure you want to delete the " & $iCheckedCount & " selected keys?") = $IDYES Then
58+
__Delete_Checked_Items($idListView)
59+
MsgBox($MB_ICONINFORMATION, "Done", "Cleanup finished successfully.")
60+
Exit
61+
EndIf
62+
EndSwitch
63+
WEnd
64+
65+
EndFunc ;==>_Cleaner
5966

6067
;---------------------------------------------------------------------------------------
61-
Func _Registry_Scan_Recursive($sKey, $sSearch, $hLV, ByRef $iCount)
62-
Local $iIndex = 1
63-
While 1
64-
Local $sSubKey = RegEnumKey($sKey, $iIndex)
65-
If @error Then ExitLoop
68+
Func __Registry_Scan_Recursive($sKey, $sSearch, $hLV, ByRef $iCount, $idStatus)
69+
Local $iIndex = 1
70+
While 1
71+
Local $sSubKey = RegEnumKey($sKey, $iIndex)
72+
If @error Then ExitLoop
6673

6774
If Mod($iIndex, 100) = 0 Then
6875
GUICtrlSetData($idStatus, "Scanning: " & $iIndex & " keys in " & StringLeft($sKey, 40) & "...")
6976
EndIf
7077

71-
Local $sFull = $sKey & "\" & $sSubKey
72-
Local $sData = RegRead($sFull, "")
78+
Local $sFull = $sKey & "\" & $sSubKey
79+
Local $sData = RegRead($sFull, "")
7380

74-
If StringInStr($sSubKey, $sSearch) Or StringInStr($sData, $sSearch) Then
75-
$iCount += 1
76-
Local $sDisplayData = ($sData <> "" ? $sData : "Folder/Container")
77-
GUICtrlCreateListViewItem($sFull & "|" & $sDisplayData, $hLV)
78-
_GUICtrlListView_SetItemChecked($hLV, _GUICtrlListView_GetItemCount($hLV) - 1)
79-
EndIf
81+
If StringInStr($sSubKey, $sSearch) Or StringInStr($sData, $sSearch) Then
82+
$iCount += 1
83+
Local $sDisplayData = ($sData <> "" ? $sData : "Folder/Container")
84+
GUICtrlCreateListViewItem($sFull & "|" & $sDisplayData, $hLV)
85+
_GUICtrlListView_SetItemChecked($hLV, _GUICtrlListView_GetItemCount($hLV) - 1)
86+
EndIf
87+
88+
__Registry_Scan_Recursive($sFull, $sSearch, $hLV, $iCount, $idStatus)
89+
$iIndex += 1
90+
WEnd
91+
EndFunc ;==>__Registry_Scan_Recursive
8092

81-
_Registry_Scan_Recursive($sFull, $sSearch, $hLV, $iCount)
82-
$iIndex += 1
83-
WEnd
84-
EndFunc
8593
;---------------------------------------------------------------------------------------
86-
Func _Delete_Checked_Items($hLV)
87-
; backwards deletion to avoid index shifting
88-
For $i = _GUICtrlListView_GetItemCount($hLV) - 1 To 0 Step -1
89-
If _GUICtrlListView_GetItemChecked($hLV, $i) Then
90-
Local $sKeyPath = _GUICtrlListView_GetItemText($hLV, $i)
91-
If RegDelete($sKeyPath) Then
92-
ConsoleWrite("[-] Deleted: " & $sKeyPath & @CRLF)
93-
EndIf
94-
EndIf
95-
Next
96-
EndFunc
94+
Func __Delete_Checked_Items($hLV)
95+
; backwards deletion to avoid index shifting
96+
For $i = _GUICtrlListView_GetItemCount($hLV) - 1 To 0 Step -1
97+
If _GUICtrlListView_GetItemChecked($hLV, $i) Then
98+
Local $sKeyPath = _GUICtrlListView_GetItemText($hLV, $i)
99+
If RegDelete($sKeyPath) Then
100+
ConsoleWrite("[-] Deleted: " & $sKeyPath & @CRLF)
101+
EndIf
102+
EndIf
103+
Next
104+
EndFunc ;==>__Delete_Checked_Items
97105
;---------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)