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

Possible to detect WSH mode or form of execution?

792 views
Skip to first unread message

seanst...@hotmail.com

unread,
Jun 12, 2006, 2:29:26 PM6/12/06
to
Hello -

I have a .vbs that our entire team uses and it's meant to be run in
cscript mode for WSH (no GUI handling for wscript). Thus, unless the
user has configured WSH to run in cscript mode by default, one must
execute the script like so: cscript <name of my script>.vbs

However, many of the users on my team, by default, usually see this
file and double-click it, which doesn't work out to well for them and
it's not meant to be run in the wscript GUI mode.

Question: is there a way I can catch this error, or detect how the user
executed the script (eg double click the file icon) and throw a single
error via a message box informing them of the
correct way to execute the script?

Thanks for any help,
Sean

ekkehard.horner

unread,
Jun 12, 2006, 3:14:52 PM6/12/06
to
use WScript.Fullname to determine the host - e.g.:

If "CSCRIPT.EXE" <> UCase( Right( WScript.Fullname, 11 ) ) Then
WScript.Echo "Das Programm ist fuer CSCRIPT bestimmt!"
WScript.Quit 1
End If

Todd Vargo

unread,
Jun 12, 2006, 6:10:18 PM6/12/06
to

"ekkehard.horner" <ekkehar...@arcor.de> wrote in message
news:448dbd2e$0$11068$9b4e...@newsread4.arcor-online.net...

One could even force the script to run in CSCRIPT.EXE

If "CSCRIPT.EXE" <> UCase(Right(WScript.Fullname, 11)) Then
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "CSCRIPT.EXE /nologo " & WScript.ScriptFullName
Wscript.Quit
End If

Wscript.Echo "Script is running in CSCRIPT.EXE now."
Wscript.Sleep 2000 'Pause for demo only.

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

seanst...@hotmail.com

unread,
Jun 14, 2006, 2:28:04 PM6/14/06
to
Thanks Todd. This worked real well. I just echo the correct usage now
and quit. I didn't know about the WScript.Fullname property. I'm glad
you told me.

Sean

Michael Harris (MVP)

unread,
Jun 14, 2006, 3:48:43 PM6/14/06
to
seanst...@hotmail.com wrote:
> Thanks Todd. This worked real well. I just echo the correct usage now
> and quit. I didn't know about the WScript.Fullname property. I'm glad
> you told me.
>

You'll know that and much more with...

Download details: Windows Script 5.6 Documentation
<http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en>

--
Michael Harris
Microsoft MVP Scripting


0 new messages