Pop up Message in batch cmd

不羁岁月 提交于 2019-12-22 19:41:08

问题


echo msgbox "Hey! Here is a message!" > %tmp%\tmp.vbs
cscript /nologo %tmp%\tmp.vbs
del %tmp%\tmp.vbs

or

echo msgbox "Hey! Here is a message!" > %tmp%\tmp.vbs
wscript %tmp%\tmp.vbs
del %tmp%\tmp.vbs

I found these in other thread, however how to I make it multiple lines on the text?


回答1:


Like this:

echo msgbox Replace("Hey!\nHere is a message!", "\n", vbLf) > %tmp%\tmp.vbs
cscript /nologo %tmp%\tmp.vbs
del %tmp%\tmp.vbs



回答2:


Not as short as Ekkehard's but in a single hybrid file.
The normal return code of msgbox is decreased by one to have zero - hitting abort will return one and so abort the call.

<!-- : Begin batch script
@echo off&SETLOCAL EnableDelayedExpansion
echo.
echo Step1: Closing Explorer . . .
echo.
Call :MsgBox "Do you really want to restart the explorer?" "Title" ||(Goto :Abort)
TASKKILL /F /IM explorer.exe 
echo.
echo.
echo Step2: Launching Explorer . . .
start explorer.exe
echo.
echo Success: Explorer started.
echo.
echo.
Goto :Eof

:Abort
Echo Aborted with errorlevel !Errorlevel!
Exit /B !Errorlevel!
:MsgBox
for /f "Delims=" %%i in (
  'cscript.exe //Nologo "%~f0?.wsf" "%~1" "%~2"'
) do set "Ret=%%i"
Exit /B %Ret%
Goto :Eof
----- Begin wsf script --->
<job><script language="VBScript">
Set oArgs = WScript.Arguments
If oArgs.Count = 2 Then
    Ret = MsgBox(oArgs.Item(0),1,oArgs.Item(1))
    Wscript.Echo Ret-1
    Wscript.Quit (Ret -1)
End if 
</script></job>

Don't change the first line and after ---- Begin wsf script --->



来源:https://stackoverflow.com/questions/21272110/pop-up-message-in-batch-cmd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!