Jump to content

cleaning RegEdit


odaylton
 Share

Recommended Posts

Text translated from Portuguese by google - please apologize for any errors

I need help on the issue of compatibility with win 8.1

I made this small program to make it easier to search and clean items without a Windows registry

It works perfectly in XP but for win8.1 even running as administrator it shows me the type of control but does not get the text that the control has

#Region - - -Au3Recorder generated code Start(v3.3.9.5 KeyboardLayout = 00000416) - - -

#Region --- Internal functions Au3Recorder Start ---
Func _Au3RecordSetup()
    Opt('WinWaitDelay', 100)
    Opt('WinDetectHiddenText', 1)
    Opt('MouseCoordMode', 0)
    Local $aResult = DllCall('User32.dll', 'int', 'GetKeyboardLayoutNameW', 'wstr', '')
    If $aResult[1] <> '00000416' Then
        MsgBox(64, 'Warning', 'Recording has been done under a different Keyboard layout' & @CRLF & '(00000416->' & $aResult[1] & ')')
    EndIf

EndFunc   ;==>_Au3RecordSetup

Func _WinWaitActivate($title, $text, $timeout = 0)
    WinWait($title, $text, $timeout)
    If Not WinActive($title, $text) Then WinActivate($title, $text)
    return WinWaitActive($title, $text, $timeout)
EndFunc   ;==>_WinWaitActivate

_Au3RecordSetup()
#EndRegion --- Internal functions Au3Recorder Start ---
Func Busca($a)
    Local $sText=""
While True
    $hWnd = _WinWaitActivate("Editor do Registro", "")
    $sControl = ControlGetFocus($hWnd)
    Switch $sControl
        Case "SysTreeView321" 
            $sText = ControlTreeView($hWnd, "", $sControl, "GetSelected")
        Case "SysListView321" 
            $indice = ControlListView($hWnd, "", $sControl, "GetSelected",1)
            $sText = ControlListView($hWnd, "", $sControl, "GetText",$indice,0)
    EndSwitch
    If $sText <> $a Then ExitLoop
    ToolTip("Controle[" & $sControl & "]=["& $sText &"]")
WEnd
Return $sText
EndFunc
$a=Busca("")

While True
    $ultimo=Busca("")
    Send("{F3}")
    $a=Busca($ultimo)
    #Region --- CodeWizard generated code Start ---
    ;MsgBox features: Title=Yes, Text=Yes, Buttons=Yes, No, and Cancel, Icon=None, Timeout=5 ss, Miscellaneous=Top-most attribute
    If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer
    $iMsgBoxAnswer = MsgBox(262147, _
            "Escolha o tipo", _
            "Sim para o Foco nao mudar foco e Cancelar para sair", _
            5)
    Select
        Case $iMsgBoxAnswer = 6 ;Yes
            $hWnd= _WinWaitActivate("Editor do Registro", "")
            Send("{DEL}")
            ;Send("{ENTER}")
        Case $iMsgBoxAnswer = 7 ;No
            _WinWaitActivate("Editor do Registro", "")
            Send("{TAB}")
            Send("{DEL}")
            ;Send("{ENTER}")
        Case $iMsgBoxAnswer = 2 ;Cancel
            ExitLoop
        Case $iMsgBoxAnswer = -1 ;Timeout
            _WinWaitActivate("Editor do Registro", "")
            Send("{DEL}")
            ;Send("{ENTER}")
    EndSelect
    #EndRegion --- CodeWizard generated code Start ---
WEnd


#EndRegion --- Au3Recorder generated code End ---
#EndRegion

Note that it should show no ToolTip but does not show the text of the control.

 

Link to comment
Share on other sites

1 hour ago, Subz said:

Wouldn't recommend using send keys especially using delete in RegEdit, that's just asking for trouble.  Why not use AutoIt Reg functions to search hives and delete according?

1000x this do NOT use send keys, it's not reliable and registry's tend to be quite different machine to machine, so just a single oops could create a broken computer.

All honesty the reg functions will be simpler to use anyways.

 

Here is some code that I used to manually clean up some old Oracle stuff.

I used SplashText to show the key being looked at, and gave the user a prompt to delete it or leave it.

#RequireAdmin
#Include <Array.au3>
#Include <File.au3>
#Include <FileConstants.au3>

