Run a batch with computer name

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
lalat06bag
Posts: 51
Joined: 10 Jan 2018 15:21

Run a batch with computer name

#1 Post by lalat06bag » 05 Apr 2018 14:09

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
Last edited by Squashman on 05 Apr 2018 14:21, edited 1 time in total.
Reason: MOD EDIT: Please use code tags.

Squashman
Expert
Posts: 4472
Joined: 23 Dec 2011 13:59

Re: Run a batch with computer name

#2 Post by Squashman » 05 Apr 2018 14:22

You are positive the computer name is in uppercase?

lalat06bag
Posts: 51
Joined: 10 Jan 2018 15:21

Re: Run a batch with computer name

#3 Post by lalat06bag » 05 Apr 2018 18:29

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
Attachments
Capture.PNG
Computer Name
Capture.PNG (5.02 KiB) Viewed 4618 times
Last edited by Squashman on 05 Apr 2018 19:25, edited 1 time in total.
Reason: MOD EDIT: Please use code tags.

Squashman
Expert
Posts: 4472
Joined: 23 Dec 2011 13:59

Re: Run a batch with computer name

#4 Post by Squashman » 05 Apr 2018 19:23

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.

lalat06bag
Posts: 51
Joined: 10 Jan 2018 15:21

Re: Run a batch with computer name

#5 Post by lalat06bag » 05 Apr 2018 19:44

Hi,

Never mind pls. It worked.

Please ignore the query.

Squashman
Expert
Posts: 4472
Joined: 23 Dec 2011 13:59

Re: Run a batch with computer name

#6 Post by Squashman » 05 Apr 2018 19:48

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

lalat06bag
Posts: 51
Joined: 10 Jan 2018 15:21

Re: Run a batch with computer name

#7 Post by lalat06bag » 05 Apr 2018 22:43

Thank you!

Post Reply