CMD if语句不按要求工作

时间:2014-02-26 05:34:25

标签: cmd

以下代码适用于使用Windows部署服务运行的脚本。

然而,我有这个问题,在它运行y之后并且实际上没有,如果我点击Y或N它仍然会这样做,我可以请指导我出错的地方。

由于

@echo off
Title Deployment Services - First Run

    :start
set /p intelchipset =Would you like to install Intel Chipset [y/n] ?: 
if "%intelchipset%"=="y". goto intelyes
if "%intelchipset%"=="n". goto basicprograms
if "%intelchipset%"=="Y". goto intelyes
if "%intelchipset%"=="N". goto basicprograms

    :intelyes
TITLE Deployment Services - Installing Intel Chipset
ECHO Deployment Services: Installing Intel Chipset 
net use G: \\StoreWDS\FirstTimeSetup
G:\Intel.exe
net use G: /delete
ECHO Intel Chipset Installed
goto basicprograms

    :basicprograms
TITLE Deployment Services - Basic Programs
set /p basicapps =Would you like to install Basic Programs [y/n] ?: 
if "%basicapps%"=="y" goto basicprogramsyes
if "%basicapps%"=="n" goto end

    :basicprogramsyes
net use G: \\StoreWDS\FirstTimeSetup
G:\install.exe
net use G: /delete
ECHO Basic Applications Installed
goto end


    :end
TITLE Deployment Services - Finishing Up
ECHO Running Aero Theme
set /p osversion =Is this installing Windows 8 or 8.1 or newer [y/n] ?: 
if "%osversion%"=="y" goto OS8
if "%osversion%"=="n" goto OS7

    :OS8
rundll32.exe %SystemRoot%\system32\shell32.dll,Control_RunDLL %SystemRoot%\system32\desk.cpl desk,@Themes /Action:OpenTheme /file:"%windir%\Resources\Themes\aero.theme"
ECHO Aero Theme Applied
GOTO continueend

    :OS7
rundll32.exe %SystemRoot%\system32\shell32.dll,Control_RunDLL %SystemRoot%\system32\desk.cpl desk,@Themes /Action:OpenTheme /file:"%windir%\Resources\Themes\aero.theme"
ECHO Aero Theme Applied
GOTO continueend

    :continueend
Echo Running Permissions - Notepad will open
net use G: \\StoreWDS\FirstTimeSetup
runas /user:User cmd
G:\permissions.txt 
G:\AddWSUS
takeown /f %systemdrive%\ /r
winsat dwm
net use G: /delete
ECHO Everything has been finished
pause

1 个答案:

答案 0 :(得分:3)

if /i "%intelchipset%"=="y" goto intelyes
if /i "%intelchipset%"=="n" goto basicprograms
goto start

if /i忽略了大小写。 ==适用于exactly matches - 但必须删除该点。无论是使用==还是equ,字符串都必须完全匹配。

与许多语言不同,批处理没有“程序”结束的概念 - 它只是逐行继续执行,直到它到达文件结尾。因此,如果所有选项都不匹配,则需要goto label - 否则批量收费只需通过。​​

OS测试显然也是如此。

请注意,如果用户只回复 Enter SET/P会保持变量不变。