是否可以使用批处理脚本来要求用户(在CMD内)选择当前PC是主机还是客户端?用户使用向上或向下键盘箭头选择一个选项,然后按Enter确认。
Ive做了一些谷歌搜索,但我只能找到用于输入选择号码的代码。
没有第三方程序的帮助,批处理文件无法读取光标控制键。但是,您可以通过以下过程使用基于DOSKEY命令的有趣技巧:
尽管此方法需要JScript编程语言的帮助,但XP以后的所有Windows版本均包含此方法。将以下代码复制并粘贴为Batch .BAT文件:
@if (@CodeSection == @Batch) @then
@echo off
setlocal EnableDelayedExpansion
rem Multi-line menu with options selection via DOSKEY
rem Antonio Perez Ayala
rem Define the options
set numOpts=0
for %%a in (First Second Third Fourth Fifth) do (
set /A numOpts+=1
set "option[!numOpts!]=%%a Option"
)
set /A numOpts+=1
set "option[!numOpts!]=exit"
rem Clear previous doskey history
doskey /REINSTALL
rem Fill doskey history with menu options
cscript //nologo /E:JScript "%~F0" EnterOpts
for /L %%i in (1,1,%numOpts%) do set /P "var="
:nextOpt
cls
echo MULTI-LINE MENU WITH OPTIONS SELECTION
echo/
rem Send a F7 key to open the selection menu
cscript //nologo /E:JScript "%~F0"
set /P "var=Select the desired option: "
echo/
if "%var%" equ "exit" goto :EOF
echo Option selected: "%var%"
pause
goto nextOpt
@end
var wshShell = WScript.CreateObject("WScript.Shell"),
envVar = wshShell.Environment("Process"),
numOpts = parseInt(envVar("numOpts"));
if ( WScript.Arguments.Length ) {
// Enter menu options
for ( var i=1; i <= numOpts; i++ ) {
wshShell.SendKeys(envVar("option["+i+"]")+"{ENTER}");
}
} else {
// Enter a F7 to open the menu
wshShell.SendKeys("{F7}{HOME}");
}
上一个程序的输出示例:
在这个职位的进一步细节。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句