[download id=”58″]
Today I am working on a installation package for iTunes 10.5.
We have to deploy it via Configuration Manager 2007 R2.
Beforehand we used to manually insert all product codes in the uninstall/upgrade script, to make sure that all version of itunes and support programs was uninstalled.
This was because we have experienced problems when upgrading, without removing old version first.
Now I have created a function that automatically can search both 32bit and 64bit registry for a specific product, and return the product code which can be used for automatic uninstall.
Here is the script:
Function GetProductCode(strName) Dim strComputer, oReg, strKeyPath, strValueNAme, strValue, arrSubKeys, subkey Const HKEY_LOCAL_MACHINE = &H80000002 strComputer = "." arrSubKeys = Null Set ObjShell = CreateObject("WScript.Shell") ObjShell.LogEvent 4, "Seaching in registry for installed products by search term: " & strName Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\default:StdRegProv") strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys If Not IsNull(arrSubKeys) Then For Each subkey In arrSubKeys ' WScript.Echo subkey strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & subkey strValueName = "DisplayName" oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue If InStr(LCase(strValue), LCase(strName)) > 0 Then strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & subkey strValueName = "UninstallString" oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue ObjShell.LogEvent 4, "Found Installed "& strName &" product Code: " & Replace(Replace(strValue, "MsiExec.exe /X",""), "MsiExec.exe /I","") If strValue <> "" Then GetProductCode = Replace(Replace(strValue, "MsiExec.exe /X",""), "MsiExec.exe /I","") End If End If Next End If arrSubKeys = Null ObjShell.LogEvent 4, "Seaching in Wow6432Node registry for installed products by search term: " & strName strKeyPath = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys If Not IsNull(arrSubKeys) Then For Each subkey In arrSubKeys ' WScript.Echo subkey strKeyPath = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" & subkey strValueName = "DisplayName" oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue If InStr(LCase(strValue), LCase(strName)) > 0 Then strKeyPath = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" & subkey strValueName = "UninstallString" oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue ObjShell.LogEvent 4, "Found Installed "& strName &" product Code: " & Replace(Replace(strValue, "MsiExec.exe /X",""), "MsiExec.exe /I","") If strValue <> "" Then GetProductCode = Replace(Replace(strValue, "MsiExec.exe /X",""), "MsiExec.exe /I","") End If End If Next End If End Function
use the function as the following:
WScript.Echo GetProductCode("itunes") WScript.Echo GetProductCode("bonjour") WScript.Echo GetProductCode("apple mobile") WScript.Echo GetProductCode("apple application") WScript.Echo GetProductCode("apple software update")
Download the script above for the full implementation
Next article decribes how to use it in a Uninstall/Install aka. upgrade scenario. Find it here
Happy Scripting!
Thanks for this solution!
I wait for your next post.
“Next article will decribe how to use it in a Uninstall/Install aka. upgrade scenario”
Really looking forward to enjoy this article to!
NExt post has been uploaded!
http://blog.coretech.dk/jgs/vbscript-uninstall-and-install-itunes-upgrade-using-automatic-product-code-finder-script-or-any-other-product-by-using-product-name/
Ha Ha, wow, that was fast!
Appreciate it!
ha ha! .. yeah! .. thanks for reminding for to finish the incomplete article! .. i had forgot all about it 🙂
I am getting regiry values from
“SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall”
However im using below path
“SOFTWAREMicrosoftWindowsCurrentVersionUninstall”
on 64 bit machine
Hello Guatam
i have tested on 64bit and it Works.
i just did an extra test, only checking only in “SOFTWAREMicrosoftWindowsCurrentVersionUninstall” for a product that did not appear in “SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall”.
and it found it without problem.
this was on 64bit Windows 8 machine (script was created and tested on Win7 64bit originally).
thx for your excellent work
i have use above script and detect the value but getting uninstall