Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Show entire command line, or the name of the executing vbscript 1

Status
Not open for further replies.

ESquared

Programmer
Dec 23, 2003
6,129
US
I know how in vbscript to access the command-line parameters. But can I get the name of the running script, similar to the %0 parameter in a batch file?

Consider the following:

Code:
SomeExeWritingToStandardOut.exe | cscript.exe //Nologo myvbscript.vbs param1 param2 param3
param1 - 3 are easy. But can I get "myvbscript.vbs" inside of that script?

Even better, can I get access to the initiating command line in its entirety, so I can see cscript.exe and/or SomeExeWritingToStandardOut.Exe?

I thought perhaps there was an environment variable which listed the last executed command in that command window's context and there does not appear to be such a thing.

I read the titles of all the FAQs in this forum. I searched the internet and found a bazillion references to "parameters" but haven't figured out how to restrict my results to show me what I'm looking for.

[COLOR=#aa88aa black]Cum catapultae proscriptae erunt tum soli proscript catapultas habebunt.[/color]
 
To see the script name of the script running or it's path you can try something as simple as this.

Code:
WScript.Echo WScript.ScriptName
WScript.Echo WScript.ScriptFullName

To get the command line that executed you will need to query WMI using Win32_Process class (WinXP or greater only)

Code:
Option Explicit

Dim strComputer : strComputer = "."
Dim objWMIService : Set objWMIService = GetObject("winmgmts:\\" & _
						strComputer & "\root\cimv2")
Dim colProcesses : Set colProcesses = objWMIService.ExecQuery("Select * From Win32_Process Where Name='cscript.exe'")
Dim objProcess
For Each objProcess In colProcesses
	WScript.Echo objProcess.CommandLine
Next

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Great information, thank you.

I was just coming back to post that I had found "WScript.ScriptFullName" so no one had to answer that part but you obviously are too good and too fast for me!



[COLOR=#aa88aa black]Cum catapultae proscriptae erunt tum soli proscript catapultas habebunt.[/color]
 
For anyone who similarly had problems finding info about scripting, here's a link to MSDN's Scripting Reference.

[COLOR=#aa88aa black]Cum catapultae proscriptae erunt tum soli proscript catapultas habebunt.[/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top