Jump to content

Refreshing an array (i think)


 Share

Recommended Posts

Ok i have a tool that removes a known list of uninstallers

The problem is i want to remove the reg keys that relate to the programs after everything has uninstalled 

But the array has changed because some uninstallers remove their stuff properly and the data for the array then has missing items

The origanal array is created like this

Local $aUninstallPaths[0] ; Inialize array with no elements
    For $regloop = 1 To $aRegPath[0]
        For $keyloop = 1 To $aRegKeys[0]
            If _IsRegistryExist($aRegPath[$regloop] & $aRegKeys[$keyloop], "QuietUninstallString") Then
                $sUninstallPath = RegRead($aRegPath[$regloop] & $aRegKeys[$keyloop], "QuietUninstallString") ; Find QuietUninstallString
                $aUninstallArray = _ArrayAdd($aUninstallPaths, $sUninstallPath)
            ElseIf _IsRegistryExist($aRegPath[$regloop] & $aRegKeys[$keyloop], "UninstallString") Then
                $sUninstallPath = RegRead($aRegPath[$regloop] & $aRegKeys[$keyloop], "UninstallString") ; Find UninstallString If Quiet Not Avail
                $aUninstallArray = _ArrayAdd($aUninstallPaths, $sUninstallPath)
            EndIf
        Next
    Next
;~  _ArrayDisplay($aRegPath[$regloop] & $aRegKeys[$keyloop], 'Reg Path And Keys')
    Local $aUninstallList = _ArrayUnique($aUninstallPaths)

Do i have to make a second for next loop like this and go through them all again or is there a better way?

Link to comment
Share on other sites

I propose a good solution for your circumstances would be a second loop.

By the way, is your application time critical? As that piece of code is quite slow due to _ArrayAdd() increasing the size of the array each time. If you have a 1000 items that's quite slow, as AutoIt internally copies all the elements again on a ReDim.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

so basically remake the loop lower down where i need the deletes ok ta

then it will recheck the array for what exists.

Not particulary time sensitive it was done that way to add them to the array as it passes through the registry the array it uses is about 600 ish elements

Bit bigger slice so you can see what i did (not runable code though)

$sRegKey &= '|New Key #1' ; etc etc to 600 key names
; ==================================================
Global $aRegKeys = StringSplit($sRegKey, "|")
;~ _ArrayDisplay($aRegKeys, 'Total RegKeys') ;( 633)
;~ =================================================
$aUninPaths = StringSplit($sUninPath, "|")
;~ _ArrayDisplay($aUninPaths) ;( 622 )
;~ =================================================
If @OSArch = "X64" Then
    $sRegPath = 'HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall\|' & _
            'HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\|' & _
            'HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\'
ElseIf @OSArch = "X86" Then
    $sRegPath = 'HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall\|' & _
            'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\|' & _
            'HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\'
EndIf

Global $aRegPath = StringSplit($sRegPath, "|")
;~ _ArrayDisplay( $aRegPath)
;~ =================================================

_UninstallPrograms()

Func _UninstallPrograms()
    Local $aUninstallPaths[0] ; Inialize array with no elements
    For $regloop = 1 To $aRegPath[0]
        For $keyloop = 1 To $aRegKeys[0]
            If _IsRegistryExist($aRegPath[$regloop] & $aRegKeys[$keyloop], "QuietUninstallString") Then
                $sUninstallPath = RegRead($aRegPath[$regloop] & $aRegKeys[$keyloop], "QuietUninstallString") ; Find QuietUninstallString
                $aUninstallArray = _ArrayAdd($aUninstallPaths, $sUninstallPath)
            ElseIf _IsRegistryExist($aRegPath[$regloop] & $aRegKeys[$keyloop], "UninstallString") Then
                $sUninstallPath = RegRead($aRegPath[$regloop] & $aRegKeys[$keyloop], "UninstallString") ; Find UninstallString If Quiet Not Avail
                $aUninstallArray = _ArrayAdd($aUninstallPaths, $sUninstallPath)
            EndIf
        Next
    Next
