PnoT Posted December 15, 2009 Posted December 15, 2009 I apologize in advance if this has been discussed before but I can't seem to find something that works to my specific needs. I can't find a script that will find software in the registry and automatically run the uninstall for it. I found this piece of code but it replies with a "success" no matter if the software is installed or not. I've tried to modify it to report correctly with no luck so far. Func WMIService($host) ;Connects to WMI Service $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $host & "\root\cimv2") If not IsObj($objWMIService) Then return 0 return $objWMIService EndFunc Func WMIQuery($objWMIService,$strWMIQuery) ;Perform WMI Query with Query String and Data Return Parameters $colItems = $objWMIService.ExecQuery($strWMIQuery) For $objItem in $colItems ;MsgBox(0,"asdasd",$objitem.name) $objItem.Uninstall() Next return 1 EndFunc $objWMIService = WMIService("localhost") ;WMIService Object - Establish Connection If $objWMIService = 0 Then Exit ;~ $objWMIService1 = WMIService("localhost") ;WMIService Object - Establish Connection ;~ If $objWMIService1 = 0 Then Exit $soft1 = WMIQuery($objWMIService,"Select * from Win32_Product Where Name like '%Photoshop%'") If $objWMIService = 0 Then MsgBox(0,"Error","An error have accured") Exit EndIf $objWMIService = 0 MsgBox(0,"Success","Uninstall compleeted successfully")
GEOSoft Posted December 15, 2009 Posted December 15, 2009 (edited) This should do it. Just change $sSearch to whatever it is you want to uninstall (any portion of the string) This example gets everything with "Photoshop" in the name. $sBase = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" $iEval = 1 $sSearch = "Photoshop" While 1 $sUninst = "" $sDisplay = "" $sCurrent = RegEnumKey($sBase, $iEval) If @Error Then ExitLoop $sKey = $sBase & $sCurrent $sDisplay = RegRead($sKey, "DisplayName") If StringRegExp($sDisplay, "(?i).*" & $sSearch & ".*") Then $sUninst = RegRead($sKey, "UninstallString") If $sUninst Then If MsgBox(36, "Result", "Are you sure you want to uninstall " & _ $sDisplay & "?") = 6 Then RunWait($sUninst) EndIf EndIf $iEval += 1 WEnd EDIT: Spellink EDIT 2: Actually this is better since it gives you the option to cancel $sBase = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" $iEval = 1 $sSearch = "Creative" While 1 $sUninst = "" $sDisplay = "" $sCurrent = RegEnumKey($sBase, $iEval) If @Error Then ExitLoop $sKey = $sBase & $sCurrent $sDisplay = RegRead($sKey, "DisplayName") If StringRegExp($sDisplay, ".*" & $sSearch & ".*") Then $sUninst = RegRead($sKey, "UninstallString") If $sUninst Then $sMsg = MsgBox(35, "Result", "Are you sure you want to uninstall " & $sDisplay & "?") If $sMsg = 6 Then RunWait($sUninst) ElseIf $sMsg = 2 Then ExitLoop EndIf EndIf EndIf $iEval += 1 WEnd Edited December 15, 2009 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
PnoT Posted December 15, 2009 Author Posted December 15, 2009 This is exactly what i was looking for thank you so much. The name match must be exact case but i can live with!
P3X775 Posted January 10, 2010 Posted January 10, 2010 (edited) I would like to take this script two steps further by having it first, actually answer the questions in the uninstaller, and then run another program when complete. We have a program that can only updated by uninstalling the previous version and then installing the new one. If $sMsg = 6 Then RunWait($sUninst) ;runs the uninstall function we created to finish uninstalling our program uninstallprogram() Do $process = ProcessExists("unwise.exe") until $process = 0 ;runs the install function of the next program install() ElseIf $sMsg = 2 Then ExitLoop EndIf I have tried it several different ways even substituting a message box for the uninstall function and the script never goes beyond RunWait($sUninst) It launces the uninstaller and that's where it stays. Can anyone provide any help on this? Thank you. Edited January 10, 2010 by P3X775
AdmiralAlkex Posted January 10, 2010 Posted January 10, 2010 It launces the uninstaller and that's where it stays.RunWait() pauses the script so what do you expect? You want Run(). And please read the helpfile next time. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface
robinsiebler Posted June 7, 2012 Posted June 7, 2012 I've been trying to modify this script to also search HKLMSOFTWAREMicrosoftWindowsCurrentVersionInstallerUserDataS-1-5-18Products, but I'm flailing. Any takers?
Taomyn Posted February 19, 2013 Posted February 19, 2013 (edited) Just wanted to return the favour and post my take on this script. I use it with LogMeIn tasks for uninstalling software from the command-line with no prompting or restarts: expandcollapse popup#RequireAdmin #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=n #AutoIt3Wrapper_Change2CUI=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** Opt('TrayAutoPause', 0) Opt('TrayMenuMode', 1) Opt('TrayIconHide', 1) $sBase_x64 = "HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" $sBase_x32 = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" $iEval = 1 $iLogCount = 1 ;Check if app name and logfile name passed as parameter If $CmdLine[0] <> 2 Then ConsoleWrite("Error! - Missing parameters: {App Name} {LogFileName}" & @CRLF) Exit 1 Else Local $sSearch = $CmdLine[1] Local $sLogFile = $CmdLine[2] EndIf ; 32bit & 64bit ConsoleWrite("Checking " & $sBase_x32 & @CRLF) While 1 $sUninst = "" $sDisplay = "" $sCurrent = RegEnumKey($sBase_x32, $iEval) If @Error Then ExitLoop $sKey = $sBase_x32 & $sCurrent $sDisplay = RegRead($sKey, "DisplayName") If StringRegExp($sDisplay, "(?i).*" & $sSearch & ".*") Then $sUninst = RegRead($sKey, "UninstallString") If $sUninst Then ConsoleWrite("Uninstalling " & $sDisplay & @CRLF) ConsoleWrite($sUninst & " /quiet /passive /qn /log " & $sLogFile & "_" & $iLogCount & ".log /norestart" & @CRLF) RunWait($sUninst & " /quiet /passive /qn /log " & $sLogFile & "_" & $iLogCount & ".log /norestart") $iLogCount +=1 EndIf EndIf $iEval += 1 WEnd $iEval = 1 ConsoleWrite("Checking " & $sBase_x64 & @CRLF) While @CPUArch = "X64" $sUninst = "" $sDisplay = "" $sCurrent = RegEnumKey($sBase_x64, $iEval) If @Error Then ExitLoop $sKey = $sBase_x64 & $sCurrent $sDisplay = RegRead($sKey, "DisplayName") If StringRegExp($sDisplay, "(?i).*" & $sSearch & ".*") Then $sUninst = RegRead($sKey, "UninstallString") If $sUninst Then ConsoleWrite("Uninstalling " & $sDisplay & @CRLF) ConsoleWrite($sUninst & " /quiet /passive /qn /log " & $sLogFile & "_" & $iLogCount & ".log /norestart" & @CRLF) RunWait($sUninst & " /quiet /passive /qn /log " & $sLogFile & "_" & $iLogCount & ".log /norestart") $iLogCount +=1 EndIf EndIf $iEval += 1 WEnd It copes with 64bit PCs and the two areas in the registry, therefore for example if you install both 32bit and 64bit versions of Java, it will remove both. Edited February 19, 2013 by Taomyn
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now