【问题标题】:Powershell write to vbscript console(cscript.exe)Powershell 写入 vbscript 控制台(cscript.exe)
【发布时间】:2016-02-17 23:58:03
【问题描述】:

我需要通过 vbscript(cscript.exe) 在静默模式下运行 powershell 脚本。

脚本的基本步骤如下。

vbscript

WScript.StdOut.WriteLine "Welcome..."
WScript.StdOut.WriteLine "First Step..."
WScript.Sleep Int(2000)
Set objShell = CreateObject("Wscript.Shell"): objShell.Run "powershell -nologo -file D:\basic\child.ps1" ,0,true
WScript.StdOut.WriteLine "Script Completed."
WScript.Sleep Int(5000)

powershell 脚本

Write-Host "Some Text Printed"
Start-Sleep -s 2

此时,我喜欢将 powershell 脚本写入 vbscript(cscript.exe) 控制台。

我正在运行如下的 vb 脚本。

cscript d:\basic\script.vbs

是否有解决此要求的方法。

【问题讨论】:

标签: powershell vbscript powershell-2.0 windows-scripting


【解决方案1】:

正如我作为可能重复链接的问题的答案中所述,您可以执行以下操作:

WScript.StdOut.WriteLine "Welcome..."
WScript.StdOut.WriteLine "First Step..."
WScript.Sleep Int(2000)
res = getCommandOutput("powershell -nologo -file D:\basic\child.ps1")
WScript.StdOut.Write res
WScript.StdOut.WriteLine "Script Completed."
WScript.Sleep Int(5000)

Function getCommandOutput(theCommand)

    Dim objShell, objCmdExec
    Set objShell = CreateObject("WScript.Shell")
    Set objCmdExec = objshell.exec(thecommand)
    getCommandOutput = objCmdExec.StdOut.ReadAll

end Function

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多