;~  _ArrayDisplay($aRegPath[$regloop] & $aRegKeys[$keyloop], 'Reg Path And Keys')
    Local $aUninstallList = _ArrayUnique($aUninstallPaths)

    If Not IsArray($aUninstallList) Then
        SplashTextOn("Error Found", "No Programs To Uninstall" & @CRLF & @CRLF & _
                "Closing Program", 300, 90, -1, -1, 18)
        Sleep(300)
        For $LocationLoop = 1 To $aUninPaths[0]
            DirRemove(@ProgramFilesDir & '\' & $aUninPaths[$LocationLoop], 1) ; Program Files X86 Folder
            DirRemove(StringTrimRight(@ProgramFilesDir, 6) & '\' & $aUninPaths[$LocationLoop], 1) ; Program Files Folder
            DirRemove('C:\ProgramData' & '\' & $aUninPaths[$LocationLoop], 1) ; ProgramData Folder
            DirRemove(@AppDataDir & '\' & $aUninPaths[$LocationLoop], 1) ; AppData Roaming Folder
            DirRemove(@LocalAppDataDir & '\' & $aUninPaths[$LocationLoop], 1) ; AppData Local Folder
            DirRemove(StringTrimRight(@AppDataDir, 8) & '\LocalLow' & '\' & $aUninPaths[$LocationLoop], 1) ; AppData LocalLow Folder
        Next
        Exit
    EndIf
    _ArrayDisplay($aUninstallList)
    Local $sUninstallCount = _ArrayMax($aUninstallList)

And the uninstall like this

For $UninstallLoop = 1 To $aUninstallList[0]
        If StringInStr($aUninstallList[$UninstallLoop], 'MsiExec.exe', 1) Then ; Check For MSI Uninstaller
            Sleep(200)
            $aUninstallList[$UninstallLoop] = StringReplace($aUninstallList[$UninstallLoop], "/I", "/X") ; Change I to X to force uninstall rather than change
            $PID = Run($aUninstallList[$UninstallLoop] & ' /qb /quiet /passive /norestart') ; Start uninstall process with switches to create $PID
            GUICtrlSetData($cLabel_PID, 'Task Manager PID is =  ' & $PID)
            GUICtrlSetData($cLabel_App, $aUninstallList[$UninstallLoop])
            _ProcessWaitCloseRec($PID, 60) ; Uninstall by waiting for process to stop
            If @error < 0 Then MsgBox(64, 'Uninstall Failure', 'Failed Uninstall ' & $aUninstallList[$UninstallLoop])
            Sleep(1000)
            _WindowClose() ; Close any popup browser windows
;~          RegDelete($aRegPath[$regloop], $aRegKeys[$keyloop]) ; Delete regkey after uninstall
        Else
            Sleep(200)
            If FileExists($aUninstallList[$UninstallLoop]) Then
                $PID = Run($aUninstallList[$UninstallLoop] & ' /s /S /sp- /silent /norestart /remove /q0 /uninstall') ; Start uninstall process with switches to create $PID
                GUICtrlSetData($cLabel_PID, 'Task Manager PID is =  ' & $PID)
                GUICtrlSetData($cLabel_App, $aUninstallList[$UninstallLoop])
                _ProcessWaitCloseRec($PID, 60) ; Uninstall by waiting for process to stop
                If @error < 0 Then MsgBox(64, 'Uninstall Failure', 'Failed Uninstall ' & $aUninstallList[$UninstallLoop])
                Sleep(500)
                _WindowClose() ; Close any popup browser windows
;~          RegDelete($aRegPath[$regloop], $aRegKeys[$keyloop]) ; Delete regkey after uninstall
            EndIf
        EndIf
        GUICtrlSetData($hProgress, $iUnInstallIndex)
        $iUnInstallIndex += 1
    Next
Link to comment
Share on other sites

Any reason you use Sleep()?

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

I think you have been misinformed, as those sleep calls in that code snippet do nothing more than slow the execution of the code down. If there is going to be an error, sleeping is not the approach to avoiding them.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

erm not so much the error more to give things time to complete, i think that was why, been doing it a long time now so its often in stuff i have copied

Ill have a look and remove the unnecessary ones

Thx

Link to comment
Share on other sites

Just as an example, you could have something like this if you need to pause for a file to exist.
 

; Wait for a file to exist or the counter is reached.
Local $sFilePath = ""
Local $iCount = 0
Do
    $iCount += 1
Until FileExists($sFilePath) Or $iCount = 5 Or Not Sleep(200) ; If the file exists then the sleep will not be invoked. Note: Sleep always returns 1, so Not Sleep() is basically waiting for it to return zero, which it won't. So if the other two conditions are false then the sleep is called and the loop continues, as it doesn't return zero.
Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

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...