Steve Ewart Steve Ewart - 1 month ago 17
C# Question

Batch file getting syntax error

I am trying to write a batch file that checks if your computer name is a certain name, and then if it matches the exe file will run.

@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


I am getting some error about (something) was not expected here, or syntax error, but I can't really read it because the command prompt closes too quickly. Any help?

Answer

Your syntax for the IF statement is wrong. Try this:

@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
)