批处理文件获取语法错误

时间:2016-11-02 15:09:27

标签: c# batch-file error-handling

我正在尝试编写一个批处理文件来检查您的计算机名是否是某个名称,然后如果它与exe文件匹配则会运行。

@echo off

echo adidas shoe cop bot console...
echo by sam
pause

echo checking for computer name...

If %computername%=="DESKTOP-HQPDA76"
   then echo %computername% found
   echo user confirmed
   echo starting file
   pause
   start /B "" "C:\Users\Sam Marriott\Desktop\Adidas Shoe Cop Bot\Package\Adidas Shoe Cop Bot\bin\Debug\Adidas Shoe Cop Bot.exe"
   pause
Else NOT %computername%=="DESKTOP-HQPDA76"
   then echo user access denied
   pause

我收到一些错误(某事)在这里没有预期,或语法错误,但我无法真正阅读它,因为命令提示关闭太快。有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

您的IF语句的语法错误。试试这个:

@echo off

echo adidas shoe cop bot console...
echo by sam
pause

echo checking for computer name...

if "%computername%"=="DESKTOP-HQPDA76" (
    echo %computername% found
    echo user confirmed
    echo starting file
    pause
    start /B "" "C:\Users\Sam Marriott\Desktop\Adidas Shoe Cop Bot\Package\Adidas Shoe Cop Bot\bin\Debug\Adidas Shoe Cop Bot.exe"
    pause
) else (
     echo user access denied
     pause
)