【问题标题】:Can i pop a message when user clicks on close button in batch script?当用户单击批处理脚本中的关闭按钮时,我可以弹出一条消息吗?
【发布时间】:2019-11-07 07:55:00
【问题描述】:

我想知道当用户点击批处理文件中的关闭按钮时如何弹出消息

我正在寻找一种在用户批量单击关闭按钮时弹出消息框的方法。

就像当用户点击关闭按钮时,它会弹出一条消息说“你刚刚关闭”使用 VBScript 或任何其他......

【问题讨论】:

    标签: batch-file


    【解决方案1】:

    我发布这个只是因为你年轻并且愿意学习。

    当您关闭 cmd 窗口时,它会停止该命令内的所有执行,不会触发任何进一步的事件。因此,您需要使用另一个脚本监视该特定实例。例如,创建一个名为 mytest.cmd 的批处理文件并输入以下代码。

    @echo off
    title Monitor_This
    pause
    

    创建另一个批处理文件,我们将其命名为 monitoring.cmd 并输入以下批处理/vbscript 代码:

    <!-- :
    @echo off
    :start
    tasklist /FI "windowtitle eq Monitor_This" | findstr "cmd.exe">nul 2>&1
    if %errorlevel% equ 1 cscript //nologo "%~f0?.wsf" & exit /b
    timeout 1 >nul 2>&1
    goto :start
    exit /b
    -->
    
    <job><script language="VBScript">
    Set objShell = Wscript.CreateObject("Wscript.Shell")
    objShell.Popup "You closed The Window",, "My Popup"
    </script></job>
    

    现在运行这两个脚本。它们运行后,您可以关闭标题为关闭 Monitor_This 的窗口,如下图所示:

    关闭后将返回:

    【讨论】:

      【解决方案2】:

      这是一个仅命令行界面的方法:

      @echo off
      if "%~1"=="startchk" goto chk
      start "" cmd /c "%~f0 startchk"
      rem Rest of code here
      goto :eof
      :chk
      set count=0
      for /f "tokens=1 delims= " %%a in ('tasklist ^| findstr /r "[c][m][d][.][e][x][e]"') do set /a count += 1
      :chk2
      set new=0
      for /f "tokens=1 delims= " %%a in ('tasklist ^| findstr /r "[c][m][d][.][e][x][e]"') do set /a new += 1
      if %new% lss %count% goto over
      goto chk2
      :over
      msg * "You have closed cmd"
      Goto :eof
      

      【讨论】:

        猜你喜欢
        • 2012-08-11
        • 2014-12-02
        • 2012-09-12
        • 1970-01-01
        • 2016-11-15
        • 1970-01-01
        • 1970-01-01
        • 2015-07-20
        • 1970-01-01
        相关资源
        最近更新 更多