Page 1 of 1

Run a batch with computer name

Posted: 05 Apr 2018 14:09
by lalat06bag
I want to run another batch file when executed on a particular computer. But below script is not working, please suggest.

Code: Select all

@echo off

If "%computername%"=="DXX" (

echo "Computer FOUND"
pause
goto :eof
)

:eof
Exit

Re: Run a batch with computer name

Posted: 05 Apr 2018 14:22
by Squashman
You are positive the computer name is in uppercase?

Re: Run a batch with computer name

Posted: 05 Apr 2018 18:29
by lalat06bag
With this, computer name shows in upper case. Please see the attachment.

Code: Select all

@echo off
echo %ComputerName%
pause
If "%computername%"=="USER-PC" (

echo  Computer FOUND
goto :eof
)

:eof
Exit

Re: Run a batch with computer name

Posted: 05 Apr 2018 19:23
by Squashman
Turn ECHO ON and lets see all the verbose output of the script running.

You do know you can copy and paste the text in the console window. That is a lot easier then creating a screen shot and posting it here.

Also, could you please be courteous and use code tags with your code. Thanks.

Re: Run a batch with computer name

Posted: 05 Apr 2018 19:44
by lalat06bag
Hi,

Never mind pls. It worked.

Please ignore the query.

Re: Run a batch with computer name

Posted: 05 Apr 2018 19:48
by Squashman
Just a quick tip for you. Don't create the label :EOF. It is already a built-in label.
Please read this.
https://ss64.com/nt/goto.html

Re: Run a batch with computer name

Posted: 05 Apr 2018 22:43
by lalat06bag
Thank you!