更新时间:2022-05-16 03:36:17
wscript.echo 是正确的命令 - 但是要输出到控制台而不是对话,您需要使用 cscript 而不是 wscript 运行脚本.
wscript.echo is the correct command - but to output to console rather than dialogue you need to run the script with cscript instead of wscript.
您可以通过以下方式解决此问题
You can resolve this by
像这样从命令行运行脚本:
running your script from command line like so:
cscript myscript.vbs
更改默认文件关联(或为要使用 cscript 运行的脚本创建新的文件扩展名和关联).
changing the default file association (or creating a new file extension and association for those scripts you want to run with cscript).
通过脚本主机选项更改引擎(即根据 http://support.microsoft.com/kb/245254)
change the engine via the script host option (i.e. as per http://support.microsoft.com/kb/245254)
cscript //h:cscript //s
或者您可以在脚本的开头添加几行,以强制它将引擎"从 wscript 切换到 cscript - 请参阅 http://www.robvanderwoude.com/vbstech_engine_force.php(复制如下):
RunMeAsCScript
'do whatever you want; anything after the above line you can gaurentee you'll be in cscript
Sub RunMeAsCScript()
Dim strArgs, strCmd, strEngine, i, objDebug, wshShell
Set wshShell = CreateObject( "WScript.Shell" )
strEngine = UCase( Right( WScript.FullName, 12 ) )
If strEngine <> "\CSCRIPT.EXE" Then
' Recreate the list of command line arguments
strArgs = ""
If WScript.Arguments.Count > 0 Then
For i = 0 To WScript.Arguments.Count
strArgs = strArgs & " " & QuoteIt(WScript.Arguments(i))
Next
End If
' Create the complete command line to rerun this script in CSCRIPT
strCmd = "CSCRIPT.EXE //NoLogo """ & WScript.ScriptFullName & """" & strArgs
' Rerun the script in CSCRIPT
Set objDebug = wshShell.Exec( strCmd )
' Wait until the script exits
Do While objDebug.Status = 0
WScript.Sleep 100
Loop
' Exit with CSCRIPT's return code
WScript.Quit objDebug.ExitCode
End If
End Sub
'per Tomasz Gandor's comment, this will ensure parameters in quotes are covered:
function QuoteIt(strTemp)
if instr(strTemp," ") then
strTemp = """" & replace(strTemp,"""","""""") & """"
end if
QuoteIt = strTemp
end function