Wie wird eine Warnmeldung angezeigt, während eine Batchdatei geschlossen wird?
Ich habe eine Batch-Datei. Nach dem Öffnen möchte ich den Benutzer durch ein Warndialogfeld mit einer benutzerdefinierten Nachricht zum Schließen warnen. Oder wenn das oben genannte nicht möglich ist, mindestens eine Nachricht in der Batch-Datei.
Gibt es eine Möglichkeit dazu?
Antworten
Oder wenn das oben genannte nicht möglich ist, mindestens eine Nachricht in der Batch-Datei.
Eine Möglichkeit, dies zu tun, besteht darin, eine Reihe von REMZeilen hinzuzufügen und einzuschließen echo on. Sie können dann eine Bannernachricht wie folgt einfügen:
REM ************************
REM DO NOT CLOSE THIS WINDOW
REM *************************
Weitere Informationen finden Sie hierREM
Wenn das nicht wie erwartet funktioniert, schauen Sie sich das Beispiel an https://ss64.com/nt/rem.html
Mehrzeilige Kommentare Ein Ansatz zum Hinzufügen eines großen mehrzeiligen Blocks von Kommentartests besteht darin, einfachen Text und einen goto-Befehl zu verwenden, um die Ausführung an den Kommentaren vorbei zu springen:
@Echo OFF Goto :START Description can go here which can even include - | > characters
:START
Die obige Technik funktioniert nicht in der Mitte eines Ausdrucks in Klammern, z. B. einer
FOR... DO(...)Schleife. Dies liegt daran, dass ein Befehl "Springen" nicht in Klammern verwendet werden kann - dies würde den Kontext beschädigen.Solche Fälle können behandelt werden, indem der Kommentartext wie folgt in Klammern gesetzt wird:
( Echo the lines below are commented Rem/||( some comment text that will work within brackets. The REM command always evaluates to TRUE so these lines will never be executed. ) )
@Goto %:^)
*** This text is your message to editor in your code ***
%:^)
@echo off && mode 50,4 && title <nul && set "_yn=" <nul
setlocal & color 0A & title .\%~nx0 & >"%temp%\_vbs.vbs" ^
set /p "'=yn=msgbox("Hey!, Close %~nx0 Now!",4,"Warnning!!."):wsh.echo yn" <nul
%__AppDir__%cscript.exe "%temp%\_vbs.vbs" //nologo | find "6" >nul && set "_yn=y"
if "%_yn%"=="y" (endlocal && echo\Thank you, %~nx0 stopped by user!.. && goto :EOF)
set "_yn=" & rem :: if user answer is "No" do more below here ::
for %%i in ( "OK button only. 0.Simple Ok",
"OK and Cancel buttons. 1.Simple OK or Cancel",
"Abort Retry Ignore buttons. 2.Simple Abort Retry or Ignore",
"Yes No and Cancel buttons. 3.Yes No Cancel",
"Yes No buttons. 4.Yes or No",
"Retry Cancel buttons. 5.Retry Cancel",
"Critical Message icon. 16.Critical Error Retry Cancel",
"Warning Query icon. 32.Warnning and Simple Ok",
"Warning Message icon. 48.Warnning ans Simple Ok",
"Information Message icon. 64.Warnning and Simple Ok",
)do call %:^] "%%~i"
%:^]
if "%~1" == "" %__AppDir__%timeout.exe -1 | <nul ^
echo\Press any key any time... & endlocal & goto :EOF
for /f tokens^=1-3delims^=. %%i in ('echo\%~1
')do echo\msgbox"%%~i",%%~j,"%%~k" >"%temp%\_vbs.vbs"
%__AppDir__%wscript.exe "%temp%\_vbs.vbs" //nologo & exit /b
Sie können VBS in Ihrer Bat-Datei verwenden und Ihren Benutzer bitten, zu schließen oder nicht ...
:: Create you VBS dialog box file:
echo\Msgbox"You text msg", int_id,"Window Title" >"%temp%\_vbs.vbs"
run your VBS file:
%__AppDir__%cscript.exe "%temp%\_vbs.vbs" //nologo
- Holen Sie sich den Klick des Benutzers auf die Variable in cmd:
:: set user answer click ::
=yn=msgbox("Hey!, Close %~nx0 Now!",4,"Warnning!!."):wsh.echo yn"
:: set user answer click value/id Yes and No ::
Yes == 6
No == 7
:: Command line run VBS |redirect output | find "answer_Number" ::
%__AppDir__%cscript.exe "%temp%\_vbs.vbs" //nologo |find "6"
:: With operator && and set if find "6" ::
%__AppDir__%cscript.exe "%temp%\_vbs.vbs" //nologo |find "6" >nul && set "_yn=y"
:: VBS ID click returns:
Ok = 1
Cancel = 2
Abort = 3
Retry = 4
Ignore = 5
Yes = 6
No = 7