Friday, January 15, 2010

Automatically Uninstall Applications in the Registry

In the Windows Registry there are numerous entries under HKLM that you can manipulate. One of them happen to be the Uninstall Key.

In the Uninstall Key it will have the silent uninstall key, where you can simply copy and paste and uninstall applications. To make the applications silent (if they are MSI's) you'll have to add /X as a parameter.

Here is my script in it's entirety. Essentially it enumerates the Unisntall Key and all the entries and searches for a given word or partial word located in the Display name.



Const HKEY_LOCAL_MACHINE = &H80000002
Dim yInput, xInput, vUsername, vPassword
Dim nCounter

strComputer = "."
nCounter = 0

strComputer = InputBox("Please enter Computer Name or use a period for local machine:","Input Computer Name")

If strComputer <> "." then
a strComputer=UCase(strComputer)
else
strComputer = "."
End if
If strComputer = "" then strComputer="."

Set WshShell = CreateObject("wscript.Shell")

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")

If Err.Number <> 0 Then
'strMsg=”There was a problem connecting to " & strComputer
'MsgBox "Error"
WScript.Quit
End If

strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

yInput = InputBox("Please enter any part of an application you want to Uninstall:","Input AppName")



On Error Resume Next

For Each subkey In arrSubKeys

strDisplayName = WshShell.RegRead ("HKLM\" & strKeyPath & "\" & subkey & "\DisplayName")
sCompare = InStr(strDisplayName,yInput)

If sCompare > 0 Then
strUninstall = WshShell.RegRead ("HKLM\" & strKeyPath & "\" & subkey & "\UninstallString")
xInput = MsgBox("Are you sure you want to delete: " & strDisplayName,4,"Confirmation")
If xInput = 6 then
If strComputer = "." Then
WshShell.Run strUninstall & " /qn /norestart", 7, True
Else
WshShell.Run "psexec \\" & strComputer & " " & strUninstall & " /qn /norestart", 7, True
End If

MsgBox strDisplayName & " has been uninstalled!"
End If
nCounter = nCounter + 1
End If

Next

MsgBox "Finished Running Script: " & nCounter & " items found."

If (nCounter = 0) then
MsgBox "Sorry no results were found that contain " & yInput & "!"
End If


No comments:

Post a Comment

Generating "Always On Top" NSWindow in macOS across all detected displays

Also: Using UIKit & Cocoa Frameworks using Objective-C In m acOS or OS X , written in either Objective-C or Swift  Langues, you m...