问题
How do I get the entire command line in a .vbs file? I'm looking to process it myself, with all special characters/quotes still intact.
For example, the command:
cscript.exe example.vbs /month:April /price:500 "Joe Smith" is "our" guy
I am NOT interested in:
WScript.Arguments.Named.Item("month")
= April
WScript.Arguments.Item(2)
= Joe Smith
Dim StrArgs
For Each arg In WScript.Arguments
StrArgs = StrArgs & " " & arg
Next
= /month:April /price:500 Joe Smith is our guy
These methods mangle and strip all quotes.
I want to get the raw arguments, unprocessed in any way:
/month:April /price:500 "Joe Smith" is "our" guy
回答1:
You can use WMI:
Option Explicit
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Dim oWMI : Set oWMI = GetObject("winmgmts:\\.\root\CIMV2")
Dim oCol : Set oCol = oWMI.ExecQuery( _
"SELECT Commandline FROM Win32_Process", _
"WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
Dim oElm
For Each oElm In oCol
If Instr(oElm.CommandLine, "40056204.vbs") Then
WScript.Echo "CommandLine: " & oElm.CommandLine
End If
Next
output:
cscript 40056204.vbs /month:April /price:500 "Joe Smith" is "our" guy
CommandLine: cscript 40056204.vbs /month:April /price:500 "Joe Smith" is "our" guy
来源:https://stackoverflow.com/questions/40056204/how-do-i-get-raw-vbscript-command-line-arguments