1
state = 1
While state = 1
    Set WshShell = WScript.CreateObject ("WScript.Shell")
    Set colProcessList = GetObject("Winmgmts:").ExecQuery ("Select * from Win32_Process")
    Set oShell = CreateObject ("Wscript.Shell")
    For Each objProcess in colProcessList
        if objProcess.Name = "server.exe" And objProcess.Name = "cmd.exe" then
            vFound = True
        End if
    Next
    If vFound = True then
        wscript.sleep 10000
    Else
        Dim strArg, strArgs
        strArg = "pskill /accepteula cmd.exe"
        strArgs = "%windir%\psexec /accepteula \\server test.exe"
        oShell.Run strArg & oShell.Run strArgs, 0, false
        wscript.sleep 10000
    End If
    vFound = False
Wend

请帮助我正确运行此脚本,我要做的是,如果在进程中找不到“server.exe”和“cmd.exe”,请运行 Dim strArg 和 strArgs。

4

1 回答 1

3

您收到此错误是您正在对Run此处的方法进行嵌套调用:

oShell.Run strArg & oShell.Run strArgs, 0, false

要完成这项工作,您必须将嵌套调用的参数列表放在括号中:

oShell.Run strArg & oShell.Run(strArgs, 0, false)

但是,我不太清楚您要在这里实现什么。为什么要将一个调用的返回值与另一个Run调用的命令字符串连接起来Run?您是否正在尝试并行运行这两个命令?如果是这样,你只需要这样做:

oShell.Run strArg, 0, False
oShell.Run strArgs, 0, False

要按顺序运行命令,请等待每个命令返回:

oShell.Run strArg, 0, True
oShell.Run strArgs, 0, True
于 2013-07-04T18:46:22.560 回答