I want to execute a batch file
D:\apache-tomcat-6.0.20\apache-tomcat-7.0.30\bin\shutdown.bat
Which is on my server inidsoasrv01
.
How should I write my .bat
file?
Type the following command to run a Windows 10 batch file and press Enter: C:\PATH\TO\FOLDER\BATCH-NAME. bat.
To create a share on a remote computer by using WMIC: At a command prompt, type wmic, and then press ENTER. Type /node:computer name where computer nameis the name of the target computer. If you want to pass administrator credentials, type /user:"domain\username", to receive a prompt for a password.
Doing it manually works fine: Run cmd, launch "C:\pstools\psexec.exe \user-pc -u domain\admin -p password cmd /k", it goes into CMD on a remote computer. Then i type "start \share\script. bat" and it launches my batch file.
To run a batch file, move to the directory containing the file and type the name of the batch file. For example, if the batch file is named "hope. bat," you'd type "hope" to execute the batch file.
Use microsoft's tool for remote commands executions: PsExec
If there isn't your bat-file on remote host, copy it first. For example:
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 execute:
psexec \\RemoteServerNameOrIP d:\apache-tomcat-6.0.20\apache-tomcat-7.0.30\bin\shutdown.bat
Note: filepath for psexec is path to file on remote server, not your local.
You can use WMIC or SCHTASKS (which means no third party software is needed):
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"
WMIC (wmic will return the pid of the started process)
WMIC /NODE:"remote_machine" /user:user /password:password process call create "c:\some.bat","c:\exec_dir"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With