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

Comments

Please log in to comment

Community Chosen Answer

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
Answered 08/29/2011 by: Foleymon
Orange Senior Belt

Please log in to comment
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

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!
Answered 08/29/2011 by: neksh
Senior Yellow Belt

Please log in to comment
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!
Answered 08/29/2011 by: neksh
Senior Yellow Belt

Please log in to comment
0
GREAT
Glad you could make it work!! [:)]
Answered 08/29/2011 by: Foleymon
Orange Senior Belt

Please log in to comment
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.
Answered 08/30/2011 by: VBScab
Red Belt

Please log in to comment
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.
Answered 08/30/2011 by: neksh
Senior Yellow Belt

Please log in to comment
1
You have a hundred and fifty packages from the same vendor?!? Hmmm...
Answered 08/31/2011 by: VBScab
Red Belt

Please log in to comment
0
And here we also see crappy packaging from vendors - same product code for each product? Someone should fire their packagers.
Answered 08/31/2011 by: Arminius
Second Degree Green Belt

Please log in to comment
Answer this question or Comment on this question for clarity