2014-10-02 97 views
0

我找不到爲什麼我的代碼關閉程序幫助的原因!當我運行該程序,我可以進入該程序,然後它隨機關閉我一直在試圖解決它的一個小時,現在請大家幫忙批處理程序在嘗試使用IF語句時關閉

@echo off 
title Services Program 
color 0e 

set mainMenu=0 

goto check_Permissions 

:check_Permissions 
    echo Administrative permissions required. Detecting permissions... 

    net session >nul 2>&1 
    if %errorLevel% == 0 (
     echo Success: Administrative permissions confirmed. 
    ) else (
     echo Failure: Current permissions inadequate. 
    echo Restart this program but run it in administrator mode! 
    pause >nul 
    ) 

    pause >nul 
    goto main 

:main 
cls 
echo Main Menu 
echo. 
echo 1 - Start 
echo 2 - Options 
echo 3 - Exit 
set /p id=Enter The Value:%=% 

IF %id%==1(
echo Pow 
pause 
    ) 
goto main 



:program 
echo Insert Program here 
pause 
goto main 


:options 
echo Options 
pause 
goto main 

回答

1
IF %id%==1(

是不正確的語法。

IF "%id%"=="1" (

應該工作。所述(之前的空間需要

因爲id可以或可以不具有一個值,或者可以包含空格或其他分離器或笨拙字符批次發現令人討厭,它括在"quotes"除去到的靈敏度(空,包含分隔符)[但不幸的是,以"unbalanced quotes]

==運營商的雙方需要exactly匹配 - 所以引號必須包括雙方。

0

你如果是不正確

IF %id%==1(

首先,它需要括號前添加一個空格,然後你是一個錯誤的比較,因爲「==」運營商只是比較字符串和你工作的時候」重新嘗試與一個數字進行比較。你可以做如下:

if %id% EQU 1 (<--- IF only parses numbers when one of the compare-op operators (EQU, NEQ, LSS, LEQ, GTR, GEQ) is used. 
if "%id%" == "1" (<--- To force a string comparison. The == comparison operator always results in a string comparison. 

對於進一步閱讀,follow this link