0
votes

I need to change gateway address on multiple computers throughout the year and I wanted to create a batch file that would make my life a whole lot easier. The problem I am having is that once the batch file connects another computer, it no longer continues running the batch I coded until I "exit" from their computer and then it runs.

set /p ComName= Input Computer Name:

cd \diag

psexec \%ComName% cmd.exe

netsh interface ip set address name="local area connection" gateway=192.X.X.XXX gwmetric=0

ipconfig

After it runs the "psexec \%ComName% cmd.exe", what do I need to have that would allow the rest of my batch file run on the other computer?

2
Put the commands you want to run on the remote computer into a batch file and then run it on the remote computer using psexec. - aphoria
There has to be an alternative to that. I have close to 400 computers. I can't go to each computer, create a batch file and edit it every time I wish to run this batch file from my computer. Is there any possibility of getting my batch file to do everything from my computer? - user3376172
The batch file can just exist on your computer. - aphoria
Alternatively, you could run each command with PSEXEC. You wouldn't need to run CMD.EXE remotely. - aphoria
The purpose of this experiment was to remove having to type in as many commands as possible. But I think I found an answer to my question with part of your original answer of having a batch file on each computer. - user3376172

2 Answers

1
votes

You can do this a couple different ways.

Option 1 - One batch file

SET /P ComName=Input Computer Name:
CD \diag

PSEXEC \\%ComName% netsh interface ...<your parameters>...
PSEXEC \\%ComName% ipconfig


Option 2 - Two batch files

First.cmd

@ECHO OFF
SET /P ComName=Input Computer Name:
CD \diag

PSEXEC \\%ComName% -c Second.cmd

Note the -c parameter. It tells PSEXEC to copy the file to be run to the remote machine first.

Second.cmd

@ECHO OFF
netsh interface ...<your parameters>...
ipconfig
0
votes

Pass the commands as arguments to cmd with the /C option and explicitly call exit

psexec \\%ComName% cmd /C "( netsh interface ip set address name="local area connection" gateway=192.X.X.XXX gwmetric=0 && ipconfig ) & exit"