$HKLM = "HKLM"
If StringInStr(@OSArch, "64") Then  $HKLM &= "64"

;5 Remove Hansen
If MsgBox(4, "BoCC Automation", "Have You Checked for Hansen in Add/Remove Programs?") = 6 Then
    SplashTextOn("BoCC Automation", "C: - *Hansen*", @DesktopWidth, 43, 0, 0, 1)
$aHansenRoot = _FileListToArray("C:\", "*", $FLTA_FOLDERS, True)
For $i = 1 to $aHansenRoot[0]
    If StringInStr($aHansenRoot[$i], "Hansen") Then
    If MsgBox(4, "BoCC Automation", "Delete Folder " & $aHansenRoot[$i] & "?") = 6 Then DirRemove($aHansenRoot[$i], 1)
    EndIf
Next
SplashOff()

    SplashTextOn("BoCC Automation", @ProgramFilesDir & " - *Hansen*", @DesktopWidth, 43, 0, 0, 1)
$aHansenRoot = _FileListToArray(@ProgramFilesDir, "*", $FLTA_FOLDERS, True)
For $i = 1 to $aHansenRoot[0]
    If StringInStr($aHansenRoot[$i], "Hansen") Then
    If MsgBox(4, "BoCC Automation", "Delete Folder " & $aHansenRoot[$i] & "?") = 6 Then DirRemove($aHansenRoot[$i], 1)
    EndIf
Next
SplashOff()
EndIf


;6 Remove Crystal Reports
SplashTextOn("BoCC Automation", @ProgramFilesDir & " - *Seagate* *Crystal*", @DesktopWidth, 43, 0, 0, 1)
$aCrystal = _FileListToArray("C:\Program Files (x86)", "*", $FLTA_FOLDERS, True)
$aCrystal2 = _FileListToArray("C:\Program Files", "*", $FLTA_FOLDERS, True)
_ArrayConcatenate($aCrystal, $aCrystal2, 1)
For $i = 1 to UBound($aCrystal) - 1
    If StringInStr($aCrystal[$i], "Seagate") OR StringInStr($aCrystal[$i], "Crystal") Then
    If MsgBox(4, "BoCC Automation", "Delete Folder " & $aCrystal[$i] & "?") = 6 Then DirRemove($aCrystal[$i], 1)
    EndIf
Next
SplashOff()

SplashTextOn("BoCC Automation", @StartMenuCommonDir & "\Programs - *Seagate* *Crystal*", @DesktopWidth, 43, 0, 0, 1)
$aStartMenuCommon = _FileListToArray(@StartMenuCommonDir & "\Programs", "*", $FLTA_FOLDERS, True)
For $i = 1 to $aStartMenuCommon[0]
    If StringInStr($aStartMenuCommon[$i], "Seagate") OR StringInStr($aStartMenuCommon[$i], "Crystal") Then
    If  MsgBox(4, "BoCC Automation", "Delete Start Menu Entry " & $aStartMenuCommon[$i] & "?") = 6 Then DirRemove($aStartMenuCommon[$i], 1)
    EndIf
Next
SplashOff()

SplashTextOn("BoCC Automation", @StartMenuDir & "\Programs - *Seagate* *Crystal*", @DesktopWidth, 43, 0, 0, 1)
$aStartMenu = _FileListToArray(@StartMenuDir & "\Programs", "*", $FLTA_FOLDERS, True)
For $i = 1 to $aStartMenu[0]
    If StringInStr($aStartMenu[$i], "Seagate") OR StringInStr($aStartMenu[$i], "Crystal") Then
    If MsgBox(4, "BoCC Automation", "Delete Start Menu Entry " & $aStartMenu[$i] & "?") = 6 Then DirRemove($aStartMenu[$i], 1)
    EndIf
Next
SplashOff()

;7 Remove Oracle references from PATH environment varible.
SplashTextOn("BoCC Automation", "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment - PATH", @DesktopWidth, 43, 0, 0, 1)
If StringInStr(RegRead($HKLM & "\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "Path"), "Oracle") Then
    If MsgBox(4, "BoCC Automation", "Remove Oracle References from System Path Variable?") = 6 Then _RemoveFromPath("Oracle", 1)
EndIf
SplashOff()

;8 Remove TNS_ADMIN environment variable.
SplashTextOn("BoCC Automation", "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment - TNS_ADMIN", @DesktopWidth, 43, 0, 0, 1)
If RegRead($HKLM & "\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "TNS_ADMIN") Then
    If MsgBox(4, "BoCC Automation", "Delete TNS_ADMIN?") = 6 Then RegDelete($HKLM & "\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "TNS_ADMIN")
EndIf
SplashOff()

;10 Remove Oracle Client
SplashTextOn("BoCC Automation", "HKLM\Software\Oracle", @DesktopWidth, 43, 0, 0, 1)
If _RegExistKey($HKLM & "\Software\Oracle") Then
    If MsgBox(4, "BoCC Automation", "Delete Oracle Software Key?") = 6 Then RegDelete($HKLM & "\Software\Oracle")
EndIf
SplashOff()

SplashTextOn("BoCC Automation", "HKLM\System\CurrentControlSet\Services - *Oracle In*", @DesktopWidth, 43, 0, 0, 1)
For $i = 1 To 500
    $var = RegEnumKey($HKLM & "\System\CurrentControlSet\Services", $i)
    If @error <> 0 Then ExitLoop
    If StringInStr($var, "Ora", 0, 1, 1, 3) Then
        $Delete = MsgBox(4, "CurrentControlSet\Services", "Delete " & $var & " ?")
        If $Delete = 6 Then RegDelete($HKLM & "\System\CurrentControlSet\Services\" & $var)
    EndIf
Next
SplashOff()

SplashTextOn("BoCC Automation", "HKLM\Software\ODBC\ODBCINST.INI\ODBC Drivers - *Oracle In*", @DesktopWidth, 43, 0, 0, 1)
For $i = 1 To 500
    $var = RegEnumVal("HKLM\Software\ODBC\ODBCINST.INI\ODBC Drivers\", $i)
    If @error <> 0 Then ExitLoop
    If StringInStr($var, "Oracle In") Then
        $Delete = MsgBox(4, "ODBC Drivers", "Delete " & $var & " ?")
        If $Delete = 6 Then RegDelete("HKLM\Software\ODBC\ODBCINST.INI\ODBC Drivers\", $var)
    EndIf
Next
SplashOff()

SplashTextOn("BoCC Automation", "HKLM\Software\ODBC\ODBCINST.INI\ODBC Drivers - *Oracle In*", @DesktopWidth, 43, 0, 0, 1)
For $i = 1 To 500
    $var = RegEnumVal("HKLM64\Software\ODBC\ODBCINST.INI\ODBC Drivers\", $i)
    If @error <> 0 Then ExitLoop
    If StringInStr($var, "Oracle In") Then
        $Delete = MsgBox(4, "ODBC Drivers", "Delete " & $var & " ?")
        If $Delete = 6 Then RegDelete("HKLM64\Software\ODBC\ODBCINST.INI\ODBC Drivers\", $var)
    EndIf
Next
SplashOff()

SplashTextOn("BoCC Automation", "HKLM\Software\ODBC\ODBCINST.INI - *Oracle In*", @DesktopWidth, 43, 0, 0, 1)
For $i = 1 To 500
    $var = RegEnumKey("HKLM\Software\ODBC\ODBCINST.INI", $i)
    If @error <> 0 Then ExitLoop
    If StringInStr($var, "Oracle In") Then
        $Delete = MsgBox(4, "ODBCINST.INI", "Delete " & $var & " ?")
        If $Delete = 6 Then RegDelete("HKLM\Software\ODBC\ODBCINST.INI\" & $var)
    EndIf
Next
SplashOff()

SplashTextOn("BoCC Automation", "HKLM\Software\ODBC\ODBCINST.INI - *Oracle In*", @DesktopWidth, 43, 0, 0, 1)
For $i = 1 To 500
    $var = RegEnumKey("HKLM64\Software\ODBC\ODBCINST.INI", $i)
    If @error <> 0 Then ExitLoop
    If StringInStr($var, "Oracle In") Then
        $Delete = MsgBox(4, "ODBCINST.INI", "Delete " & $var & " ?")
        If $Delete = 6 Then RegDelete("HKLM64\Software\ODBC\ODBCINST.INI\" & $var)
    EndIf
Next
SplashOff()

SplashTextOn("BoCC Automation", "HKLM\System\CurrentControlSet\Services\EventLog\Application - Ora*", @DesktopWidth, 43, 0, 0, 1)
For $i = 1 To 500
    $var = RegEnumKey($HKLM & "\System\CurrentControlSet\Services\EventLog\Application", $i)
    If @error <> 0 Then ExitLoop
    If StringInStr($var, "Ora", 0, 1, 1, 3) Then
        $Delete = MsgBox(4, "Event Logs", "Delete " & $var & " ?")
        If $Delete = 6 Then RegDelete($HKLM & "\System\CurrentControlSet\Services\EventLog\Application\" & $var)
    EndIf
Next
SplashOff()

SplashTextOn("BoCC Automation", "HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall - *Oracle*", @DesktopWidth, 43, 0, 0, 1)
For $i = 1 To 500
    $var = RegEnumKey($HKLM & "\Software\Microsoft\Windows\CurrentVersion\Uninstall", $i)
    If @error <> 0 Then ExitLoop
    If StringInStr($var, "Oracle") Then
        $Delete = MsgBox(4, "Uninstall Strings", "Delete " & $var & " ?")
        If $Delete = 6 Then RegDelete($HKLM & "\Software\Microsoft\Windows\CurrentVersion\Uninstall\" & $var)
    EndIf
Next
SplashOff()

SplashTextOn("BoCC Automation", "HKCR\ - Ora* - ORCL*", @DesktopWidth, 43, 0, 0, 1)
For $i = 1 To 5000
    $var = RegEnumKey("HKCR\", $i)
    If @error <> 0 Then ExitLoop
    If StringInStr($var, "Ora", 0, 1, 1, 3) OR StringInStr($var, "ORCL", 0, 1, 1, 4) Then
        $Delete = MsgBox(4, "HKEY CLASSES ROOT", "Delete " & $var & " ?")
        If $Delete = 6 Then RegDelete("HKCR\" & $var)
    EndIf
Next
SplashOff()

SplashTextOn("BoCC Automation", "HKLM\Software\Classes - Ora*", @DesktopWidth, 43, 0, 0, 1)
For $i = 1 To 5000
    $var = RegEnumKey($HKLM & "\Software\Classes", $i)
    If @error <> 0 Then ExitLoop
    If StringInStr($var, "Ora", 0, 1, 1, 3) OR StringInStr($var, "ORCL", 0, 1, 1, 4) Then
        $Delete = MsgBox(4, "Software Classes", "Delete " & $var & " ?")
        If $Delete = 6 Then RegDelete($HKLM & "\Software\Classes\" & $var)
    EndIf
Next
SplashOff()

SplashTextOn("BoCC Automation", "HKU\ - \Software\Oracle", @DesktopWidth, 43, 0, 0, 1)
For $i = 1 To 500
    $var = RegEnumKey("HKU\", $i)
    If @error <> 0 Then ExitLoop
    If _RegExistKey("HKU\" & $var & "\Software\Oracle") Then
        If MsgBox(4, "BoCC Automation", "Delete Software Oracle Key for SSID " & $var & "?") = 6 Then   RegDelete("HKU\" & $var & "\Software\Oracle")
    EndIf
Next
SplashOff()

;11 Remove any  items on the Start Menu for Oracle

SplashTextOn("BoCC Automation", @StartMenuCommonDir & "\Programs - *Oracle*", @DesktopWidth, 43, 0, 0, 1)
$aStartMenuCommon = _FileListToArray(@StartMenuCommonDir & "\Programs", "*", $FLTA_FOLDERS, True)
For $i = 1 to $aStartMenuCommon[0]
    If StringInStr($aStartMenuCommon[$i], "Oracle") Then
    If  MsgBox(4, "BoCC Automation", "Delete Start Menu Entry " & $aStartMenuCommon[$i] & "?") = 6 Then DirRemove($aStartMenuCommon[$i], 1)
    EndIf
Next
SplashOff()

SplashTextOn("BoCC Automation", @StartMenuDir & "\Programs - *Oracle*", @DesktopWidth, 43, 0, 0, 1)
$aStartMenu = _FileListToArray(@StartMenuDir & "\Programs", "*", $FLTA_FOLDERS, True)
For $i = 1 to $aStartMenu[0]
    If StringInStr($aStartMenu[$i], "Oracle") Then
    If MsgBox(4, "BoCC Automation", "Delete Start Menu Entry " & $aStartMenu[$i] & "?") = 6 Then DirRemove($aStartMenu[$i], 1)
    EndIf
Next
SplashOff()

;12 Remove Oracle Folder
SplashTextOn("BoCC Automation", @ProgramFilesDir & " - *Oracle*", @DesktopWidth, 43, 0, 0, 1)
$aOracle = _FileListToArray("C:\Program Files (x86)", "*", $FLTA_FOLDERS, True)
$aOracle2 = _FileListToArray("C:\Program Files", "*", $FLTA_FOLDERS, True)
_ArrayConcatenate($aOracle, $aOracle2, 1)
For $i = 1 to UBound($aOracle) - 1
    If StringInStr($aOracle[$i], "Oracle") Then
    If MsgBox(4, "BoCC Automation", "Delete Folder " & $aOracle[$i] & "?") = 6 Then DirRemove($aOracle[$i], 1)
    EndIf
Next
SplashOff()

SplashTextOn("BoCC Automation", "C: - *Oracle*", @DesktopWidth, 43, 0, 0, 1)
$aOracleRoot = _FileListToArray("C:\", "*", $FLTA_FOLDERS, True)
For $i = 1 to $aOracleRoot[0]
    If StringInStr($aOracleRoot[$i], "Oracle") Then
    If MsgBox(4, "BoCC Automation", "Delete Folder " & $aOracleRoot[$i] & "?") = 6 Then DirRemove($aOracleRoot[$i], 1)
    EndIf
Next
SplashOff()

;****************************************************
;************** Functions Below ********************
;****************************************************

Func _RegExistKey($sKeyname)
    RegEnumVal ($sKeyname, 1)
    Return (@error <= 0)
EndFunc

; iFlag possible combinations :
;  - 0  : add the sText to the beginning (default)
;  - 1  : add the sText to the end
;  - 2  : add the sText even if it is already present
Func _AddToPath($sText, $iFlag = 0)
    If NOT IsAdmin() Then Return SetError(4, 0, 0)
    Local $sPath  = RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "path")
    If NOT BitAND($iFlag, 2) AND StringRegExp($sPath, "(?i)(?:^|;)\Q" & $sText & "\E(?:;|$)") Then Return SetError(5, 0, 1)
    Local $sNewPath = $sText & ";" & $sPath
    If BitAND($iFlag, 1) Then $sNewPath = $sPath & ";" & $sText
    RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "path", "REG_EXPAND_SZ", $sNewPath)
    If @error Then Return SetError(@error, 0, 0)
    EnvUpdate()
    Return 1
EndFunc

; iFlag = 0  :  match exactly the text (default)
; iFlag = 1  :  match part of the text
Func _RemoveFromPath($sText, $iFlag = 0)
    If NOT IsAdmin() Then Return SetError(4, 0, 0)
    Local $sPattern = "\Q" & $sText & "\E*"
    If $iFlag Then $sPattern = "[^;]*" & $sPattern & "[^;]*"
    Local $sPath  = RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "path")
    Local $sNewPath  = StringRegExpReplace($sPath, "(?i)(?<=^|;)" & $sPattern & "(?:;|$)", "")
    Local $iExtended = @extended
    If $iExtended Then
        RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "path", "REG_EXPAND_SZ", $sNewPath)
        If @error Then Return SetError(@error, 0, 0)
        EnvUpdate()
    EndIf
    ConsoleWrite($sNewPath)
    Return SetExtended($iExtended, 1)
EndFunc

 

Link to comment
Share on other sites

I agree it's not advisable but I was wanting to do a quick script to do a simple cleanup just annoying.

But my doubt is because in win8.1 even using run as adm did not get the text of the current control

Switch $sControl
        Case "SysTreeView321" 
            $sText = ControlTreeView($hWnd, "", $sControl, "GetSelected")
        Case "SysListView321" 
            $indice = ControlListView($hWnd, "", $sControl, "GetSelected",1)
            $sText = ControlListView($hWnd, "", $sControl, "GetText",$indice,0)
    EndSwitch

 

Edited by odaylton
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...