Jump to content

Uninstall Script help


g8rcb
 Share

Recommended Posts

I have some junky software on some boxes that needs to be uninstalled.  Unfortunately I can't just run msiexec/x {guid} /qb like I want to.  It prompts saying files are in use click ok or cancel.  Ive tried various things using autoit to call a batch that runs through various reg keys to see what version is installed and then runs the msiexec line.  The box disappears and the msi never gets called.  Anyway here are my obstacles.  #1 there are various versions so I need to read HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\ and various guids depending on the software (each machine will only have 1 version).  Then execute msiexec /x {guid} /qb  I guess sleep or winwait till the dialogue comes up saying files are in use and send the appropriate key strokes (tab then enter).  Any help would be greatly appreciately.

Link to comment
Share on other sites

Here is something I wrote to uninstall a specific piece of software on about 88 machines. Of yourse you will have to make the necessary modifications for each piece of software.

This should get you started " hopefully" .

 

Basically it will find "Edgecam 2014 R2\\unins000.exe" in the registry location then grab the silent uninstall key and run it, of course you could modify this pices to execute the commands you want.

 

#include <File.au3>
#include <array.au3>

Global $file11, $wt, $zt, $sTxt

If Not FileExists("C:\Program Files (x86)\Planit\Edgecam 2014 R2\unins000.exe") Then
    DirRemove("C:\Program Files (x86)\Planit", 1)
    Exit
EndIf


$cmd = 'REGEDIT /e c:\edge.reg HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
RunWait('"' & @ComSpec & '" /c ' & $cmd, @SystemDir, @SW_HIDE)
$file11 = "c:\edge.reg"
_FileReadToArray($file11, $sTxt)
$count - UBound($sTxt) -1


;SplashTextOn("Current LIne", "", 120, 80, -1, -1, 22, "")
For $k = 1 To $count
    ;GUIGetMsg();prevent high cpu usage
    If $k < 1 Then
        $k = 1
    EndIf
    $Snumber = $sTxt[$k]
    ;ControlSetText("Current LIne", "", "Static1", $k)
    If StringInStr($Snumber, "Edgecam 2014 R2\\unins000.exe") > 1 Then
        ;MsgBox("", "", $Snumber)
        ExitLoop
    EndIf
Next

For $j = $k To 1 Step -1
    $Snumber1 = $sTxt[$k]
    If StringInStr($Snumber1, "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall") > 1 Then
        $yt = StringSplit($Snumber1, "\")
        $zt = StringSplit($yt[8], "]")
        ;MsgBox("", "", $zt[1])
        ExitLoop
    EndIf
Next

$wt = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" & $zt[1], "QuietUninstallString")
;MsgBox("", "", $wt)
;Exit
$cmd1 = $wt
RunWait('"' & @ComSpec & '" /c ' & $cmd1, @SystemDir, @SW_HIDE)

FileDelete($file11)
DirRemove("C:\Program Files (x86)\Planit", 1)

 

 

Edited by Carm01
dumped file to array and made reading faster
Link to comment
Share on other sites

thanks...I get most everything you are doing.  I'm not sure what you are doing with stringsplit though ($yt and zt).  I know in the registry too the uninstall string on the ones I need to remove are all msiexec /I which I want to replace the /I with a /x

Link to comment
Share on other sites

If you are using " HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\ " then you will have to change the '8' to a 7 since split string is splitting that into an array, and only '7' segments exist., the last being what I am looking for which is the silent uninstall string.

 

So if HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\abc then $zt[1] = abc

so then $wt = whatever the silent uninstall string is in the registry , which is what you might need.if you need to modify that unstall key which i think is hat you are saying then you can either dump that into a variable and do a find and replace, which might be the easiest. I would need an example

 

Link to comment
Share on other sites

@g8rcb : can you identify the GUID from the application name ?

Here is a way, using my suggestion in #1 :

#include <Date.au3> ; needed for _UninstallList function

; Lists all uninstall keys
Local $aList = _UninstallList("DisplayName", "Your AppName", "UninstallString", 1)
For $i = 1 To $aList[0][0]
    MsgBox(0, "", "uninstalling " & $aList[$i][1])
    $iPid = Run($aList[$i][4] & " /qb")
    While ProcessExists($iPid)
        If WinExists("window title") Then ; title of the warning window (file in use)
            ControlSend("window title", "", "[CLASS:Button; INSTANCE:1]") ; Use something else to click on the desired button
        EndIf
        Sleep(100)
    WEnd
Next

For the "file in use" issue, the best way seems to close the opened application before running the uninstallation

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