Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

run EXE from a VBS custom action

1,384 views
Skip to first unread message

Jens Lenge

unread,
Jan 20, 2004, 10:52:59 PM1/20/04
to
I need to run an exe file from my VBScript.
Should be simple, I know, but the script is run as a custom action from an
MSI installer, so there is no WSH and no WScript object.

How can I run an exe from my script?
Is there a way to make my script wait until the exe finishes (even if it is
a GUI exe)?

Jens

Torgeir Bakken (MVP)

unread,
Jan 20, 2004, 11:08:12 PM1/20/04
to
Jens Lenge wrote:

Hi

You can use the Run method in a CA VBScript:

Set oShell = CreateObject("WScript.Shell")

' if it is a console program, and you want To
' hide the console, use 0 instead of 1
oShell.Run "notepad", 1, True


If you might have spaces in the path to the exe:

Set oShell = CreateObject("WScript.Shell")
sProgram = "c:\some path\some file.exe"
oShell.Run """" & sProgram & """" , 0, True


If the program also needs command line switches:

Set oShell = CreateObject("WScript.Shell")
sProgram = "c:\some path\some file.exe"
sParams = "/s /n"
oShell.Run """" & sProgram & """ " & sParams, 0, True


--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter


Jens Lenge

unread,
Jan 22, 2004, 11:29:10 AM1/22/04
to
Thanks for the hint, I will try that as soon as possible.

BTW, just for understanding:
Why may I create a shell object via CreateObject("WScript.Shell") even in
environments where the WScript object itself is not accessible?
Maybe I am caught in the C++ way of thinking, but I cannot see why it is
possible to access a specific class member when the corresponding class
itself is not present.

Guess I didn't truly understand the VBScript object model?

Jens

Joe Earnest

unread,
Jan 22, 2004, 12:33:50 PM1/22/04
to
Hi,

"Jens Lenge" <Spa...@gmx.net> wrote in message
news:buotoj$15v$03$1...@news.t-online.com...

Don't feel alone. This one confuses many people and threw me for a long
time. WScript.Shell is only syntactically a subobject of WScript.
Physically, its in a separate file. For an overview:

The immediate WScript object methods and properties are designed to work
only where WSH is the host. WSH is the host only where WSCRIPT.EXE and
CSCRIPT.EXE are run directly.

WSH comes with numerous DLL/OCX files, in addition to the EXE files. Each
scripting host that allows VBS/JS, accessess the various WSH DLL/OCX files,
as that host permits.

MS placed the only "immediate" WScript methods and properties (i.e., not
WScript.Shell) in the WSH EXE files, themselves, so they are not accessible
from other scripting hosts. (Credit Tom Lavedas for a post with this info.)
By comparison, the fundamental WScript.Shell object and the Err object are
exposed through other DLL/OCX files, and are available in other hosts, when
not suppressed for security reasons. MS apparently believes that the
immediate WScript methods and properties present a basic conflict or
security hazard with other hosts.

The WScript object can be passed into a WSC file through a defined property,
but I have not been successful in trying to pass it into any other hosts.

Joe Earnest

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.564 / Virus Database: 356 - Release Date: 01-19-04


Torgeir Bakken (MVP)

unread,
Jan 22, 2004, 12:48:47 PM1/22/04
to
Jens Lenge wrote:

Hi

As Joe wrote, it is an unfortunate name confusion, and to exemplify a bit:

The WScript in
CreateObject("WScript.Shell")

is not the same as WScript in e.g.
WScript.Echo


E.g. this will not work:


Set oShell = CreateObject("WScript.Shell")

oShell.Echo

Error: object doesn't support this property or method: 'oShell.Echo'


So, to conclude, in a Custom Action you can use CreateObject("WScript.Shell")
and all it's available methods and properties.

0 new messages