I want to automate the removal of an application using a query to the registry using Visual Basic Script (VBS) to get the Uninstall string (the command that would be executed if you went into Control Panel Add/Remove and Un-installed a specific application).
I have workstations with a mix of Windows 7 and Windows XP in x32 and x64 bit architectures. And the location of Uninstall settings change across different architectures because 32 bit applications have a separate Registry area on 64 bit operating systems.
I don't want to have to specify the entire DisplayName but a substring to search on.
This is my Googled-together answer to the problem.
Using:
To return the Operating Systems bit type: http://csi-windows.com/toolkit/csi-getosbits
Find the correct registry uninstall key by looping through the Uninstall Registry Key/s using - Uninstall an Application Using GUID from Registry
'use this with
' oWshShell.run uiString("PROD Enterprise App 2007 RE")
wscript.echo uiString("PROD Enterprise App 2007 RE")
wscript.echo uiString("DEV Enterprise App 2007 RE")
Function getBits()
' from http://csi-windows.com/toolkit/csi-getosbits
getBits = GetObject("winmgmts:root\cimv2:Win32_Processor='cpu0'").AddressWidth
End Function
Function uiString(strName)
' from http://aka-community.symantec.com/connect/zh-hant/user/cableguy41
On error resume Next
Dim WshShell, oReg, keyname
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set WshShell = CreateObject("WScript.Shell")
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
' the registry uninstall key shifts for 32bit applications on a 64bit OS
if getBits = 64 then
strKeyPath = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
else
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
end if
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
keyname = ""
keyname = wshshell.RegRead("HKEY_LOCAL_MACHINE\" & strKeyPath & "\" & subkey & "\DisplayName")
'wscript.echo subkey
'wscript.echo keyname
' use the instr function to check for part of the DisplayName
If Instr ( keyname, strName ) > 0 then
uiString = wshshell.RegRead("HKEY_LOCAL_MACHINE\" & strKeyPath & "\" & subkey & "\UninstallString")
exit function
End If
Next
uiString = ""
Set WshShell = Nothing
set ObjReg = Nothing
end function
0 Comments