dos下使用set命令来实现choice的功能
dos6.0下能实现的choice选项,但是因为choice是外部命令,在xp中没有所以不能实现选择菜单。
解决办法:用SET命令代替
解决办法:用SET命令代替
现在下面举几个例子:
@echo off
choice /c 12c
if %errorlevel%==1 echo 你选择了1
if %errorlevel%==2 echo 你选择了2
if %errorlevel%==3 echo 你选择了c
pause>nul
使用set来实现choicewa字符串是什么选择
@echo off
set /p a= 请输入选择[1, 2, c]:
if %a%==1 echo 你选择了1
if %a%==2 echo 你选择了2
if %a%==c echo 你选择了c
pause>nul
上面是set和choice的一点小差别,choice%errorlevel%是从1开始排列的,和选择是一一对应的.而set有更大的自由度.
set 命令详解
显示、设置或删除 环境变量。
SET [variable=[string]]
variable 指定环境变量名。
string 指定要指派给变量的一系列字符串。
variable 指定环境变量名。
string 指定要指派给变量的一系列字符串。
要显示当前环境变量,键入不带参数的 SET。
如果命令扩展被启用,SET 会如下改变:
可仅用一个变量激活 SET 命令,等号或值不显示所有前缀匹配SET 命令已使用的名称的所有变量的值。
例: SET P
会显示所有以字母 P 打头的变量
可仅用一个变量激活 SET 命令,等号或值不显示所有前缀匹配SET 命令已使用的名称的所有变量的值。
例: SET P
会显示所有以字母 P 打头的变量
如果在当前环境中不到该变量名称,SET 命令将把 ERRORLEVEL设置成 1。
SET 命令不允许变量名含有等号。
在 SET 命令中添加了两个新命令行开关:
SET /A expression
SET /P variable=[promptString]
SET /A expression
SET /P variable=[promptString]
/A 命令行开关指定等号右边的字符串为被评估的数字表达式。
除十六进制有 0x 前缀,八进制有 0 前缀的,数字值为十进位数字。因此,0x12 与 18 和 022 相同。请注意八进制公式可能很容易搞混: 08 和 09 是无效的数字,因为 8 和 9 不是有效的八进制位数。
除十六进制有 0x 前缀,八进制有 0 前缀的,数字值为十进位数字。因此,0x12 与 18 和 022 相同。请注意八进制公式可能很容易搞混: 08 和 09 是无效的数字,因为 8 和 9 不是有效的八进制位数。
/P 命令行开关允许将变量数值设成用户输入的一行输入。读取输入行之前,显示指定的 promptString。promptString 可以是空的。
%PATH:~10,5%
会扩展 PATH 环境变量,然后只使用在扩展结果中从第 11 个(偏移量 10)字符开始的五个字符。如果没有指定长度,则采用默认值,即变量数值的余数。如果两个数字(偏移量和长度)都是负数,使用的数字则是环境变量数值长度加上指定的偏移量或长度。
会扩展 PATH 环境变量,然后只使用在扩展结果中从第 11 个(偏移量 10)字符开始的五个字符。如果没有指定长度,则采用默认值,即变量数值的余数。如果两个数字(偏移量和长度)都是负数,使用的数字则是环境变量数值长度加上指定的偏移量或长度。
%PATH:~-10%
会提取 PATH 变量的最后十个字符。
会提取 PATH 变量的最后十个字符。
%PATH:~0,-2%
会提取 PATH 变量的所有字符,除了最后两个。
会提取 PATH 变量的所有字符,除了最后两个。
如果命令扩展被启用,有几个动态环境变量可以被扩展,但不会出现在 SET 显示的变量列表中。每次变量数值被扩展时,这些变量数值都会被动态计算。如果用户用这些名称中任何一个定义变量,那个定义会替代下面描述的动态定义:
%CD% - 扩展到当前目录字符串。
%DATE% - 用跟 DATE 命令同样的格式扩展到当前日期。
%TIME% - 用跟 TIME 命令同样的格式扩展到当前时间。
%RANDOM% - 扩展到 0 和 32767 之间的任意十进制数字。
%ERRORLEVEL% - 扩展到当前 ERRORLEVEL 数值。
%CMDEXTVERSION% - 扩展到当前命令处理器扩展版本号。
%CMDCMDLINE% - 扩展到调用命令处理器的原始命令行。
应用例子:
@echo off
@echo off
title window优化文件
:start
cls
cls
color 0c
MODE con: COLS=50 LINES=27
echo Windows Xp 优化文件!
echo Powered By ThunderRay!
echo.
echo ==============================
echo 请选择要进行的操作,然后按回车
echo ==============================
echo.
echo 1.优化系统服务
echo.
echo 2.进行端口操作
echo.
echo 3.设置IP为192.168.1.2
echo.
MODE con: COLS=50 LINES=27
echo Windows Xp 优化文件!
echo Powered By ThunderRay!
echo.
echo ==============================
echo 请选择要进行的操作,然后按回车
echo ==============================
echo.
echo 1.优化系统服务
echo.
echo 2.进行端口操作
echo.
echo 3.设置IP为192.168.1.2
echo.
echo (局域网上网者慎用此功能)
echo.
echo 4.其它优化
echo.
echo 5.设置OEM信息
echo.
echo 6.清除根目录下的SXS病毒
echo.
echo 7.清理系统垃圾
echo.
echo 8.退出
echo.
echo.
echo 4.其它优化
echo.
echo 5.设置OEM信息
echo.
echo 6.清除根目录下的SXS病毒
echo.
echo 7.清理系统垃圾
echo.
echo 8.退出
echo.
:cho
set choice=
set /p choice= 请选择:
set choice=
set /p choice= 请选择:
IF NOT "%Choice%"=="" SET Choice=%Choice:~0,1%
if /i "%choice%"=="1" goto start2
if /i "%choice%"=="2" goto start3
if /i "%choice%"=="3" goto ip
if /i "%choice%"=="4" goto other
if /i "%choice%"=="5" goto oem
if /i "%choice%"=="6" goto virus
if /i "%choice%"=="7" goto del
if /i "%choice%"=="8" goto end
echo 选择无效,请重新输入
echo.
goto cho
if /i "%choice%"=="1" goto start2
if /i "%choice%"=="2" goto start3
if /i "%choice%"=="3" goto ip
if /i "%choice%"=="4" goto other
if /i "%choice%"=="5" goto oem
if /i "%choice%"=="6" goto virus
if /i "%choice%"=="7" goto del
if /i "%choice%"=="8" goto end
echo 选择无效,请重新输入
echo.
goto cho
:start2
cls
echo Windows Xp 优化文件!
cls
echo Windows Xp 优化文件!
echo Powered By ThunderRay!
echo.
echo ==============================
echo 请选择要进行的操作,然后按回车
echo ==============================
echo.
echo 1.优化XP系统服务
echo.
echo 2.恢复XP原系统服务
echo.
echo 3.返回主菜单
echo.
echo 4.退出
echo.
echo.
echo ==============================
echo 请选择要进行的操作,然后按回车
echo ==============================
echo.
echo 1.优化XP系统服务
echo.
echo 2.恢复XP原系统服务
echo.
echo 3.返回主菜单
echo.
echo 4.退出
echo.
:Choice2
set choice2=
set /p choice2= 请选择:
IF NOT "%Choice2%"=="" SET Choice2=%Choice2:~0,1%
if /i "%choice2%"=="1" goto optimize
if /i "%choice2%"=="2" goto Restore
if /i "%choice2%"=="3" goto start
if /i "%choice2%"=="4" goto end
echo 选择无效,请重新输入
echo.
goto Choice2
set /p choice2= 请选择:
IF NOT "%Choice2%"=="" SET Choice2=%Choice2:~0,1%
if /i "%choice2%"=="1" goto optimize
if /i "%choice2%"=="2" goto Restore
if /i "%choice2%"=="3" goto start
if /i "%choice2%"=="4" goto end
echo 选择无效,请重新输入
echo.
goto Choice2
:optimize
cls
echo 开始进行优化系统服务...
sc config Alerter start= DISABLED
sc config ALG start= DISABLED
cls
echo 开始进行优化系统服务...
sc config Alerter start= DISABLED
sc config ALG start= DISABLED
sc config AppMgmt start= DEMAND
sc config AudioSrv start= AUTO
sc config BITS start= DEMAND
sc config Browser start= DISABLED
sc config CiSvc start= DISABLED
sc config ClipSrv start= DISABLED
sc config COMSysApp start= DEMAND
sc config CryptSvc start= DEMAND
sc config DcomLaunch start= AUTO
sc config Dhcp start= DISABLED
sc config dmadmin start= DEMAND
sc config dmserver start= DISABLED
sc config Dnscache start= DISABLED
sc config ERSvc start= DISABLED
sc config Eventlog start= AUTO
sc config AudioSrv start= AUTO
sc config BITS start= DEMAND
sc config Browser start= DISABLED
sc config CiSvc start= DISABLED
sc config ClipSrv start= DISABLED
sc config COMSysApp start= DEMAND
sc config CryptSvc start= DEMAND
sc config DcomLaunch start= AUTO
sc config Dhcp start= DISABLED
sc config dmadmin start= DEMAND
sc config dmserver start= DISABLED
sc config Dnscache start= DISABLED
sc config ERSvc start= DISABLED
sc config Eventlog start= AUTO
sc config EventSystem start= DISABLED
sc config FastUserSwitchingCompatibility start= DISABLED
sc config helpsvc start= DISABLED
sc config HidServ start= DISABLED
sc config HTTPFilter start= DEMAND
sc config ImapiService start= DISABLED
sc config lanmanserver start= DISABLED
sc config lanmanworkstation start= AUTO
sc config LmHosts start= DISABLED
sc config Messenger start= DISABLED
sc config mnmsrvc start= DISABLED
sc config MSDTC start= DISABLED
sc config MSIServer start= DEMAND
sc config NetDDE start= DISABLED
sc config NetDDEdsdm start= DISABLED
sc config FastUserSwitchingCompatibility start= DISABLED
sc config helpsvc start= DISABLED
sc config HidServ start= DISABLED
sc config HTTPFilter start= DEMAND
sc config ImapiService start= DISABLED
sc config lanmanserver start= DISABLED
sc config lanmanworkstation start= AUTO
sc config LmHosts start= DISABLED
sc config Messenger start= DISABLED
sc config mnmsrvc start= DISABLED
sc config MSDTC start= DISABLED
sc config MSIServer start= DEMAND
sc config NetDDE start= DISABLED
sc config NetDDEdsdm start= DISABLED
sc config Netlogon start= DISABLED
sc config Netman start= DEMAND
sc config Nla start= DISABLED
sc config NtLmSsp start= DISABLED
sc config NtmsSvc start= DEMAND
sc config Nvsvc start= DISABLED
sc config Ose start= DEMAND
sc config PlugPlay start= AUTO
sc config PolicyAgent start= DISABLED
sc config ProtectedStorage start= DISABLED
sc config RasAuto start= DEMAND
sc config RasMan start= DEMAND
sc config RDSessMgr start= DISABLED
sc config RemoteAccess start= DISABLED
sc config RemoteRegistry start= DISABLED
sc config Netman start= DEMAND
sc config Nla start= DISABLED
sc config NtLmSsp start= DISABLED
sc config NtmsSvc start= DEMAND
sc config Nvsvc start= DISABLED
sc config Ose start= DEMAND
sc config PlugPlay start= AUTO
sc config PolicyAgent start= DISABLED
sc config ProtectedStorage start= DISABLED
sc config RasAuto start= DEMAND
sc config RasMan start= DEMAND
sc config RDSessMgr start= DISABLED
sc config RemoteAccess start= DISABLED
sc config RemoteRegistry start= DISABLED
sc config RpcLocator start= DEMAND
sc config RpcSs start= AUTO
sc config SamSs start= DISABLED
sc config SCardSvr start= DISABLED
sc config Schedule start= DISABLED
sc config seclogon start= DISABLED
sc config SENS start= DISABLED
sc config SharedAccess start= DISABLED
sc config ShellHWDetection start= DISABLED
sc config Spooler start= DEMAND
sc config srservice start= DISABLED
sc config SSDPSRV start= DISABLED
sc config Stisvc start= DISABLED
sc config Swprv start= DISABLED
sc config SysmonLog start= DISABLED
sc config RpcSs start= AUTO
sc config SamSs start= DISABLED
sc config SCardSvr start= DISABLED
sc config Schedule start= DISABLED
sc config seclogon start= DISABLED
sc config SENS start= DISABLED
sc config SharedAccess start= DISABLED
sc config ShellHWDetection start= DISABLED
sc config Spooler start= DEMAND
sc config srservice start= DISABLED
sc config SSDPSRV start= DISABLED
sc config Stisvc start= DISABLED
sc config Swprv start= DISABLED
sc config SysmonLog start= DISABLED
sc config TapiSrv start= DEMAND
sc config TermService start= DISABLED
sc config Themes start= AUTO
sc config TlntSvr start= DISABLED
sc config TrkWks start= DISABLED
sc config UMWdf start= DISABLED
sc config upnphost start= DEMAND
sc config UPS start= DISABLED
sc config VSS start= DISABLED
sc config W32Time start= DISABLED
sc config WebClient start= DISABLED
sc config winmgmt start= AUTO
sc config WmdmPmSN start= DISABLED
sc config Wmi start= DEMAND
sc config WmiApSrv start= DISABLED
sc config TermService start= DISABLED
sc config Themes start= AUTO
sc config TlntSvr start= DISABLED
sc config TrkWks start= DISABLED
sc config UMWdf start= DISABLED
sc config upnphost start= DEMAND
sc config UPS start= DISABLED
sc config VSS start= DISABLED
sc config W32Time start= DISABLED
sc config WebClient start= DISABLED
sc config winmgmt start= AUTO
sc config WmdmPmSN start= DISABLED
sc config Wmi start= DEMAND
sc config WmiApSrv start= DISABLED
sc config wuauserv start= DISABLED
sc config WZCSVC start= DISABLED
sc config wscsvc start= DISABLED
sc config xmlprov start= DEMAND
echo 优化XP系统服务结束,按任意键返回!
pause >nul
goto start2
sc config WZCSVC start= DISABLED
sc config wscsvc start= DISABLED
sc config xmlprov start= DEMAND
echo 优化XP系统服务结束,按任意键返回!
pause >nul
goto start2
:Restore
cls
echo 开始恢复XP原系统服务...
sc config Alerter start= DISABLED
sc config ALG start= DEMAND
sc config AppMgmt start= DEMAND
sc config AudioSrv start= AUTO
sc config BITS start= DEMAND
cls
echo 开始恢复XP原系统服务...
sc config Alerter start= DISABLED
sc config ALG start= DEMAND
sc config AppMgmt start= DEMAND
sc config AudioSrv start= AUTO
sc config BITS start= DEMAND
sc config Browser start= AUTO
sc config CiSvc start= DEMAND
sc config ClipSrv start= DISABLED
sc config COMSysApp start= DEMAND
sc config CryptSvc start= AUTO
sc config DcomLaunch start= AUTO
sc config Dhcp start= AUTO
sc config dmadmin start= DEMAND
sc config dmserver start= AUTO
sc config Dnscache start= AUTO
sc config ERSvc start= AUTO
sc config Eventlog start= AUTO
sc config EventSystem start= DEMAND
sc config FastUserSwitchingCompatibility start= DEMAND
sc config helpsvc start= AUTO
sc config CiSvc start= DEMAND
sc config ClipSrv start= DISABLED
sc config COMSysApp start= DEMAND
sc config CryptSvc start= AUTO
sc config DcomLaunch start= AUTO
sc config Dhcp start= AUTO
sc config dmadmin start= DEMAND
sc config dmserver start= AUTO
sc config Dnscache start= AUTO
sc config ERSvc start= AUTO
sc config Eventlog start= AUTO
sc config EventSystem start= DEMAND
sc config FastUserSwitchingCompatibility start= DEMAND
sc config helpsvc start= AUTO
sc config HidServ start= DISABLED
sc config HTTPFilter start= DEMAND
sc config ImapiService start= DEMAND
sc config lanmanserver start= AUTO
sc config lanmanworkstation start= AUTO
sc config LmHosts start= AUTO
sc config Messenger start= DISABLED
sc config mnmsrvc start= DEMAND
sc config MSDTC start= DEMAND
sc config MSIServer start= DEMAND
sc config NetDDE start= DISABLED
sc config NetDDEdsdm start= DISABLED
sc config Netlogon start= DEMAND
sc config Netman start= DEMAND
sc config Nla start= DEMAND
sc config HTTPFilter start= DEMAND
sc config ImapiService start= DEMAND
sc config lanmanserver start= AUTO
sc config lanmanworkstation start= AUTO
sc config LmHosts start= AUTO
sc config Messenger start= DISABLED
sc config mnmsrvc start= DEMAND
sc config MSDTC start= DEMAND
sc config MSIServer start= DEMAND
sc config NetDDE start= DISABLED
sc config NetDDEdsdm start= DISABLED
sc config Netlogon start= DEMAND
sc config Netman start= DEMAND
sc config Nla start= DEMAND
sc config NtLmSsp start= DEMAND
sc config NtmsSvc start= DEMAND
sc config PlugPlay start= AUTO
sc config PolicyAgent start= AUTO
sc config ProtectedStorage start= AUTO
sc config RasAuto start= DEMAND
sc config RasMan start= DEMAND
sc config RDSessMgr start= DEMAND
sc config RemoteAccess start= DISABLED
sc config RemoteRegistry start= AUTO
sc config RpcLocator start= DEMAND
sc config RpcSs start= AUTO
sc config RSVP start= DEMAND
sc config SamSs start= AUTO
sc config SCardSvr start= DEMAND
sc config NtmsSvc start= DEMAND
sc config PlugPlay start= AUTO
sc config PolicyAgent start= AUTO
sc config ProtectedStorage start= AUTO
sc config RasAuto start= DEMAND
sc config RasMan start= DEMAND
sc config RDSessMgr start= DEMAND
sc config RemoteAccess start= DISABLED
sc config RemoteRegistry start= AUTO
sc config RpcLocator start= DEMAND
sc config RpcSs start= AUTO
sc config RSVP start= DEMAND
sc config SamSs start= AUTO
sc config SCardSvr start= DEMAND
sc config Schedule start= AUTO
sc config seclogon start= AUTO
sc config SENS start= AUTO
sc config SharedAccess start= AUTO
sc config ShellHWDetection start= AUTO
sc config Spooler start= AUTO
sc config srservice start= DISABLED
sc config SSDPSRV start= DEMAND
sc config stisvc start= DEMAND
sc config SwPrv start= DEMAND
sc config SysmonLog start= DEMAND
sc config TapiSrv start= DEMAND
sc config TermService start= DEMAND
sc config Themes start= AUTO
sc config TlntSvr start= DISABLED
sc config seclogon start= AUTO
sc config SENS start= AUTO
sc config SharedAccess start= AUTO
sc config ShellHWDetection start= AUTO
sc config Spooler start= AUTO
sc config srservice start= DISABLED
sc config SSDPSRV start= DEMAND
sc config stisvc start= DEMAND
sc config SwPrv start= DEMAND
sc config SysmonLog start= DEMAND
sc config TapiSrv start= DEMAND
sc config TermService start= DEMAND
sc config Themes start= AUTO
sc config TlntSvr start= DISABLED
sc config TrkWks start= AUTO
sc config UMWdf start= DEMAND
sc config upnphost start= DEMAND
sc config UPS start= DEMAND
sc config VSS start= DEMAND
sc config W32Time start= AUTO
sc config WebClient start= AUTO
sc config winmgmt start= AUTO
sc config WmdmPmSN start= DEMAND
sc config Wmi start= DEMAND
sc config WmiApSrv start= DEMAND
sc config wscsvc start= AUTO
sc config wuauserv start= AUTO
sc config WZCSVC start= AUTO
sc config xmlprov start= DEMAND
sc config UMWdf start= DEMAND
sc config upnphost start= DEMAND
sc config UPS start= DEMAND
sc config VSS start= DEMAND
sc config W32Time start= AUTO
sc config WebClient start= AUTO
sc config winmgmt start= AUTO
sc config WmdmPmSN start= DEMAND
sc config Wmi start= DEMAND
sc config WmiApSrv start= DEMAND
sc config wscsvc start= AUTO
sc config wuauserv start= AUTO
sc config WZCSVC start= AUTO
sc config xmlprov start= DEMAND
echo 恢复XP原系统服务结束,按任意键返回!
pause >nul
goto start2
pause >nul
goto start2
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论