从控制台显示弹出 window

Show popup window from console

是否可以在批处理文件中显示 popup/alert?

我一直在阅读有关 vb 脚本用法的信息,但这是完全必要的吗?

http://ss64.com/vb/popup.html or http://ss64.com/vb/msgbox.html

VBScript 不是必需的。您可以使用除批处理之外的任何编程语言(Powershell/Jscript/Any .NET 语言)。

一行VBS脚本做一个消息框

msgbox wscript.Arguments(0)

使用

"C:\Users\User\Desktop\MsgBox.vbs" "Hi there"

输入框

将用户输入的内容放入变量 %Filter_InputBox%

键入 set f 以查看结果

您需要将自己的路径放入

使用

batchfile.bat "Text", "Window Title" "Default text"

记住,如果你想控制 return 到另一个批次

,你必须 call 一个批处理文件
call batchfile.bat "Text", "Window Title" "Default text"

VBS 文件

'Create a batchfile that filter.bat will run as last step to set the environmental variable %Filter_InputBox%.
Text=InputBox(Wscript.Arguments(0), Wscript.Arguments(1),Wscript.Arguments(2))

Set Fso = CreateObject("Scripting.FileSystemObject")
Set File = Fso.CreateTextFile("FilterExit.bat", True)
If err.number <> 0 then
    Wscript.echo "Error: " & err.number & " " & err.description & " from " & err.source
    err.clear
    wscript.exit
End If
File.WriteLine "set Filter_InputBox=" & Text
File.close

批处理文件

InputBox.vbs %*
If exist "FilterExit.bat" call "FilterExit.bat"
If exist "FilterExit.bat" del "FilterExit.bat"

您可以使用 Batch-JScript 混合脚本,最终它是一个 .BATch 文件;例如:

@if (@CodeSection == @Batch) @then

@echo off

CScript //nologo //E:JScript "%~F0" "Hi, there..." 
goto :EOF

@end

WScript.CreateObject("WScript.Shell").Popup(WScript.Arguments(0));

将之前的代码复制到扩展名为.bat的文件中并执行。 Popup 也可能包含选择按钮,结果可能从 Batch code 中获取。例如:

@if (@CodeSection == @Batch) @then

@echo off

rem Define values for Popup buttons
set /A YesNoAndCancel=3, QuestionMark=32
set /A YesButton=6, NoButton=7, TimedOut=-1

rem Call Popup JScript method with a 7 second timeout.
set /A buttons=YesNoandCancel + QuestionMark
CScript //nologo //E:JScript "%~F0" "Do you feel alright?" "Answer please:" %buttons% 7
set btn=%errorlevel%
if %btn% equ %YesButton% (
   echo Glad to hear you feel alright.
) else if %btn% equ %NoButton% (
   echo Hope you're feeling better soon.
) else if %btn% equ %TimedOut% (
   echo Is there anybody out there?
)
goto :EOF

@end

var arg = WScript.Arguments;
WScript.Quit(WScript.CreateObject("WScript.Shell").Popup(arg(1),arg(3),arg(0),arg(2)));

有关 JScript Popup 方法的更多详细信息,请参阅 here