windows xp下没有dos的choice命令的解决方法
dos6.0下能实现的choice选项,但是因为choice是外部命令,在xp中没有choice.exe所以不能实现选择菜单。解决办法:用SET命令代替
set命令详解
在批处理中回显信息有两个命令,echo和set/p=
代码:
@echooff echobathome echobatman pause>nul
代码:
@echooff set/p=bathomenul
运行这两段代码,大家看到第一段的结果是分两行依次在屏幕上输出了bathome
和batman,而第二段的结果是在一行中依次输出了bathome和batman,大家再仔细点还可看到光
标所处的位置也不一样。好了,就讲到这里吧。
一、set的主要作用是赋值
1、set/pa=promptstring
先显示promptstring,再接受用户输入的内容,以回车表示结束,赋值给变量a
2、set/pa=promptstring<1.txt
先显示promptstring,再把"<"管道号右边的1.txt文件中从第一个字符开始直到碰到回车符的内容赋值给变量a(通常表现为第一行)。
3、set/pa=promptstring
二、因为在接受用户输入前可先显示promptstring,故此set还可当作显示命令用(仅作为显示命令使用时,可省略变量a)
1、set/p=promptstring
显示promptstring,再接受用户输入的内容,以回车表示结束。如用户直接按回车则仅显示promptstring。(赋值给空变量,赋值意义已丧失,仅作显示之用,需用户按回车键结束语句,无多大实际用途)
2、set/p=promptstring<1.txt
先显示promptstring,再把"<"管道号右边的1.txt文件中从第一个字符开始直到碰到回车符的内容赋值给空变量(无实际用途)
3、set/p=promptstring
以下是补充:
显示、设置或删除cmd.exe环境变量。
SET[variable=[string]]
variable指定环境变量名。
string指定要指派给变量的一系列字符串。
要显示当前环境变量,键入不带参数的SET。
如果命令扩展被启用,SET会如下改变:
可仅用一个变量激活SET命令,等号或值不显示所有前缀匹配SET命令已使用的名称的所有变量的值。
例:SETP
会显示所有以字母P打头的变量
如果在当前环境中找不到该变量名称,SET命令将把ERRORLEVEL设置成1。
SET命令不允许变量名含有等号。
在SET命令中添加了两个新命令行开关:
SET/A
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显示的变量列表中。每次变量数值被扩展时,这些变量数值都会被动态计算。如果用户用这些名称中任何一个定义变量,那个定义会替代下面描述的动态定义:
í%-扩展到当前目录字符串。
úTE%-用跟DATE命令同样的格式扩展到当前日期。
%TIME%-用跟TIME命令同样的格式扩展到当前时间。
%RANDOM%-扩展到0和32767之间的任意十进制数字。
%ERRORLEVEL%-扩展到当前ERRORLEVEL数值。
%CMDEXTVERSION%-扩展到当前命令处理器扩展版本号。
%CMDCMDLINE%-扩展到调用命令处理器的原始命令行。
应用例子:
@echooff titleWindowsXp优化文件! :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\CurrentControlSet\Services\NetBT\Parameters/vSMBDeviceEnabled/tREG_DWORD/d0/f echo封杀135,445端口结束,按任意键返回! pause>nul gotostart3 :openport cls echo开始恢复135,445端口... regaddHKLM\SOFTWARE\Microsoft\Ole/vEnableDCOM/dY/f regaddHKLM\SOFTWARE\Microsoft\Rpc/v"DCOMProtocols"/tREG_MULTI_SZ/dncacn_spx\0ncacn_nb_nb\0ncacn_nb_ipx\0ncacn_ip_tcp\0/f scconfigMSDTCstart=AUTO regaddHKLM\SYSTEM\CurrentControlSet\Services\NetBT\Parameters/vSMBDeviceEnabled/tREG_DWORD/d1/f echo恢复135,445端口结束,按任意键返回! pause>nul gotostart3 :ip cls echo开始设置IP地址... netshinterfaceipsetaddressname="本地连接"static192.168.1.2255.255.255.0 echo设置IP地址结束,按任意键返回! pause>nul gotostart :other cls echo开始进行其它优化... taskkill/imTIMPlatform.exe/f del/f/s/qC:\Progra~1\Tencent\QQ\TIMPlatform.exe del/f/s/qD:\Progra~1\Tencent\QQ\TIMPlatform.exe taskkill/imrealsched.exe/f del/f/s/qC:\Progra~1\Common~1\Real\Update_OB\realsched.exe @rem删除运行QQ和Real时启动的多余程序 regdeleteHKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run/va/f regdeleteHKCR\Software\Microsoft\Windows\CurrentVersion\Run/va/f regdelete"HKLM\SOFTWARE\Microsoft\SharedTools\MSConfig\startupreg"/f del"C:\DocumentsandSettings\AllUsers\「开始」菜单\程序\启动\*.*"/q/f del"C:\DocumentsandSettings\DefaultUser\「开始」菜单\程序\启动\*.*"/q/f del"%userprofile%\「开始」菜单\程序\启动\*.*"/q/f @rem删除多余的启动项 regsvr32/u/sigfxpph.dll regdeleteHKCR\Directory\Background\shellex\ContextMenuHandlers/f regaddHKCR\Directory\Background\shellex\ContextMenuHandlers\new/ve/d{D969A300-E7FF-11d0-A93B-00A0C90F2719} regdeleteHKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run/vHotKeysCmds/f regdeleteHKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run/vIgfxTray/f @rem删除桌面多余的右键菜单 sfc/purgecache @rem消除系统缓存 regsvr32/u/szipfldr.dll @rem取消ZIP文件夹功能 regadd"HKCU\ControlPanel\Desktop"/vAutoEndTasks/tREG_DWORD/d1/f regadd"HKCU\ControlPanel\Desktop"/vHungAppTimeout/d50/f regadd"HKCU\ControlPanel\Desktop"/vWaitToKillAppTimeout/d200/f @rem加快关机速度 regadd"HKLM\SYSTEM\CurrentControlSet\Control\SessionManager\MemoryManagement\PrefetchParameters"/vEnablePrefetcher/tREG_DWORD/d1/f @rem启动条滚动一次 regaddHKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer/vAlwaysUnloadDLL/tREG_DWORD/d1/f @rem清除内存中不被使用的DLL文件 regadd"HKLM\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\AeDebug"/vAuto/d0/f @rem关闭华医生 regadd"HKLM\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\Winlogon"/vSFCDisable/tREG_DWORD/d4294967197/f @rem禁用文件保护 regadd"HKCU\Software\Microsoft\Windows\CurrentVersion\InternetSettings"/vMaxConnectionsPer1_0Server/tREG_DWORD/d8/f regadd"HKCU\Software\Microsoft\Windows\CurrentVersion\InternetSettings"/vMaxConnectionsPerServer/tREG_DWORD/d8/f @remIE下载多线程 regaddHKU\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Explorer/vLink/tREG_BINARY/d00000000/f @rem去掉快捷方式字样 regaddHKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\Explorer/vNoLowDiskSpaceChecks/tREG_DWORD/d1/f @rem取消磁盘空间太小提示 regaddHKLM\SYSTEM\CurrentControlSet\Control\FileSystem/vConfigFileAllocSize/tREG_DWORD/d500/f @rem优化文件系统 regaddHKCU\Console/vLoadConIme/tREG_DWORD/d0/f @rem运行CMD时不自动加载Conime regaddHKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system/vdontdisplaylastusername/tREG_DWORD/d1/f @rem不显示上次登陆用户名 regaddHKLM\SYSTEM\CurrentControlSet\Control\Lsa/vrestrictanonymous/tREG_DWORD/d1/f @rem不允许SAM帐户和共享的匿名枚举 regaddHKLM\SYSTEM\ControlSet001\Control\CrashControl/vAutoReboot/tREG_DWORD/d0/f regaddHKLM\SYSTEM\ControlSet001\Control\CrashControl/vCrashDumpEnabled/tREG_DWORD/d0/f regaddHKLM\SYSTEM\ControlSet001\Control\CrashControl/vDumpFile/tREG_EXPAND_SZ/d%SystemRoot%\MEMORY.DMP/f regaddHKLM\SYSTEM\ControlSet001\Control\CrashControl/vLogEvent/tREG_DWORD/d0/f regaddHKLM\SYSTEM\ControlSet001\Control\CrashControl/vMinidumpDir/tREG_EXPAND_SZ/d%SystemRoot%\Minidump/f regaddHKLM\SYSTEM\ControlSet001\Control\CrashControl/vOverwrite/tREG_DWORD/d1/f regaddHKLM\SYSTEM\ControlSet001\Control\CrashControl/vSendAlert/tREG_DWORD/d0/f @rem系统失败的几个勾全都不选 regaddHKLM\SOFTWARE\Microsoft\PCHealth\ErrorReporting/vDoReport/tREG_DWORD/d0/f regaddHKLM\SOFTWARE\Microsoft\PCHealth\ErrorReporting/vShowUI/tREG_DWORD/d0/f @rem禁用错误汇报,但在发生严重错误时通知我的勾不选 regaddHKCR\CLSID\{450D8FBA-AD25-11D0-98A8-0800361B1103}/vSortOrderIndex/tREG_DWORD/d54/f @rem桌面第一显示我的电脑 regaddHKLM\SOFTWARE\Classes\*\shell\OpenInNotepad/ve/d使用记事本打开/f regaddHKLM\SOFTWARE\Classes\*\shell\OpenInNotepad\command/ve/d"notepad.exe\"%%1%\""/f regaddHKCR\Directory\shell\DOS/ve/d使用DOS浏览/f regaddHKCR\Directory\shell\DOS\Command/ve/d"cmd.exe/k\"cd%%L%"/f @rem在文件右键菜单增加"使用记事本打开"&在文件夹右键增加使用DOS浏览 regadd"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\UserShellFolders"/vFavorites/tREG_EXPAND_SZ/dD:\Favorites/f regadd"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\UserShellFolders"/vPersonal/tREG_EXPAND_SZ/d"D:\MyDocuments"/f @rem将我的文档与收藏夹放在D盘下 echo其它优化结束,按任意键返回! pause>nul gotostart :OEM cls echo开始设置OEM信息... Copy/yOEM\*.*%windir%\system32\*.*>nul echoOEM设置信息结束,按任意键返回! pause>nul gotostart :virus cls echo开始清除根目录下的SXS病毒... FOR%%aIN(C:D:E:F:G:H:I:J:K:L:M:N:O:P:Q:R:S:T:U:V:W:X:Y:Z:)DOATTRIB-R-H-S-A%%a\SXS.EXE&DEL/F/Q/A-R-H-S-A%%a\SXS.EXE&ATTRIB-R-H-S-A%%a\AUTORUN.INF&DEL/F/Q/A-R-H-S-A%%a\AUTORUN.INF echo清除根目录下的SXS病毒结束,按任意键返回! pause>nul gotostart :del cls echo开始清理系统垃圾文件... del/f/s/q%systemdrive%\*.tmp del/f/s/q%systemdrive%\*._mp del/f/s/q%systemdrive%\*.log del/f/s/q%systemdrive%\*.gid del/f/s/q%systemdrive%\*.chk del/f/s/q%systemdrive%\*.old del/f/s/q%systemdrive%\recycled\*.* del/f/s/q%windir%\*.bak del/f/s/q%windir%\prefetch\*.* rd/s/q%windir%\temp&md%windir%\temp del/f/q%userprofile%\cookies\*.* del/f/q%userprofile%\recent\*.* del/f/s/q"%userprofile%\LocalSettings\TemporaryInternetFiles\*.*" del/f/s/q"%userprofile%\LocalSettings\Temp\*.*" del/f/s/q"%userprofile%\recent\*.*" echo清理系统垃圾文件结束,按任意键返回! echo. pause>nul gotostart :end exit
通过对以上的实现方式大家可以参考一下。