vbscript.runshow输出

vbscript.runshow输出,vbscript,wsh,remote-process,Vbscript,Wsh,Remote Process,我可以使用以下语法成功运行test.vbs: Dim WshShell Set WshShell = CreateObject("WScript.Shell") sEXE = """\\uncpath\file.exe""" with CreateObject("WScript.Shell") .Run sEXE & " ", 1, true ' Wait for finish or False to not wait end with 但是,我想将输出存储到\\\uncpath

我可以使用以下语法成功运行test.vbs:

Dim WshShell
Set WshShell = CreateObject("WScript.Shell")

sEXE = """\\uncpath\file.exe"""
with CreateObject("WScript.Shell")
  .Run sEXE & " ", 1, true ' Wait for finish or False to not wait
end with
但是,我想将输出存储到
\\\uncpath\%computername%.txt

这不起作用:

sEXE = """\\uncpath\file.exe>>\\uncpath\%computername%.txt"""
with CreateObject("WScript.Shell")
  .Run sEXE & " ", 1, true ' Wait for finish or False to not wait
end with
行出错:带有CreateObject(“WScript.Shell”)

这也不行

sEXE = """\\uncpath\file.exe"""
with CreateObject("WScript.Shell")
  .Run sEXE & " >>\\uncpath\%computername%.txt", 1, true ' Wait for finish or False to not wait
end with
有什么帮助吗?

方法
.Run()
无法从您使用的任务
.Exec()
中读取标准输出,但是您需要一些更改来模拟
.Run()
自动为您执行的阻塞

Dim WshShell, sEXE, cmd, result
Set WshShell = CreateObject("WScript.Shell")

sEXE = """\\uncpath\file.exe"""
With CreateObject("WScript.Shell")
  Set cmd = .Exec(sEXE)
  'Block until complete.
  Do While cmd.Status <> 1
     WScript.Sleep 100
  Loop
  'Get output
  result = cmd.StdOut.Readall()
  'Check the output
  WScript.Echo result
  Set cmd = Nothing
End With

有用的链接
  • (由
    .Exec()
    返回)
  • (由
    .StdIn
    StdOut
    StdErr
    返回)
sEXE = "cmd /c ""\\uncpath\file.exe >> \\uncpath\%computername%.txt"""
With CreateObject("WScript.Shell")
  .Run sEXE & " ", 1, true ' Wait for finish or False to not wait
End With