#85309 - 2002-03-13 10:43 PM
MSI Automation via KIX 4.02
|
Alex Khassin
Lurker
Registered: 2002-03-13
Posts: 4
|
So, I am not having any luck retrieving any info from the WindowsInstaller::Installer object in KIX.
The following VBscript code lists the MSI product IDs for all products installed on this system:
code:
Dim installer, Products
Set installer = Nothing Set installer = Wscript.CreateObject("WindowsInstaller.Installer")
Set Products = installer.Products For Each product In Products Wscript.Echo product Next
Set Products = Nothing Set installer = Nothing
That works fine. The same code in KIX, however, does not list anything:
code:
$installer = CreateObject("WindowsInstaller.Installer")
$Products = $installer.Products For Each $product In $Products ? $product Next
Other COM code such as the WMI example in the KIX 4.02 doc ($Drives = GetObject("winmgmts:").ExecQuery("select Name,DriveType from Win32_LogicalDisk") ) does work.
I must be missing something very simple.
Any help would be greatly appreciated - I don't want to have to use two different languages for a single task.
Also, can someone clarify the difference between GetObject() and CreateObject()?
TIA
|
Top
|
|
|
|
#85310 - 2002-03-13 11:58 PM
Re: MSI Automation via KIX 4.02
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
kix32 crashes on this for me...
code:
$installer = CreateObject("WindowsInstaller.Installer") ? $installer $Products = $installer.Products ? $Products For Each $product In $Products ? $product Next
with the output of quote:
C:\Documents and Settings\conrad>kix32 "C:\Documents and Settings\conrad\Desktop \msi.kix"
1403404 1404228
C:\Documents and Settings\conrad>
and then I get KIX32 has encounters errors, do you want to send a report to M$...
on winXP with local admin
|
Top
|
|
|
|
#85311 - 2002-03-14 05:56 PM
Re: MSI Automation via KIX 4.02
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
It crashes in win2k also...
|
Top
|
|
|
|
#85312 - 2002-03-20 08:02 PM
Re: MSI Automation via KIX 4.02
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
bump... Anyone gotten this to work??
|
Top
|
|
|
|
#85313 - 2002-03-20 08:47 PM
Re: MSI Automation via KIX 4.02
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Stating the obvious: The error occurs when the FOR EACH line is executed. [ 20 March 2002, 21:03: Message edited by: Howard Bullock ]
|
Top
|
|
|
|
#85315 - 2002-03-21 02:56 AM
Re: MSI Automation via KIX 4.02
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11623
Loc: CA
|
SHAWN Is Da-Man!
The code works fine for me... it reports back all the GUID IDs for my installs.
Now! what is the purpose of getting these ID numbers?
|
Top
|
|
|
|
#85316 - 2002-03-21 03:05 AM
Re: MSI Automation via KIX 4.02
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Ok. I understand the code. But why does the "for each" fail? [ 21 March 2002, 03:05: Message edited by: Howard Bullock ]
|
Top
|
|
|
|
#85317 - 2002-03-21 03:51 AM
Re: MSI Automation via KIX 4.02
|
Alex Khassin
Lurker
Registered: 2002-03-13
Posts: 4
|
That does indeed work but it's extremely slow compared to the same operation in VBscript.
You won't see it with Products but if you have Office 2000 or XP installed, you should have several hundreds Components installed.
Enumerating them is just too slow:
code:
break on
$installer = CreateObject("WindowsInstaller.Installer")
for $i = 0 to $installer.Components.count
? $installer.Components.item($i)
next
exit 1
And what exactly is the difference between GetObject and CreateObject?
And to answer NTDOC, the ability to access MSI information would allow a KIX script to see if, say, a particular part of Office was installed and from where and under which Suite, etc.
|
Top
|
|
|
|
#85319 - 2002-03-21 04:23 AM
Re: MSI Automation via KIX 4.02
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Shawn, you seem to have a good handle on this. What is the difference between what you did above and using "For each"? [ 21 March 2002, 04:23: Message edited by: Howard Bullock ]
|
Top
|
|
|
|
#85321 - 2002-03-21 05:01 AM
Re: MSI Automation via KIX 4.02
|
Alex Khassin
Lurker
Registered: 2002-03-13
Posts: 4
|
Thanks, Shawn
BTW, the for loop would need to go to count - 1 as we start from 0.
If you could just enlighten me to the GetObject and CreateObject difference, I would greatly appreciate it.
And Ruud definately needs to work on some performance issue in the nested collections reference and the foreach which may be the same underlying problem.
Until then, I think I'll stick to VBscript for this MSI project.
|
Top
|
|
|
|
#85323 - 2002-03-21 05:06 AM
Re: MSI Automation via KIX 4.02
|
Shawn
Administrator
Registered: 1999-08-13
Posts: 8611
|
I tried that. It was still causing grief
Let me try here:
<
Ok that worked, let me edit post...
Ok ... it was the equal sign after the <
i had to leave off the ; ???
The difference between getobject and createobject. Here's some web info:
quote:
CreateObject vs. GetObject: What's the Difference?
Besides minor differences in the syntax, the CreateObject and GetObject functions are used in different contexts. The differences are discussed in the VBScript documentation, but can be summarized as follows:
CreateObject is used to create an interface to a new instance of an application. Use CreateObject when it's not certain whether the application to integrate is running. For example: Set xl = CreateObject("Excel.Application")
starts Microsoft Excel. The object returned in xl is a reference to the Excel.Application object just created.
GetObject is used with an application that's already running, or to start an application with a file already loaded. For example: Set xlBook = GetObject("C:\TEST.XLS")
would start Microsoft Excel with the file Test.xls already loaded. The object returned would be a reference to the Workbook object representing the just opened Test.xls file.
I like to think that CreateObject creates a running instance of a specific application or a specific DLL or EXE. GetObject is like starting a COM shortcut. Your providing the name (called a moniker) of an abstract thing. Kinda like file associations in Windows. Starting COM objects indirectly.
-Shawn [ 21 March 2002, 05:24: Message edited by: Shawn ]
|
Top
|
|
|
|
#85324 - 2002-03-21 05:15 AM
Re: MSI Automation via KIX 4.02
|
Les
KiX Master
Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
|
|
Top
|
|
|
|
#85327 - 2002-03-21 08:32 PM
Re: MSI Automation via KIX 4.02
|
Alex Khassin
Lurker
Registered: 2002-03-13
Posts: 4
|
GUIDs are not really published anywhere 'central' and the numbers are fairly random. Sometimes each manufacturer will publish the GUIDs of certain apps such as the case for Office XP (there is a KB article on it).
However, you can find the GUID for any Product from its MSI file by inspecting the ProductID Property in the Properties table of the MSI file with Orca (the MSI database editor from the MSI SDK) or with the following command:
code:
cscript //NoLogo MSIRunSQL.vbs <msifile> "SELECT Value from Property where Property = 'ProductCode'"
You can download MSIRunSQL.vbs from http://am.net/LIB/TOOLS/AM/MSIRunSQL.vbs
You can also download http://am.net/LIB/TOOLS/AM/MSIdump.vbs - be sure to open the script and read the usage notes at the begining. Dumping everything can take several minutes and will result in a rather large .INI file. I suggest you start with:
code:
cscript //NoLogo MSIdump.vbs %temp%\test.ini } } 0 1 1 1
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
0 registered
and 557 anonymous users online.
|
|
|