如何从VB.Net启动vbs脚本并将参数传递给启动的vb脚本

时间:2016-05-19 20:09:33

标签: vb.net string process arguments wsh

我需要执行像" cscript OSPP.vbs / dstatus"这样的命令。从视觉基础应用程序。我正在使用波纹管代码,但我无法转移参数" dstatus"到OSPP.vbs。我怎么能这样做?任何帮助

    Dim start As New ProcessStartInfo
    Dim task As New Process
    Dim so As IO.StreamReader

    start.FileName = "C:\WINDOWS\system32\cscript.exe"
    start.Arguments = """C:\Program Files (x86)\Microsoft Office\Office15\OSPP.vbs /dstatus"""

    start.UseShellExecute = False
    start.RedirectStandardOutput = True
    start.RedirectStandardError = False        

    task.StartInfo = start
    task.Start()
    so = task.StandardOutput
    task.WaitForExit()
    MsgBox(so.ReadToEnd)

1 个答案:

答案 0 :(得分:0)

您的参数格式不正确,因为路径有空格,您需要将它括在双引号之间。

试试这个:

Dim args as string =
     String.Format("""{0}"" ""{1}""", 
                   "C:\Program Files (x86)\Microsoft Office\Office15\OSPP.vbs", 
                   "/dstatus") 

start.FileName = "C:\WINDOWS\system32\cscript.exe"
start.Arguments = args