|
|
| |
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 |
| |
 |
|
Top |
|
|
|
|
|
|
|
|
|
|
|
|
| |
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 |
| |
 |
|
Top |
|
|
|
|
|
|
|
|
|
| |
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 |
| |
 |
|
Top |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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 |
| |
 |
|
Top |
|
|
|
|
|
|
|
|