【问题标题】:Batch: The syntax of the command is incorrect?批处理:命令的语法不正确?
【发布时间】:2014-12-31 02:42:21
【问题描述】:

我找不到错误我花了很长时间试图修复这个错误但我找不到错误。

当我运行以下代码时,批处理文件不断提示我命令的语法不正确

有什么问题?

代码:

@echo off 

whoami /groups | find "S-1-16-12288" > nul

if %errorlevel% == 0 (
goto :Runing in Admin Mode
) ELSE (
goto :Not Runing in Admin Mode
)

if %errorlevel% == 2 (
goto :Not Runing in Admin Mode
) ELSE (
goto :Runing in Admin Mode
)

SET AND=IF
SET THEN=(
SET ELSE=) ELSE (
SET NOELSE=
SET ENDIF=)
SET BEGIN=(
SET END=)
SET RETURN=EXIT /B

:Runing in Admin Mode
if %errorlevel% == 0 (
echo Runing in Admin Mode
echo.
attrib -h FileCompressionTool.bat

IF EXIST "upx.exe" %THEN%
attrib -h upx.exe
set missingfilesFalse=False
%ELSE%
 echo upx.exe. missing.
set missingfilesTrue=True
ping >nul 3 %THEN%

IF EXIST "mpress.exe" %THEN%
attrib -h mpress.exe
set missingfilesFalse=False
%ELSE%
echo mpress.exe. missing.
set missingfilesTrue=True
ping >nul 3 
%THEN%

IF EXIST strip.exe  %THEN%
attrib -h strip.exe
%ELSE%
echo strip.exe. missing.
set missingfilesTrue=True
ping >nul 3 %THEN%

IF EXIST reshacker.exe  %THEN%
attrib -h reshacker.exe
%ELSE%
echo reshacker.exe. missing.
set missingfilesTrue=True
ping >nul 3 %THEN%

IF EXIST reshacker.ini %THEN%
attrib -h reshacker.ini
%ELSE%
echo reshacker.ini. missing.
set missingfilesTrue=True
ping >nul 3 %THEN%

IF EXIST reshacker.Log %THEN%
attrib -h reshacker.Log
%ELSE%
echo reshacker.Log. missing.
set missingfilesTrue=True
ping >nul 3 %THEN%

%NOELSE%
%ENDIF%
%NOELSE%
%ENDIF%
%NOELSE%
%ENDIF%
%NOELSE%
%ENDIF%
%NOELSE%
%ENDIF%
%NOELSE%
%ENDIF%

cls

:Not Runing in Admin Mode
if %errorlevel% == 2 (
echo Not Runing in Admin Mode
echo.

attrib -h FileCompressionTool.bat

IF EXIST "upx.exe" %THEN%
attrib -h upx.exe
set missingfilesFalse=False
%ELSE%
echo upx.exe. missing.
set missingfilesTrue=True
ping >nul 3 %THEN%

IF EXIST "mpress.exe" %THEN%
attrib -h mpress.exe
set missingfilesFalse=False
%ELSE%
echo mpress.exe. missing.
set missingfilesTrue=True
ping >nul 3 
%THEN%

IF EXIST strip.exe  %THEN%
attrib -h strip.exe
%ELSE%
echo strip.exe. missing.
set missingfilesTrue=True
ping >nul 3 %THEN%

IF EXIST reshacker.exe  %THEN%
attrib -h reshacker.exe
%ELSE%
echo reshacker.exe. missing.
set missingfilesTrue=True
ping >nul 3 %THEN%

IF EXIST reshacker.ini %THEN%
attrib -h reshacker.ini
%ELSE%
echo reshacker.ini. missing.
set missingfilesTrue=True
ping >nul 3 %THEN%

IF EXIST reshacker.Log %THEN%
attrib -h reshacker.Log
%ELSE%
echo reshacker.Log. missing.
set missingfilesTrue=True
ping >nul 3 %THEN%

%NOELSE%
%ENDIF%
%NOELSE%
%ENDIF%
%NOELSE%
%ENDIF%
%NOELSE%
%ENDIF%
%NOELSE%
%ENDIF%
%NOELSE%
%ENDIF%

cls

IF EXIST "%~1" %THEN%
SET "result=%~1"
%ELSE%
SET "result="
%ENDIF%

set False= Pause

set True=echo Some file are missing this program may not work correctly please Re-download                                         **File Compression Tool**


echo 1 UPX Compression
echo 2 Mpress Compression
echo 3 Decompress a file
echo 4 Remove VB6 default icon
echo Type exit to exit 
echo.
if "%missingfilesTrue%"=="True" %true%

Set /p choice= 
If %choice%==1 goto :1
If %choice%==2 goto :2
If %choice%==3 goto :3
If %choice%==4 goto :4
If %choice%==exit goto :exit

if %missingfilesTrue%==True(
 %true%
) else (
if %missingfilesFalse%==False
%False%
)

goto :exit

:1
cls
echo ***Drag your exe file into this window and press enter***
set /p File=: 
echo.
copy %file% %file%.bak
upx --best %file%
echo.
echo Done!
echo Press any key to exit. . .
pause >nul
goto exit

:2
cls
echo ***Drag your exe file into this window and press enter***
set /p file=: 
echo.
copy %file% %file%.bak
Mpress -s %file%
echo.
echo Done!
echo Press any key to exit. . .
pause >nul
goto exit

:3
cls
echo ***Drag your exe file into this window and press enter***
set /p file=: 
echo.
copy %file% %file%.bak
upx -d %file%
echo.
echo Done!
echo Press any key to exit. . .
pause >nul
goto exit

:4
cls
echo ***Drag your exe file into this window and press enter***
set /p thefile=:

(
reshacker -delete %thefile%, %thefile%, ICONGROUP, 1, 0
)

strip -s --strip-all -g -S -d --strip-debug -x --discard-all -X --discard-locals %thefile%
upx -9 %thefile%
echo.
echo Done!
echo Press any key to exit. . .
pause >nul
goto exit

:exit
Exit

【问题讨论】:

  • 我认为标签名称中不能有空格。此外,%THEN% 看起来也不对;这将引用一个名为THEN 的变量。 (我不太了解 Windows 批处理语法,无法进一步评论。)
  • 删除@echo 关闭的行。你可以找出哪里出错了
  • 没想到我会试试谢谢。

标签: batch-file if-statement syntax cmd


【解决方案1】:
if %errorlevel% == 0 (
goto :Runing in Admin Mode
) ELSE (
goto :Not Runing in Admin Mode
)

如果errorlevel0goto 标签:Runing 和标签:Not 否则(因为not 是一个批处理关键字,这是一个可怕但不是非法的标签名称)

由于那时尚未建立变量“Then”等,它们将被它们当时的值(即什么都没有)替换,并且 - 好吧,在这样的代码中,我不会打扰计算结果。关注@echo off的评论,将显示构造命令的语法错误。

【讨论】:

    猜你喜欢
    • 2016-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多