/build/static/layout/Breadcrumb_cap_w.png

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 [:)]

0 Comments   [ + ] Show comments

Answers (8)

Posted by: Foleymon 13 years ago
Orange Senior Belt
2
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
Red Belt
1
You have a hundred and fifty packages from the same vendor?!? Hmmm...
Posted by: neksh 13 years ago
Senior Yellow Belt
0
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!
Posted by: neksh 13 years ago
Senior Yellow Belt
0
I know it is ugly, but I'm just going to have my batch file call this vbs:



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: Foleymon 13 years ago
Orange Senior Belt
0
GREAT
Glad you could make it work!! [:)]
Posted by: anonymous_9363 13 years ago
Red Belt
0
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.
Posted by: neksh 13 years ago
Senior Yellow Belt
0
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
Second Degree Green Belt
0
And here we also see crappy packaging from vendors - same product code for each product? Someone should fire their packagers.
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