how to find the product code .msi which east put in the command line of the program
-
Tuesday, June 03, 2008 12:59 PM
Hi,
I try to find the product code of the .msi for must execute de uninstalaltion.
Thx,
Nicolas Lombard
Answers
-
Wednesday, June 04, 2008 8:19 PM
Hi,
I was having some trouble running Andy's code, so I wrote a quick VBScript example that outputs the ProductName and ProductCode. The script requires an MSI name at the command-line and isn't especially robust, but worked on several MSIs for me. Output and script below.
It should be noted, that it's easier to just load up ORCA or another MSI editor to just look at the ProductCode property.
Example command-line and output for GetMSIProductCode.vbs
C:\>cscript GetMSIProductCode.vbs ccmsetup.msi
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.
Database (MSI) = ccmsetup.msi
ProductName = SMS Client Setup Bootstrap
ProductCode = {292C90B8-E8FA-47A3-92BB-F2F62AC109FC}
Code Snippet' GetMSIProductCode.vbs
Option Explicit
' Variables
Const msiOpenDatabaseModeReadOnly = 0' Get command-line arguements
Dim argCount:argCount = Wscript.Arguments.Count' Connect to the Windows Installer object.
On Error Resume Next
Dim installer : Set installer = Nothing
Set installer = Wscript.CreateObject("WindowsInstaller.Installer") : CheckError' Open the database (read-only).
Dim databasePath:databasePath = Wscript.Arguments(0)
Dim openMode : openMode = msiOpenDatabaseModeReadOnly
Dim database : Set database = installer.OpenDatabase(databasePath, openMode) : CheckError' Extract language info and compose report message
Wscript.Echo "Database (MSI) = " & databasePath
Wscript.Echo "ProductName = " & ProductName(database)
Wscript.Echo "ProductCode = " & ProductCode(database)' Clean up
Set database = nothing
Wscript.Quit 0' Get the Property.ProductName value.
Function ProductName(database)
On Error Resume Next
Dim view : Set view = database.OpenView("SELECT `Value` FROM `Property` WHERE `Property` = 'ProductName'")
view.Execute : CheckError
Dim record : Set record = view.Fetch : CheckError
If record Is Nothing Then ProductName = "Not specified!" Else ProductName = record.StringData(1)
End Function' Get the Property.ProductCode value.
Function ProductCode(database)
On Error Resume Next
Dim view : Set view = database.OpenView("SELECT `Value` FROM `Property` WHERE `Property` = 'ProductCode'")
view.Execute : CheckError
Dim record : Set record = view.Fetch : CheckError
If record Is Nothing Then ProductCode = "Not specified!" Else ProductCode = record.StringData(1)
End FunctionSub CheckError
Dim message, errRec
If Err = 0 Then Exit Sub
message = Err.Source & " " & Hex(Err) & ": " & Err.Description
If Not installer Is Nothing Then
Set errRec = installer.LastErrorRecord
If Not errRec Is Nothing Then message = message & vbNewLine & errRec.FormatText
End If
Fail message
End SubSub Fail(message)
Wscript.Echo message
Wscript.Quit 2
End SubHere are some great resources that I stumbled across. The example script above is a modification of one of the MSI script examples in the Windows SDK.
Uninstall MSI with VBScript
http://juice.altiris.com/download/3859/uninstall-msi-with-vbscript
How Can I Retrieve the Subject Property for a .MSI File?
http://www.microsoft.com/technet/scriptcenter/resources/qanda/jan07/hey0110.mspx
Microsoft ® Windows Server® 2003 R2 Platform SDK Web Install*
22 MSI Script Examples (after Windows SDK installation)
C:\Program Files\Microsoft SDKs\Windows\v6.0\Samples\SysMgmt\MSI\scripts
* I already have several versions of the SDK installed, so I didn't specifically download and test with the Windows Server 2003 R2 Platform SDK ... it was just the latest that I saw on the download center.
Anyway, I hope this helps!
Jim Bradbury
All Replies
-
Tuesday, June 03, 2008 2:57 PM
That is the forum for the SCCM SDK. Is your question somehow SCCM related?
-
Tuesday, June 03, 2008 7:43 PM
Hi,
This is not a complete solution, but you should be able to reuse a part of this code to do what you want.
I remember looking for an example to of gettting the product code ... not easy to find one. Andy wrote this for a customer a couple of months back.
Code SnippetRepairClient.vbs
Wscript.Quit ExecuteCommandLine("msiexec", "/f " & GetCmClientProductCode, 1)
Function GetCmClientProductCode()
'// Default to empty variable return
GetCmClientProductCode = vbEmpty
'// Variables
Dim installer: Set installer = CreateObject("WindowsInstaller.Installer")
Dim productName: productName = "SMS Advanced Client"
Dim productCode
Const msiOpenDatabaseModeReadOnly = 0
Const msiInstallStateNotUsed = -7
'// Check for obj err
If err.number <> 0 Then Exit Function
'// Verify the client is available to find
If installer.ProductState(productName) <> msiInstallStateUnknown Then
'// Search for the client
For Each productCode In installer.Products
If LCase(productName) = LCase(installer.ProductInfo(productCode, "ProductName")) Then
GetCmClientProductCode = productCode
Exit Function
End If
Next
Else
'// Client isn't installed or cannot be found by the correct name
End If
End FunctionFunction ExecuteCommandLine(File, Params, WindowStyle)
Dim wsh: Set wsh = CreateObject("WScript.Shell")
ExecuteCommandLine = wsh.Run("""" & file & """ " & Params, WindowStyle, True)
End FunctionI hope this helps!
Jim Bradbury
-
Wednesday, June 04, 2008 8:13 AM
Yes but it's when i make a custom program by code.
For create a program for uninstall product i must find the product code.
-
Wednesday, June 04, 2008 8:15 AM
I devellop in c# but i try to convert this vbs in c#
thx
-
Wednesday, June 04, 2008 1:06 PM
I'm not sure what you're trying to do, but the example has a section of code that shows how to get the product code that's been defined for an MSI. In the example, the product code is then used to repair an MSI installation of the "SMS Advanced Client".
If you already have a custom MSI, I imagine you would pull out product code in the same way, but I could be mistaken. You might tweak the code to list all of the product names and product codes ... then add the logic to make a specific selection.
If you are looking to create a custom MSI with a product code, you might take a look at the following knowledge base article:
How To Create Patch Files for the MSDE 2000 Sample.msi File
http://support.microsoft.com/kb/314131Unfortunately, I don't play with MSI files much. If you have additional questions, you might want to do a quick search for a more relevant forum / newsgroup (something Windows Installer / MSI specific).
Thanks,
Jim Bradbury
-
Wednesday, June 04, 2008 1:19 PM
Thank youy for your quickly response but i not find that i would
I try to another newsgroup/forum
-
Wednesday, June 04, 2008 8:19 PM
Hi,
I was having some trouble running Andy's code, so I wrote a quick VBScript example that outputs the ProductName and ProductCode. The script requires an MSI name at the command-line and isn't especially robust, but worked on several MSIs for me. Output and script below.
It should be noted, that it's easier to just load up ORCA or another MSI editor to just look at the ProductCode property.
Example command-line and output for GetMSIProductCode.vbs
C:\>cscript GetMSIProductCode.vbs ccmsetup.msi
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.
Database (MSI) = ccmsetup.msi
ProductName = SMS Client Setup Bootstrap
ProductCode = {292C90B8-E8FA-47A3-92BB-F2F62AC109FC}
Code Snippet' GetMSIProductCode.vbs
Option Explicit
' Variables
Const msiOpenDatabaseModeReadOnly = 0' Get command-line arguements
Dim argCount:argCount = Wscript.Arguments.Count' Connect to the Windows Installer object.
On Error Resume Next
Dim installer : Set installer = Nothing
Set installer = Wscript.CreateObject("WindowsInstaller.Installer") : CheckError' Open the database (read-only).
Dim databasePath:databasePath = Wscript.Arguments(0)
Dim openMode : openMode = msiOpenDatabaseModeReadOnly
Dim database : Set database = installer.OpenDatabase(databasePath, openMode) : CheckError' Extract language info and compose report message
Wscript.Echo "Database (MSI) = " & databasePath
Wscript.Echo "ProductName = " & ProductName(database)
Wscript.Echo "ProductCode = " & ProductCode(database)' Clean up
Set database = nothing
Wscript.Quit 0' Get the Property.ProductName value.
Function ProductName(database)
On Error Resume Next
Dim view : Set view = database.OpenView("SELECT `Value` FROM `Property` WHERE `Property` = 'ProductName'")
view.Execute : CheckError
Dim record : Set record = view.Fetch : CheckError
If record Is Nothing Then ProductName = "Not specified!" Else ProductName = record.StringData(1)
End Function' Get the Property.ProductCode value.
Function ProductCode(database)
On Error Resume Next
Dim view : Set view = database.OpenView("SELECT `Value` FROM `Property` WHERE `Property` = 'ProductCode'")
view.Execute : CheckError
Dim record : Set record = view.Fetch : CheckError
If record Is Nothing Then ProductCode = "Not specified!" Else ProductCode = record.StringData(1)
End FunctionSub CheckError
Dim message, errRec
If Err = 0 Then Exit Sub
message = Err.Source & " " & Hex(Err) & ": " & Err.Description
If Not installer Is Nothing Then
Set errRec = installer.LastErrorRecord
If Not errRec Is Nothing Then message = message & vbNewLine & errRec.FormatText
End If
Fail message
End SubSub Fail(message)
Wscript.Echo message
Wscript.Quit 2
End SubHere are some great resources that I stumbled across. The example script above is a modification of one of the MSI script examples in the Windows SDK.
Uninstall MSI with VBScript
http://juice.altiris.com/download/3859/uninstall-msi-with-vbscript
How Can I Retrieve the Subject Property for a .MSI File?
http://www.microsoft.com/technet/scriptcenter/resources/qanda/jan07/hey0110.mspx
Microsoft ® Windows Server® 2003 R2 Platform SDK Web Install*
22 MSI Script Examples (after Windows SDK installation)
C:\Program Files\Microsoft SDKs\Windows\v6.0\Samples\SysMgmt\MSI\scripts
* I already have several versions of the SDK installed, so I didn't specifically download and test with the Windows Server 2003 R2 Platform SDK ... it was just the latest that I saw on the download center.
Anyway, I hope this helps!
Jim Bradbury
-
Thursday, June 05, 2008 7:04 AM
Thank you for this response.
I had already found something but your script helped me well.
thx

