1

这是我的 VBS 代码

Set wshshell = wscript.CreateObject("WScript.Shell")
Wshshell.run "C:\Temp\Executable.exe -c -dir C:\Productdir"
'Wait till "This will install the product on your computer. Press OK, Cancel" appears
WScript.Sleep 10000
WshShell.SendKeys "~"   
  1. 是否有可能“而不是硬编码的 10 秒睡眠”添加这样的东西,例如if consolemessage="This will install the product on your computer. Press OK, Cancel" then WshShell.SendKeys "~"
  2. 在上述情况下可以WScript.StdOut用来捕获控制台消息吗?我没能做到。
4

1 回答 1

1

当您使用该方法StdOut执行程序时,您可以读取一个进程。Exec

Set wshshell = wscript.CreateObject("WScript.Shell")
Set p = Wshshell.Exec("C:\Temp\Executable.exe -c -dir C:\Productdir")

Do While p.Status = 0
  output = ""
  Do Until p.StdOut.AtEndOfStream
    c = p.StdOut.Read(1)
    WScript.StdOut.Write c  'write read characters to the command prompt
    output = output & c
    If InStr(output, "This will install the product") > 0 Then
      'do stuff
      Exit Do
    End If
  Loop
  WScript.Sleep 100
Loop
于 2013-08-02T11:45:28.307 回答