Click Here to Install Silverlight*
United StatesChange|All Microsoft Sites|Sign in
Microsoft
|Communities Home|Communities Worldwide
  VBscript samples and documentation for MSI in MSI  
 |  Edit my Profile  |  Help
 
     
  
 
 
 
Lee 8/24/2005 7:58 PM PST
  Question
  I'm working on a Basic MSI project in InstallShield 10.5, and I wrote my own
function in WI DLL as a Custom Action, which takes only one parameter
MSIHANDLE, and it works fine.

For some reason, I want to use VBScript instead, because all I want to
retrive is so called, SOURCEDIR.
That case,I want to know if I can pass this handle to VBScript (it seems I
can't). If so, how? If not, to me an alternative is to pass the fullpath of
the MSI package name to VBScript so that I can call OpenDatabase(
fullpath_msi, ...), but I don't know how to pass the fullpath to VBscript.
Besides, I wonder if this is the only way to optain SOURCEDIR in VBscript.

Unfortunately I can't find any useful sample or documentation about this. I
don't even know what Objects, their methods / properties are due to lack of
this information.
I tried hard to find this info, but no avail. I am so frustrated, and kind
of upset: why this little simple stuff can be achieved so difficult, and
began to hate Microsoft, especially MSI. *SIGH*
 
  Was this post helpful to you?  
 
 
  Reply | Print post   TopTop  
 
 
 
 
Bugbear.1973 8/25/2005 12:48 AM PST
   
  I assume you've tried using:

MsgBox Session.Property( "SOURCEDIR" )

Or perhaps I'm missing what you are trying to do?

 
  Was this post helpful to you?  
 
 
  Reply | Print post   TopTop  
 
 
 
 
Lee 8/25/2005 6:20 AM PST
   
  Sort of.

It took a couple of days to get some reusable codes from quite a few
different websites, and I eventually managed to write a following VBScript:
---- Code Starts -----------
Option Explicit

Const msiOpenDatabaseModeReadOnly = 0

' Connect to Windows Installer object
On Error Resume Next
Dim installer : Set installer =
Wscript.CreateObject("WindowsInstaller.Installer") : CheckError
Dim WshShell : Set WshShell = Wscript.CreateObject("Wscript.Shell") :
CheckError
' Open database
Dim databasePath : Set databasePath = Wscript.Arguments(0)
Dim database : Set database = installer.OpenDatabase(databasePath,
msiOpenDatabaseModeReadOnly) : If Err <> 0 Then MsgBox "databasePath" &
databasePath
Dim session : Set session = installer.OpenPackage(database) : If Err <> 0
Then MsgBox "database" & database
Dim SourceDir : Set SourceDir = session.Property("SOURCEDIR") : If Err <> 0
Then MsgBox "SOURCEDIR" & SourceDir
WshShell.Run SourceDir & "\" & "myBatch.bat"
Wscript.Quit 0
---- Code Ends -----------

Now to use "Session" object, I need "database" object, which I can obtain
from "databasePath". Unfortunately, this "databasePath" must be passed in
from somewhere. Obviously this script must be running from the commandline,
not within the MSI package.

In InstallScript, I could do the samething in the following short function:
function RunCustomBat( hMSI )
STRING szSrcDir;
NUMBER nSize, nRet;
begin
nSize = 256;
nRet = MsiGetProperty( hMSI, "SOURCEDIR", szSrcDir, nSize );
LaunchAppAndWait( szSrcDir ^ "myBatch.bat", "", NOWAIT );
end;

So I REALLLY want to find out how I can do the same in VBScript.
When I surfed the several websites, a few people wanted to find what I want,
but I couldn't find any useful information.
 
  Was this post helpful to you?  
 
 
  Reply | Print post   TopTop  
 
 
 
 
Phil Wilson 8/26/2005 8:38 AM PST
   
  If you just want to get the SOURCEDIR property during a custom action, the
previous poster was absolutely right. The session object is provided for
free during a VBScript custom action. Session.Property("SOURCEDIR") is just
a wrapper around MsiGetProperty. If Session.Property("SOURCEDIR") doesn't
work, you've got some other problem going on.
--
Phil Wilson
[Microsoft MVP-Windows Installer]
Definitive Guide to Windows Installer
http://apress.com/book/bookDisplay.html?bID=280

<Lee> wrote in message
news:341EEAA6-6F3D-4016-A7E9-EBB19DB55D2B@microsoft.com...
> Sort of.
>
> It took a couple of days to get some reusable codes from quite a few
> different websites, and I eventually managed to write a following
> VBScript:
> ---- Code Starts -----------
> Option Explicit
>
> Const msiOpenDatabaseModeReadOnly = 0
>
> ' Connect to Windows Installer object
> On Error Resume Next
> Dim installer : Set installer =
> Wscript.CreateObject("WindowsInstaller.Installer") : CheckError
> Dim WshShell : Set WshShell = Wscript.CreateObject("Wscript.Shell") :
> CheckError
> ' Open database
> Dim databasePath : Set databasePath = Wscript.Arguments(0)
> Dim database : Set database = installer.OpenDatabase(databasePath,
> msiOpenDatabaseModeReadOnly) : If Err <> 0 Then MsgBox "databasePath" &
> databasePath
> Dim session : Set session = installer.OpenPackage(database) : If Err <> 0
> Then MsgBox "database" & database
> Dim SourceDir : Set SourceDir = session.Property("SOURCEDIR") : If Err <>
> 0
> Then MsgBox "SOURCEDIR" & SourceDir
> WshShell.Run SourceDir & "\" & "myBatch.bat"
> Wscript.Quit 0
> ---- Code Ends -----------
>
> Now to use "Session" object, I need "database" object, which I can obtain
> from "databasePath". Unfortunately, this "databasePath" must be passed in
> from somewhere. Obviously this script must be running from the
> commandline,
> not within the MSI package.
>
> In InstallScript, I could do the samething in the following short
> function:
> function RunCustomBat( hMSI )
> STRING szSrcDir;
> NUMBER nSize, nRet;
> begin
> nSize = 256;
> nRet = MsiGetProperty( hMSI, "SOURCEDIR", szSrcDir, nSize );
> LaunchAppAndWait( szSrcDir ^ "myBatch.bat", "", NOWAIT );
> end;
>
> So I REALLLY want to find out how I can do the same in VBScript.
> When I surfed the several websites, a few people wanted to find what I
> want,
> but I couldn't find any useful information.


 
  Was this post helpful to you?  
 
 
  Reply | Print post   TopTop  
 
 
 
 
Lee 8/26/2005 1:27 PM PST
   
  I see.
Is there any way to find if VBScript is running OK?
I just tested it with a single line of code:
MsgBox Session.Property("SOURCEDIR")

But I didn't see the message box. So I changed it to:
MsgBox "Hello"

and I still don't see it.

Thanks.

"Phil Wilson" wrote:

> If you just want to get the SOURCEDIR property during a custom action, the
> previous poster was absolutely right. The session object is provided for
> free during a VBScript custom action. Session.Property("SOURCEDIR") is just
> a wrapper around MsiGetProperty. If Session.Property("SOURCEDIR") doesn't
> work, you've got some other problem going on.
> --
> Phil Wilson
> [Microsoft MVP-Windows Installer]
> Definitive Guide to Windows Installer
> http://apress.com/book/bookDisplay.html?bID=280
 
  Was this post helpful to you?  
 
 
  Reply | Print post   TopTop  
 
 
 
 
Phil Wilson 8/26/2005 2:03 PM PST
   
  If you don't see a message box at all, there could be something wrong with
the condition on the custom action that causes it to be skipped. If this is
an install, doing it with a log will show something about whether it's being
skipped.

msiexec /i <path to msi> /l*v somelogfile.log.

There are other situations in which it won't be called. If you've already
installed the product and you're doing it again and going into repair mode,
it's the already installed MSI that runs, not your new one, so your new
custom action in the new MSI won't be called.
--
Phil Wilson [MVP Windows Installer]
----
<Lee> wrote in message
news:1171F095-9BB2-4A73-B478-272A072C6590@microsoft.com...
>I see.
> Is there any way to find if VBScript is running OK?
> I just tested it with a single line of code:
> MsgBox Session.Property("SOURCEDIR")
>
> But I didn't see the message box. So I changed it to:
> MsgBox "Hello"
>
> and I still don't see it.
>
> Thanks.
>
> "Phil Wilson" wrote:
>
>> If you just want to get the SOURCEDIR property during a custom action,
>> the
>> previous poster was absolutely right. The session object is provided for
>> free during a VBScript custom action. Session.Property("SOURCEDIR") is
>> just
>> a wrapper around MsiGetProperty. If Session.Property("SOURCEDIR") doesn't
>> work, you've got some other problem going on.
>> --
>> Phil Wilson
>> [Microsoft MVP-Windows Installer]
>> Definitive Guide to Windows Installer
>> http://apress.com/book/bookDisplay.html?bID=280
>


 
  Was this post helpful to you?  
 
 
  Reply | Print post   TopTop  
 
 
 
 
Lee 8/30/2005 8:55 AM PST
   
  Hi Phil, Thank you for helping me this: the log indicated that the custom
action was skipped, and I found why, and now a very simple MsgBox is
displayed.

Here is something I'd like to share with the beginngers like me.
When I added the following lines that I excerp from Platform SDK, I got
errors:
1 Dim WshShell : Set WshShell = Wscript.CreateObject("Wscript.Shell")
2 Dim SourceDir : Set SourceDir = Session.Property("SOURCEDIR")
3 WshShell.Run SourceDir & "\" & "my.bat"
4 Wscript.Quit 0

And the final working script is:
1 Set WshShell = CreateObject("WScript.Shell")
2 SourceDir = Session.Property("SOURCEDIR")
3 WshShell.Run Chr(34) & SourceDir & "my.bat" & Chr(34), 0, True

However, I just copied and pasted, so I don't even know what the last two
parameters (0, True)in the line #3 are for.

So here are a couple of questions to the experts like you:
1. Is "Session" object the only free that I can use in VBScript?
2. How can I find the methods available for "Session" object and others like
the last 2 partameters in question?

Thanks again!!!
 
  Was this post helpful to you?  
 
 
  Reply | Print post   TopTop  
 
 
 
 
Phil Wilson 8/30/2005 1:28 PM PST
  Answer
  You'll get errors with this:
Dim WshShell : Set WshShell = Wscript.CreateObject("Wscript.Shell")
because you're not running a WSH VBScript, you're running an MSI VBScript.
IE, WSH, MSI are all hosts for VBScripts with their own object model, and
you get Wscript only with WSH.

IIRC correctly Session is the root object in an MSI VBScript and it gets you
to various methods as well as an Installer object, Session.Installer, the
current Installer object, Database for the running MSI file, as well as
Property() to get/set property values.

WSHShell is Windows Script Host, not MSI stuff:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/wsobjwshshell.asp

--
Phil Wilson [MVP Windows Installer]
----
<Lee> wrote in message
news:15EEA754-F016-48D7-9B9D-024683B72898@microsoft.com...
> Hi Phil, Thank you for helping me this: the log indicated that the custom
> action was skipped, and I found why, and now a very simple MsgBox is
> displayed.
>
> Here is something I'd like to share with the beginngers like me.
> When I added the following lines that I excerp from Platform SDK, I got
> errors:
> 1 Dim WshShell : Set WshShell = Wscript.CreateObject("Wscript.Shell")
> 2 Dim SourceDir : Set SourceDir = Session.Property("SOURCEDIR")
> 3 WshShell.Run SourceDir & "\" & "my.bat"
> 4 Wscript.Quit 0
>
> And the final working script is:
> 1 Set WshShell = CreateObject("WScript.Shell")
> 2 SourceDir = Session.Property("SOURCEDIR")
> 3 WshShell.Run Chr(34) & SourceDir & "my.bat" & Chr(34), 0, True
>
> However, I just copied and pasted, so I don't even know what the last two
> parameters (0, True)in the line #3 are for.
>
> So here are a couple of questions to the experts like you:
> 1. Is "Session" object the only free that I can use in VBScript?
> 2. How can I find the methods available for "Session" object and others
> like
> the last 2 partameters in question?
>
> Thanks again!!!


 
  Was this post helpful to you?  
 
 
  Reply | Print post   TopTop  
 
 
 
 
Lee 8/30/2005 2:07 PM PST
   
  Thank you Phil.
You are TRULY MVP!!!!!!!
 
  Was this post helpful to you?  
 
 
  Reply | Print post   TopTop  
 
 
  Return to Microsoft Communities  Notify me of replies  
 
Windows Live ID

© 2009 Microsoft Corporation. All rights reserved. Contact Us |Terms of Use |Trademarks |Privacy Statement