2014-10-02 64 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