2017-01-20 46 views
-2

我一直到我的批處理文件結束,到「測試」回聲。然後劇本爆炸了。它從來沒有使它成爲「test1」聲明。我不確定爲什麼會這樣,因爲有條件的命令幾乎與以前的命令相同。爲什麼我的批處理文件沒有處理最後的條件語句?

這是我的代碼。我已經註釋了編輯註冊表的命令,以便您可以安全地運行此腳本。發生相同的行爲。

@echo OFF 

echo A "feature" in Windows 7 may cause problems for some programs in 
echo certain conditions. 
echo. 
echo Basically, if you have a high resolution screen at install time, Win7 will 
echo install a larger font set (125%) by default. If you then choose go back to the 
echo standard font size (100%), Windows will keep some of the large fonts even 
echo though everything else is adjusted for standard fonts, causing programs that 
echo use these fonts to break because the text will not always fit inside the GUI. 
echo. 
echo. 

for /f "tokens=4-5 delims=. " %%i in ('ver') do set VERSION=%%i.%%j 

if "%version%" == "6.1" (
    echo Verified Windows 7 system 
    echo. 
) else (
    echo This is not a Windows 7 system. 
    goto end 
) 


setlocal ENABLEEXTENSIONS 

::variable used for validation logic 
set fontsExist=true 

:: Sets the Registry Key Name 
set KEY_NAME="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" 

:: Sets the Registry Sub Key Names 
set COURIER_VALUE_NAME="Courier 10,12,15" 
set MS_SANS_SERIF_VALUE_NAME="MS Sans Serif 8,10,12,14,18,24" 
set MS_SERIF_VALUE_NAME="MS Serif 8,10,12,14,18,24" 

:: Queries the registry for the Courier 10,12,15 font and saves the data 
FOR /F "usebackq skip=2 tokens=1-6" %%A IN (`REG QUERY %KEY_NAME% /v %COURIER_VALUE_NAME% 2^>nul`) DO (
    set COURIER_ValueName=%%A %%B 
    set COURIER_ValueType=%%C 
    set COURIER_ValueValue=%%D 
) 

if defined COURIER_ValueName (
    @echo Courier 10,12,15 Value Name = %COURIER_ValueName% 
    @echo Courier 10,12,15 Value Type = %COURIER_ValueType% 
    @echo Courier 10,12,15 Value Value = %COURIER_ValueValue% 
    echo. 
) else (
    @echo %KEY_NAME%\%COURIER_VALUE_NAME% not found. 
    echo. 
    set fontsExist=false 
) 

FOR /F "usebackq skip=2 tokens=1-6" %%A IN (`REG QUERY %KEY_NAME% /v %MS_SANS_SERIF_VALUE_NAME% 2^>nul`) DO (
    set MS_SANS_SERIF_ValueName=%%A %%B %%C %%D 
    set MS_SANS_SERIF_ValueType=%%E 
    set MS_SANS_SERIF_ValueValue=%%F 
) 

if defined MS_SANS_SERIF_ValueName (
    @echo MS Sans Serif 8,10,12,14,18,24 Value Name = %MS_SANS_SERIF_ValueName% 
    @echo MS Sans Serif 8,10,12,14,18,24 Value Type = %MS_SANS_SERIF_ValueType% 
    @echo MS Sans Serif 8,10,12,14,18,24 Value Value = %MS_SANS_SERIF_ValueValue% 
    echo. 
) else (
    @echo %KEY_NAME%\%MS_SANS_SERIF_VALUE_NAME% not found. 
    echo. 
    set fontsExist=false 
) 

FOR /F "usebackq skip=2 tokens=1-5" %%A IN (`REG QUERY %KEY_NAME% /v %MS_SERIF_VALUE_NAME% 2^>nul`) DO (
    set MS_SERIF_ValueName=%%A %%B %%C 
    set MS_SERIF_ValueType=%%D 
    set MS_SERIF_ValueValue=%%E 
) 

if defined MS_SERIF_ValueName (
    @echo MS Serif 8,10,12,14,18,24 Value Name = %MS_SERIF_ValueName% 
    @echo MS Serif 8,10,12,14,18,24 Value Type = %MS_SERIF_ValueType% 
    @echo MS Serif 8,10,12,14,18,24 Value Value = %MS_SERIF_ValueValue% 
    echo. 
) else (
    @echo %KEY_NAME%\%MS_SERIF_VALUE_NAME% not found. 
    echo. 
    set fontsExist=false 
) 

if fontExists==false (
    echo Not all fonts exist. 
    echo. 
    goto end 
) 

echo If you want to write to your registry then 
pause 
echo. 

:courier_eval 

::checks for correct values 
if %COURIER_ValueValue%==COURF.FON (
    echo Courier 10,12,15 registry key is correct. 
    goto san_eval 
) 

::checks for known incorrect values 
if %COURIER_ValueValue%==COURE.FON (
    echo COURIER font registry value is incorrect. Attempting to correct... 
    ::REG ADD %KEY_NAME% /v %COURIER_VALUE_NAME% /t "%COURIER_ValueType%" /d "COURE.FON" /f 
    goto san_eval 
) 

:san_eval 

::checks for correct values 
if %MS_SANS_SERIF_ValueValue%==SSERIFF.FON (
    echo MS Sans Serif 8,10,12,14,18,24 registry key is correct. 
    goto serif_eval 
) 

::checks for known incorrect values 
if %MS_SANS_SERIF_ValueValue%==SSERIFE.FON (
    echo MS SANS SERIF font registry value is incorrect. Attempting to correct... 
    ::REG ADD %KEY_NAME% /v %MS_SANS_SERIF_VALUE_NAME% /t "%MS_SANS_SERIF_ValueType%" /d "SSERIFE.FON" /f 
    goto serif_eval 
) 
:serif_eval 

::checks for correct values 
if %MS_SERIF_ValueValue%==SERIFF.FON (
    echo MS Serif 8,10,12,14,18,24 registry key is correct. 
    goto end 
) 
echo test 
pause 

::checks for known incorrect values 
if %MS_SERIF_ValueValue%==SERIFE.FON (
    echo MS SERIF font registry value is incorrect. Attempting to correct... 
    ::REG ADD %KEY_NAME% /v %MS_SERIF_VALUE_NAME% /t "%MS_SERIF_ValueType%" /d "SERIFE.FON" /f 
) 
echo test1 
pause 
:end 

pause 

有問題的代碼是echo testecho test1靠近的端部之間。

+6

Bravo for comment-out。問題在於'::'註釋風格往往會破壞代碼塊 - 使用'rem'來代替。你說沒有達到'test1',但是你沒有說'test'或'MS SERIF字體註冊表值是不正確的。正在嘗試糾正......,但你沒有說明「MS_SERIF_ValueValue」或任何其他變量的值。請澄清。 – Magoo

+0

嗯,我不知道'::'評論風格。我已經將所有這些變成了「rem」,問題現在已經消失了。請張貼作爲答案,我會表明你的答案解決了這個問題。 – Grant

+0

順便提一下,註釋掉'Reg ADD'會把你說的相同的數據'SERIFE.FON'知道是不正確的?國際海事組織更好的辦法是檢查是否存在正確的文件,並導入以前保存的reg文件或從其他pc上。 – LotPings

回答

1

問題是::評論風格傾向於打破代碼塊 - 使用rem代替。