Wednesday, February 8, 2012

Removing applications from machines without MSI packages

In SCCM, removing of any applications is using msiexec /x <msi package name>
However this command requires msi package to be available on the client itself. Of course you can say that its not not issue that the package is readily available. Well, think again. Consider this, example Skype that was installed 2 years back on a machine perhaps version 2.0. The current version of Skype is version 4.2 and you are unable to locate the msi package for version 2.0 anyway on the internet and you have 200 clients to uninstall. What can you do.
To overcome this, I have created a vbs to perform the same actions as if you are removing the application fromt the add remove program from the control panel.
How this works, there is actually an uninstall string that is kept in the registry for this purpose. If we can retrieve this value, we can perform the same.
The key location for various products unsintallation is at
Software\Microsoft\Windows\CurrentVersion\Uninstall\<Product_GUID>
Take note that the product GUID  is unique to each msi package.
The below is the vbs that i have created to remove skype
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set WshShell = WScript.CreateObject("WScript.Shell")

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

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

For Each subkey In arrSubKeys
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Uninstall\" & Subkey
strValueName = "DisplayName"
oReg.GetStringValue _
   HKEY_LOCAL_MACHINE,strKeyPath,strValueName,StringValue

if instr(lcase(stringvalue),"skype") > 0 then

strValueName = "uninstallstring"
oReg.GetStringValue _
   HKEY_LOCAL_MACHINE,strKeyPath,strValueName,StringValue
wscript.echo stringvalue
wshshell.run stringvalue & " /quiet /norestart"
end if
Next

No comments:

Post a Comment