【问题标题】:Batch windows xp timed prompt without choice.exe批处理windows xp定时提示无choice.exe
【发布时间】:2017-10-06 17:51:51
【问题描述】:

我是批处理脚本的新手。我想知道是否有一种方法可以在不使用choice.exe 的情况下编写定时提示,因为我使用的是windows xp。类似的东西:

@echo off
/set p answer=input y or n in 30 seconds
rem start timer
if answer==y(
  goto :action1
)
if answer==n(
  goto action2
)
rem if timer has expired without input go to :action1

:action 1
echo you have entered y
:action 2
echo you have entered n

感谢您的提示。

【问题讨论】:

    标签: windows batch-file prompt timed


    【解决方案1】:

    你可以试试这个:

    EditVar and Choose

    Choose 类似于 Microsoft Choice 工具,但它具有更多功能。以下是它可能优于 Choice 的一些原因:

    • 当用户做出无效选择时它不会发出哔哔声。

    • 它提供了“默认键”功能,允许用户按 Enter 键选择默认选项。

    • 它带有实模式 DOS 版本(对 MS-DOS 启动媒体有用)。 当您在单独的控制台窗口中运行多个实例时,Win32 版本的超时功能不会混淆(这是 Microsoft's Choice 工具的早期 Win32 控制台版本的问题)。

    • 提供 64 位版本。

    • 可以抑制用户选择的显示。

    • 它提供了一种“行输入”模式,用户必须在做出 > 选择后按 Enter 键。

    这是一个例子:

    CHOOOSE64.exe -c YNA -d A -n -p "Prompt" -t A,30
    rem           -Choices
    rem                  -Default
    rem                       -No default prompt
    rem                          -Prompt(custom)
    rem                                     -timeout defaultChoice, timeout in seconds
    
    if %errorlevel%==1 echo Y
    if %errorlevel%==2 echo N
    if %errorlevel%==3 echo A or timeout-ed
    

    【讨论】:

      【解决方案2】:

      这是一个想法。您可以使用Wscript.ShellPopup() 方法。它包括一个超时参数。是/否对话框将在是时返回 6,在否时​​返回 7,在超时时返回 -1。这很容易转换为布尔值,在是/超时时为 true,在否时为 false。使用 .bat 扩展名保存它,您将看到它是如何工作的。

      @if (@CodeSection == @Batch) @then
      @echo off & setlocal
      
      set delay=30
      set "msg=Do you wish to continue?"
      
      cscript /nologo /e:JScript "%~f0" "%msg%" %delay% && (
          goto yes
      ) || (
          goto no
      )
      
      :yes
      echo You chose yes.
      exit /b
      
      :no
      echo You chose no.
      exit /b
      
      @end // end Batch / begin JScript hybrid code
      
      var osh = WSH.CreateObject('WScript.Shell'),
          msg = WSH.Arguments(0),
          secs = WSH.Arguments(1);
      
      var response = osh.Popup(msg, secs, 'Waiting for response', 4 + 32);
      // yes or timeout returns true; no returns false
      WSH.Quit(!(response - 7));
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-12-02
        • 2013-12-18
        • 1970-01-01
        • 2010-10-08
        • 2010-12-14
        • 1970-01-01
        • 2010-10-24
        • 1970-01-01
        相关资源
        最近更新 更多