Extracting uninstallstring or ProductCode from MSI with batch file
Hello,
I've been working for a few weeks on automating the installation of about 150 MSI packages on 150 computers. Everything is working except one thing: the uninstallation of the old MSI package before the installation of the new one.
Everything I've built revolves around .bat files and command line stuff, and I was wondering if there is a way to automatically extract the ProductCode or UninstallString out of these MSIs so I can use the ProductCode as the parameter of the msiexec.exe /x command.
Thanks~!
PS: I've tried using the syntax "msiexec.exe /x "Name of MSI.msi"" but that isn't working because for every update we get the MSI changes names and product version. The vendor leaves the ProductCode the same for each MSI, but they update the product version... so the syntax using the name of the MSI isn't working... I need the product code [:)]
I've been working for a few weeks on automating the installation of about 150 MSI packages on 150 computers. Everything is working except one thing: the uninstallation of the old MSI package before the installation of the new one.
Everything I've built revolves around .bat files and command line stuff, and I was wondering if there is a way to automatically extract the ProductCode or UninstallString out of these MSIs so I can use the ProductCode as the parameter of the msiexec.exe /x command.
Thanks~!
PS: I've tried using the syntax "msiexec.exe /x "Name of MSI.msi"" but that isn't working because for every update we get the MSI changes names and product version. The vendor leaves the ProductCode the same for each MSI, but they update the product version... so the syntax using the name of the MSI isn't working... I need the product code [:)]
0 Comments
[ + ] Show comments
Answers (8)
Please log in to answer
Posted by:
Foleymon
13 years ago
Do you think something like this would work for you?
Function GetMSIProductCode(msi) ' Return the Product Code from a given msi
On Error Resume Next
GetMSIProductCode=""
If msi = "" Then Exit Function End If
Dim FS, TS, WI, DB, View, Rec
Set WI = CreateObject("WindowsInstaller.Installer")
Set DB = WI.OpenDatabase(msi,2)
If Err.number Then Exit Function End If
Set View = DB.OpenView("Select `Value` From Property WHERE `Property` ='ProductCode'")
View.Execute
Set Rec = View.Fetch
If Not Rec Is Nothing Then
GetMSIProductCode=Rec.StringData(1)
End If
End Function
Posted by:
anonymous_9363
13 years ago
Posted by:
neksh
13 years ago
Wow, that was FAST and AMAZING.
Now I just have to figure out how to put that vbscript code into my batch files so I can call it and get back the value.
Either that or I need to re-write my batch files into vbscript (something I'm comfortable doing... just not what I expected having to do). :-)
THANK YOU THANK YOU THANK YOU!
Now I just have to figure out how to put that vbscript code into my batch files so I can call it and get back the value.
Either that or I need to re-write my batch files into vbscript (something I'm comfortable doing... just not what I expected having to do). :-)
THANK YOU THANK YOU THANK YOU!
Posted by:
neksh
13 years ago
I know it is ugly, but I'm just going to have my batch file call this vbs:
Thanks for the help!
Dim pCode, pathToSearch, outputFile, oFSO, oFolder, oTS
'get the arguments
If Wscript.Arguments.Count <> 2 Then
Wscript.quit
End If
outputFile = Wscript.Arguments(0)
pathToSearch = Wscript.Arguments(1)
Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(pathToSearch)
Set oTS = oFSO.CreateTextFile(outputFile,TRUE)
searchSubFolder(oFolder)
oTS.Close
set oTS = nothing
Sub searchSubFolder(currentFolder)
'output(currentFolder.Name)
'output(currentFolder.Path)
For Each oFile in currentFolder.Files
if(Right(oFile.Name,4) = ".msi") Then
'output(oFile.Name)
pCode = GetMSIProductCode(oFile.Path)
oTS.WriteLine pCode
end if
Next
For Each oFolder in currentFolder.SubFolders
searchSubFolder(oFolder)
Next
end sub
sub output(outputString)
Wscript.Echo outputString
end sub
Function GetMSIProductCode(msi) ' Return the Product Code from a given msi
On Error Resume Next
GetMSIProductCode=""
If msi = "" Then Exit Function End If
Dim FS, TS, WI, DB, View, Rec
Set WI = CreateObject("WindowsInstaller.Installer")
Set DB = WI.OpenDatabase(msi,2)
If Err.number Then Exit Function End If
Set View = DB.OpenView("Select `Value` From Property WHERE `Property` ='ProductCode'")
View.Execute
Set Rec = View.Fetch
If Not Rec Is Nothing Then
GetMSIProductCode=Rec.StringData(1)
End If
End Function
Thanks for the help!
Posted by:
anonymous_9363
13 years ago
Posted by:
neksh
13 years ago
ORIGINAL: VBScab
I can't quite see the point of extracting the PC from your new MSIs if you want to uninstall previous versions, since, by definition, the old version will have a different PC.
Yeah, I was thinking the same thing... except this vendor uses the same ProductCode for each version of their product... so it turns out this actually works okay in this case.
Posted by:
Arminius
13 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.