Question

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?

No correct solution

OTHER TIPS

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

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"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top