如何获取原始VBScript命令行参数? [英] How do I get raw VBScript command line arguments?

查看:62
本文介绍了如何获取原始VBScript命令行参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在.vbs文件中获取整个命令行?我希望自己处理它,同时保留所有特殊字符/引号。

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.

例如,命令:

cscript.exe example.vbs /month:April /price:500 "Joe Smith" is "our" guy 

我不感兴趣:

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:


/月:4月/ price:500 Joe Smith是我们的家伙

/month:April /price:500 "Joe Smith" is "our" guy


推荐答案

您可以使用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

输出:

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

这篇关于如何获取原始VBScript命令行参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