从控制台显示弹出窗口

时间:2015-04-10 23:33:26

标签: batch-file cmd dos

是否可以在批处理文件中显示弹出/警报?

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

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

2 个答案:

答案 0 :(得分:2)

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

这一行VBS脚本执行消息框

msgbox wscript.Arguments(0)

使用

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

<强>的InputBox

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

输入set f以查看结果

你需要把自己的路径放在

使用

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

如果您希望控件返回另一个批次

,请记住您必须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"

答案 1 :(得分:2)

您可以使用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的文件中并执行它。弹出窗口还可以包括选择按钮,结果可以从批处理代码中获得。例如:

@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