批处理窗口 xp 定时提示没有选择.exe



im 批处理脚本的新手。我想知道是否有办法在不使用选择的情况下编写定时提示.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

谢谢你的提示。

这里有

一个想法。 你可以使用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));

你可以试试这个:

编辑变量并选择

选择类似于Microsoft选择工具,但它具有更多功能。以下是它比选择更可取的一些原因:

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

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

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

  • 提供 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

相关内容

最新更新