简体   繁体   中英

Run a bat script on a distant computer from my computer (Command Prompt)

I work on my computer A . I would like to run a batch script.bat on my computer B ( C:\\Documents\\script.bat ). The password of the admin session of B is PASSWORD .

This is my command to execute my batch from computer B :

start C:\Documents\script.bat

Now, I would like to run it with this argument : 3.2.16 I've tried these 3 commands but it says "incorrect caracter"

start C:\Documents\script.bat "3.2.16"
start C:\Documents\script.bat '3.2.16'
start C:\Documents\script.bat 3.2.16

Also, I would like to run it from my computer A . Can you help me please ? Thank you in advance.

If you want to run a process remotely, you'll either need to use Sysinternals psexec , or wmic . The difference is that psexec diverts its output to the computer it's invoked from; whereas wmic displays a window on the remote PC.

If you're curious, the wmic command syntax is as follows:

wmic /node:remotePC /user:remotePC\user /password:password process call create 'cmd /c "c:\path\to\script.bat" "arg1" "arg2"'

If you need to view the output of script.bat , redirect the output remotely to a text file, then read the text file.

wmic /node:remotePC /user:remotePC\user /password:password process call create 'cmd /c blah ^>c:\output.txt'
net use z: \\remotePC\c$ /user:remotePC\user password
type z:\output.txt
del z:\output.txt
net use z: /delete

...for example. But it's probably easier just to download and use psexec .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM