How to execute a batch file on a remote PC using a batch file on a local PC

I want to execute a batch file

D: \ Apache-6.0.20-cat \ Apache-cat-7.0.30 \ Bin \ shutdown.bat

which is on my inidsoasrv01 server.

How do I write a .bat file?

+5
source share
4 answers

Use the Microsoft tool to execute remote commands: PsExec

If the remote host does not have your bat file, copy it first. For instance:

 copy D:\apache-tomcat-6.0.20\apache-tomcat-7.0.30\bin\shutdown.bat \\RemoteServerNameOrIP\d$\apache-tomcat-6.0.20\apache-tomcat-7.0.30\bin\ 

And then do:

 psexec \\RemoteServerNameOrIP d:\apache-tomcat-6.0.20\apache-tomcat-7.0.30\bin\shutdown.bat 

Note: the file path for psexec is the file path on the remote server, not the local one.

+8
source

You can use WMIC or SCHTASKS (this means that third-party software is not required):

1) SCHTASKS :

 SCHTASKS /s remote_machine /U username /P password /create /tn "On demand demo" /tr "C:\some.bat" /sc ONCE /sd 01/01/1910 /st 00:00 SCHTASKS /s remote_machine /U username /P password /run /TN "On demand demo" 

2) WMIC (wmic will return the pid of the running process)

 WMIC /NODE:"remote_machine" /user user /password password process call create "c:\some.bat","c:\exec_dir" 
+4
source

For now, I would recommend against this.

But you can use shutdown as a client if remote shutdown is enabled on the target machine and is in the same workgroup.

Example:

 shutdown.exe /s /m \\<target-computer-name> /t 00 

replacing <target-computer-name> with the URI for the target machine,

Otherwise, if you want to run this through Apache, you need to configure the script package as a CGI script by placing AddHandler cgi-script .bat and Options +ExecCGI in the local .htaccess file or in the main configuration for installing Apache.

Then you can simply call the .bat file containing the shutdown.exe from your browser.

0
source

If you are in the same WORKGROUP shutdown.exe /s /m \\<target-computer-name> shutdown /? should be enough shutdown /? for more, otherwise you need software to connect and manage the target server.

UPDATE:

It seems shutdown.bat is here to disable apache-tomcat.

So you might be interested in psexec or PuTTY: a free Telnet / SSH client

wmic may be your own solution

Example:

wmic /node:<target-computer-name> process call create "cmd.exe c:\\somefolder\\batch.bat"

In your example should be:

 wmic /node:inidsoasrv01 process call create ^ "cmd.exe D:\\apache-tomcat-6.0.20\\apache-tomcat-7.0.30\\bin\\shutdown.bat" 

wmic /? and wmic /node /? for more

0
source

All Articles