dos下使用set命令来实现choice的功能.docx
- 文档编号:30744168
- 上传时间:2023-08-20
- 格式:DOCX
- 页数:15
- 大小:25.17KB
dos下使用set命令来实现choice的功能.docx
《dos下使用set命令来实现choice的功能.docx》由会员分享,可在线阅读,更多相关《dos下使用set命令来实现choice的功能.docx(15页珍藏版)》请在冰豆网上搜索。
dos下使用set命令来实现choice的功能
dos下使用set命令来实现choice的功能
dos6.0下能实现的choice选项,但是因为choice是外部命令,在xp中没有choice.exe所以不能实现选择菜单。
解决办法:
用SET命令代替
现在下面举几个例子:
@echooff
choice/c12c
if%errorlevel%==1echo你选择了1
if%errorlevel%==2echo你选择了2
if%errorlevel%==3echo你选择了c
pause>nul
使用set来实现choice选择
@echooff
set/pa=请输入选择[1,2,c]:
if%a%==1echo你选择了1
if%a%==2echo你选择了2
if%a%==cecho你选择了c
pause>nul
上面是set和choice的一点小差别,choice%errorlevel%是从1开始排列的,和选择是一一对应的.而set有更大的自由度.
set命令详解
显示、设置或删除cmd.exe环境变量。
SET[variable=[string]]
variable指定环境变量名。
string指定要指派给变量的一系列字符串。
要显示当前环境变量,键入不带参数的SET。
如果命令扩展被启用,SET会如下改变:
可仅用一个变量激活SET命令,等号或值不显示所有前缀匹配SET命令已使用的名称的所有变量的值。
例:
SETP
会显示所有以字母P打头的变量
如果在当前环境中找不到该变量名称,SET命令将把ERRORLEVEL设置成1。
SET命令不允许变量名含有等号。
在SET命令中添加了两个新命令行开关:
SET/Aexpression
SET/Pvariable=[promptString]
/A命令行开关指定等号右边的字符串为被评估的数字表达式。
除十六进制有0x前缀,八进制有0前缀的,数字值为十进位数字。
因此,0x12与18和022相同。
请注意八进制公式可能很容易搞混:
08和09是无效的数字,因为8和9不是有效的八进制位数。
/P命令行开关允许将变量数值设成用户输入的一行输入。
读取输入行之前,显示指定的promptString。
promptString可以是空的。
%PATH:
~10,5%
会扩展PATH环境变量,然后只使用在扩展结果中从第11个(偏移量10)字符开始的五个字符。
如果没有指定长度,则采用默认值,即变量数值的余数。
如果两个数字(偏移量和长度)都是负数,使用的数字则是环境变量数值长度加上指定的偏移量或长度。
%PATH:
~-10%
会提取PATH变量的最后十个字符。
%PATH:
~0,-2%
会提取PATH变量的所有字符,除了最后两个。
如果命令扩展被启用,有几个动态环境变量可以被扩展,但不会出现在SET显示的变量列表中。
每次变量数值被扩展时,这些变量数值都会被动态计算。
如果用户用这些名称中任何一个定义变量,那个定义会替代下面描述的动态定义:
%CD%-扩展到当前目录字符串。
%DATE%-用跟DATE命令同样的格式扩展到当前日期。
%TIME%-用跟TIME命令同样的格式扩展到当前时间。
%RANDOM%-扩展到0和32767之间的任意十进制数字。
%ERRORLEVEL%-扩展到当前ERRORLEVEL数值。
%CMDEXTVERSION%-扩展到当前命令处理器扩展版本号。
%CMDCMDLINE%-扩展到调用命令处理器的原始命令行。
应用例子:
@echooff
titlewindow优化文件
:
start
cls
color0c
MODEcon:
COLS=50LINES=27
echoWindowsXp优化文件!
echoPoweredByThunderRay!
echo.
echo==============================
echo请选择要进行的操作,然后按回车
echo==============================
echo.
echo1.优化系统服务
echo.
echo2.进行端口操作
echo.
echo3.设置IP为192.168.1.2
echo.
echo(局域网上网者慎用此功能)
echo.
echo4.其它优化
echo.
echo5.设置OEM信息
echo.
echo6.清除根目录下的SXS病毒
echo.
echo7.清理系统垃圾
echo.
echo8.退出
echo.
:
cho
setchoice=
set/pchoice=请选择:
IFNOT"%Choice%"==""SETChoice=%Choice:
~0,1%
if/i"%choice%"=="1"gotostart2
if/i"%choice%"=="2"gotostart3
if/i"%choice%"=="3"gotoip
if/i"%choice%"=="4"gotoother
if/i"%choice%"=="5"gotooem
if/i"%choice%"=="6"gotovirus
if/i"%choice%"=="7"gotodel
if/i"%choice%"=="8"gotoend
echo选择无效,请重新输入
echo.
gotocho
:
start2
cls
echoWindowsXp优化文件!
echoPoweredByThunderRay!
echo.
echo==============================
echo请选择要进行的操作,然后按回车
echo==============================
echo.
echo1.优化XP系统服务
echo.
echo2.恢复XP原系统服务
echo.
echo3.返回主菜单
echo.
echo4.退出
echo.
:
Choice2
setchoice2=
set/pchoice2=请选择:
IFNOT"%Choice2%"==""SETChoice2=%Choice2:
~0,1%
if/i"%choice2%"=="1"gotooptimize
if/i"%choice2%"=="2"gotoRestore
if/i"%choice2%"=="3"gotostart
if/i"%choice2%"=="4"gotoend
echo选择无效,请重新输入
echo.
gotoChoice2
:
optimize
cls
echo开始进行优化系统服务...
scconfigAlerterstart=DISABLED
scconfigALGstart=DISABLED
scconfigAppMgmtstart=DEMAND
scconfigAudioSrvstart=AUTO
scconfigBITSstart=DEMAND
scconfigBrowserstart=DISABLED
scconfigCiSvcstart=DISABLED
scconfigClipSrvstart=DISABLED
scconfigCOMSysAppstart=DEMAND
scconfigCryptSvcstart=DEMAND
scconfigDcomLaunchstart=AUTO
scconfigDhcpstart=DISABLED
scconfigdmadminstart=DEMAND
scconfigdmserverstart=DISABLED
scconfigDnscachestart=DISABLED
scconfigERSvcstart=DISABLED
scconfigEventlogstart=AUTO
scconfigEventSystemstart=DISABLED
scconfigFastUserSwitchingCompatibilitystart=DISABLED
scconfighelpsvcstart=DISABLED
scconfigHidServstart=DISABLED
scconfigHTTPFilterstart=DEMAND
scconfigImapiServicestart=DISABLED
scconfiglanmanserverstart=DISABLED
scconfiglanmanworkstationstart=AUTO
scconfigLmHostsstart=DISABLED
scconfigMessengerstart=DISABLED
scconfigmnmsrvcstart=DISABLED
scconfigMSDTCstart=DISABLED
scconfigMSIServerstart=DEMAND
scconfigNetDDEstart=DISABLED
scconfigNetDDEdsdmstart=DISABLED
scconfigNetlogonstart=DISABLED
scconfigNetmanstart=DEMAND
scconfigNlastart=DISABLED
scconfigNtLmSspstart=DISABLED
scconfigNtmsSvcstart=DEMAND
scconfigNvsvcstart=DISABLED
scconfigOsestart=DEMAND
scconfigPlugPlaystart=AUTO
scconfigPolicyAgentstart=DISABLED
scconfigProtectedStoragestart=DISABLED
scconfigRasAutostart=DEMAND
scconfigRasManstart=DEMAND
scconfigRDSessMgrstart=DISABLED
scconfigRemoteAccessstart=DISABLED
scconfigRemoteRegistrystart=DISABLED
scconfigRpcLocatorstart=DEMAND
scconfigRpcSsstart=AUTO
scconfigSamSsstart=DISABLED
scconfigSCardSvrstart=DISABLED
scconfigSchedulestart=DISABLED
scconfigseclogonstart=DISABLED
scconfigSENSstart=DISABLED
scconfigSharedAccessstart=DISABLED
scconfigShellHWDetectionstart=DISABLED
scconfigSpoolerstart=DEMAND
scconfigsrservicestart=DISABLED
scconfigSSDPSRVstart=DISABLED
scconfigStisvcstart=DISABLED
scconfigSwprvstart=DISABLED
scconfigSysmonLogstart=DISABLED
scconfigTapiSrvstart=DEMAND
scconfigTermServicestart=DISABLED
scconfigThemesstart=AUTO
scconfigTlntSvrstart=DISABLED
scconfigTrkWksstart=DISABLED
scconfigUMWdfstart=DISABLED
scconfigupnphoststart=DEMAND
scconfigUPSstart=DISABLED
scconfigVSSstart=DISABLED
scconfigW32Timestart=DISABLED
scconfigWebClientstart=DISABLED
scconfigwinmgmtstart=AUTO
scconfigWmdmPmSNstart=DISABLED
scconfigWmistart=DEMAND
scconfigWmiApSrvstart=DISABLED
scconfigwuauservstart=DISABLED
scconfigWZCSVCstart=DISABLED
scconfigwscsvcstart=DISABLED
scconfigxmlprovstart=DEMAND
echo优化XP系统服务结束,按任意键返回!
pause>nul
gotostart2
:
Restore
cls
echo开始恢复XP原系统服务...
scconfigAlerterstart=DISABLED
scconfigALGstart=DEMAND
scconfigAppMgmtstart=DEMAND
scconfigAudioSrvstart=AUTO
scconfigBITSstart=DEMAND
scconfigBrowserstart=AUTO
scconfigCiSvcstart=DEMAND
scconfigClipSrvstart=DISABLED
scconfigCOMSysAppstart=DEMAND
scconfigCryptSvcstart=AUTO
scconfigDcomLaunchstart=AUTO
scconfigDhcpstart=AUTO
scconfigdmadminstart=DEMAND
scconfigdmserverstart=AUTO
scconfigDnscachestart=AUTO
scconfigERSvcstart=AUTO
scconfigEventlogstart=AUTO
scconfigEventSystemstart=DEMAND
scconfigFastUserSwitchingCompatibilitystart=DEMAND
scconfighelpsvcstart=AUTO
scconfigHidServstart=DISABLED
scconfigHTTPFilterstart=DEMAND
scconfigImapiServicestart=DEMAND
scconfiglanmanserverstart=AUTO
scconfiglanmanworkstationstart=AUTO
scconfigLmHostsstart=AUTO
scconfigMessengerstart=DISABLED
scconfigmnmsrvcstart=DEMAND
scconfigMSDTCstart=DEMAND
scconfigMSIServerstart=DEMAND
scconfigNetDDEstart=DISABLED
scconfigNetDDEdsdmstart=DISABLED
scconfigNetlogonstart=DEMAND
scconfigNetmanstart=DEMAND
scconfigNlastart=DEMAND
scconfigNtLmSspstart=DEMAND
scconfigNtmsSvcstart=DEMAND
scconfigPlugPlaystart=AUTO
scconfigPolicyAgentstart=AUTO
scconfigProtectedStoragestart=AUTO
scconfigRasAutostart=DEMAND
scconfigRasManstart=DEMAND
scconfigRDSessMgrstart=DEMAND
scconfigRemoteAccessstart=DISABLED
scconfigRemoteRegistrystart=AUTO
scconfigRpcLocatorstart=DEMAND
scconfigRpcSsstart=AUTO
scconfigRSVPstart=DEMAND
scconfigSamSsstart=AUTO
scconfigSCardSvrstart=DEMAND
scconfigSchedulestart=AUTO
scconfigseclogonstart=AUTO
scconfigSENSstart=AUTO
scconfigSharedAccessstart=AUTO
scconfigShellHWDetectionstart=AUTO
scconfigSpoolerstart=AUTO
scconfigsrservicestart=DISABLED
scconfigSSDPSRVstart=DEMAND
scconfigstisvcstart=DEMAND
scconfigSwPrvstart=DEMAND
scconfigSysmonLogstart=DEMAND
scconfigTapiSrvstart=DEMAND
scconfigTermServicestart=DEMAND
scconfigThemesstart=AUTO
scconfigTlntSvrstart=DISABLED
scconfigTrkWksstart=AUTO
scconfigUMWdfstart=DEMAND
scconfigupnphoststart=DEMAND
scconfigUPSstart=DEMAND
scconfigVSSstart=DEMAND
scconfigW32Timestart=AUTO
scconfigWebClientstart=AUTO
scconfigwinmgmtstart=AUTO
scconfigWmdmPmSNstart=DEMAND
scconfigWmistart=DEMAND
scconfigWmiApSrvstart=DEMAND
scconfigwscsvcstart=AUTO
scconfigwuauservstart=AUTO
scconfigWZCSVCstart=AUTO
scconfigxmlprovstart=DEMAND
echo恢复XP原系统服务结束,按任意键返回!
pause>nul
gotostart2
:
start3
cls
echoWindowsXp优化文件!
echoPoweredByThunderRay!
echo.
echo==============================
echo请选择要进行的操作,然后按回车
echo==============================
echo.
echo1.封杀135,445端口
echo.
echo2.恢复135,445端口
echo.
echo3.返回主菜单
echo.
echo4.退出
echo.
:
Choice3
setchoice3=
set/pchoice3=请选择:
IFNOT"%Choice3%"==""SETChoice2=%Choice2:
~0,1%
if/i"%choice3%"=="1"gotokillport
if/i"%choice3%"=="2"gotoopenport
if/i"%choice3%"=="3"gotostart
if/i"%choice3%"=="4"gotoend
echo选择无效,请重新输入
echo.
gotoChoice3
:
killport
cls
echo开始封杀135,445端口...
regaddHKLM\SOFTWARE\Microsoft\Ole/vEnableDCOM/dN/f
regaddHKLM\SOFTWARE\Microsoft\Rpc/v"DCOMProtocols"/tREG_MULTI_SZ/dncacn_spx\0ncacn_nb_nb\0ncacn_nb_ipx\0/f
scconfigMSDTCstart=DISABLED
regaddHKLM\SYSTEM\C
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- dos 使用 set 命令 实现 choice 功能