Page 1 of 1 1
Topic Options
#85309 - 2002-03-13 10:43 PM MSI Automation via KIX 4.02
Alex Khassin Offline
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 Offline
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
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#85311 - 2002-03-14 05:56 PM Re: MSI Automation via KIX 4.02
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
It crashes in win2k also...
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#85312 - 2002-03-20 08:02 PM Re: MSI Automation via KIX 4.02
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
bump... Anyone gotten this to work??
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#85313 - 2002-03-20 08:47 PM Re: MSI Automation via KIX 4.02
Howard Bullock Offline
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 ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#85314 - 2002-03-21 02:50 AM Re: MSI Automation via KIX 4.02
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Does this help at all ?

break on

$installer = CreateObject("WindowsInstaller.Installer")

for $i = 0 to $installer.Products.count

 ? $installer.products.item($i)

next

exit 1


-Shawn

Top
#85315 - 2002-03-21 02:56 AM Re: MSI Automation via KIX 4.02
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
SHAWN Is Da-Man! [Big Grin]

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 Offline
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 ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#85317 - 2002-03-21 03:51 AM Re: MSI Automation via KIX 4.02
Alex Khassin Offline
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
#85318 - 2002-03-21 04:16 AM Re: MSI Automation via KIX 4.02
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Try this, its basically what you originally posted and should give you a big performance boost (referencing objects through nested properties and collections can be painfully slow sometimes)

break on

$installer = CreateObject("WindowsInstaller.Installer")

$components = $installer.components

for $i = 0 to $components.count
 ? $components.item($i)
next

exit 1


-Shawn

[ 21 March 2002, 04:19: Message edited by: Shawn ]

Top
#85319 - 2002-03-21 04:23 AM Re: MSI Automation via KIX 4.02
Howard Bullock Offline
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 ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#85320 - 2002-03-21 04:51 AM Re: MSI Automation via KIX 4.02
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Not much difference really. Every collection interface has an ITEM and COUNT property. That never changes. It's just that we have numerous ways that we can walk the collection. Here's another one, this might be the fastest work-around method:

break on

$installer = CreateObject("WindowsInstaller.Installer")

$components = $installer.components
$count = $components.count

while $i < = $count
 ? $components.item($i)
 $i=$i+1
loop

exit 1


I can't get the less-than sign posted ! Whats up with that ? Anyway...

The FOR EACH method just implements an internalized counter and a conditional statement on our behalf, and provides a convenient mechanism for pulling out and assigning the object. Other than that, its exactly the same thing. But in the case of kixtart's builtin enumeration, I think you guys have found a bug. Not too sure if its kixtart or windowsinstaller that is causing the problem. Only one guy can answer so I've sent off an email to Ruud and asked him to comment.

-Shawn

[ 21 March 2002, 05:08: Message edited by: Shawn ]

Top
#85321 - 2002-03-21 05:01 AM Re: MSI Automation via KIX 4.02
Alex Khassin Offline
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
#85322 - 2002-03-21 05:03 AM Re: MSI Automation via KIX 4.02
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
C'mon Shawn, you know your html. &lt will get you the < sign.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#85323 - 2002-03-21 05:06 AM Re: MSI Automation via KIX 4.02
Shawn Administrator Offline
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 Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Yeah, go figure... I never bother with the trailing ;
Lets try it again here without html

<=

Can't figure this UBB board out... not very consistent. Some forums you can get away with it, others you can't.

Same thing for the copy/paste thingy... for a while after the upgrade, I could just block/copy/paste right into my trusty NotePad... now it doesn''t work again. Maybe it varies from forum to forum... [Confused] [Confused] [Confused]
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#85325 - 2002-03-21 05:21 AM Re: MSI Automation via KIX 4.02
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Yeah, I think its forum related. Plus, Im typing too slowly tonight - Alex - you asked about GetObject and CreateObject - see above.

-Shawn

Top
#85326 - 2002-03-21 09:20 AM Re: MSI Automation via KIX 4.02
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Shawn,

Don't you need to destroy the create once finished?

-Alex, I understand that, but where is the MAGIC DECODER RING On what all the GUID ID's are linked to. Is there a website that lists these GUIDs and their relationship? This code only returns numbers without even a note on what they link to.

How do YOU know what application they belong to?

[ 21 March 2002, 09:21: Message edited by: NTDOC ]

Top
#85327 - 2002-03-21 08:32 PM Re: MSI Automation via KIX 4.02
Alex Khassin Offline
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
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 382 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.07 seconds in which 0.025 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org