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。
答案 0 :(得分:2)
您收到此错误的原因是您在此处对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