AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题 / 1594715
Accepted
batchcoding____s
batchcoding____s
Asked: 2020-10-16 19:29:58 +0800 CST2020-10-16 19:29:58 +0800 CST 2020-10-16 19:29:58 +0800 CST

关闭批处理文件时如何显示警告消息?

  • 772

我有一个批处理文件。打开它后,我想通过带有自定义消息的警告对话框警告用户关闭它。或者,如果上述情况不可行,则批处理文件中至少有一些消息。

有什么办法吗?

batch-file batch
  • 2 2 个回答
  • 1110 Views

2 个回答

  • Voted
  1. Best Answer
    spikey_richie
    2020-10-16T23:05:18+08:002020-10-16T23:05:18+08:00

    或者,如果上述情况不可行,则批处理文件中至少有一些消息。

    一种方法是添加一堆REM行并包含echo on. 然后,您可以像这样放置横幅消息:

    REM ************************
    REM DO NOT CLOSE THIS WINDOW
    REM *************************
    

    有关更多信息,请参阅此处REM

    如果这不能如您所愿,请查看https://ss64.com/nt/rem.html上的示例

    多行注释 添加大型多行注释测试块的一种方法是使用纯文本和 goto 命令跳过注释执行:

    @Echo OFF Goto :START Description can go here which can even include - | > characters

    :START

    上述技术不适用于括号表达式(例如FOR... DO(...)循环)的中间。这是因为 Goto 命令不能在括号内使用 - 它会破坏它们的上下文。

    这种情况也可以通过将注释文本放在括号中来处理,如下所示:

    ( 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. ) )

    • 2
  2. Io-oI
    2020-10-17T13:49:15+08:002020-10-17T13:49:15+08:00

    在此处输入图像描述


    @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
    

    您可以在您的 bat 文件中使用 VBS 并要求您的用户关闭或不...

    :: 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 

    • 让用户点击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

    在此处输入图像描述

    • 2

相关问题

  • Windows 批处理更改所有 IIS 应用程序池超时

  • 命令行:文件重命名的通用命令

  • Windows 2016 不会运行 .bat 文件

  • 如何制作批处理脚本来备份具有唯一目标文件夹的特定文件(Windows)[关闭]

  • Python 的“pass”参数的批处理等价物是什么?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    v15 为什么通过电缆(同轴电缆)的千兆位/秒 Internet 连接不能像光纤一样提供对称速度? 2020-01-25 08:53:31 +0800 CST
  • Martin Hope
    fixer1234 “HTTPS Everywhere”仍然相关吗? 2019-10-27 18:06:25 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve