1

I know PsExec is perfect for sending files over a computer on a network and then execute it on that remote computer, however I can't use PsExec because I'm developing a piece of software and I can't have PsExec as a dependency (for legal reasons etc.).

What's the easiest way to achieve the execution part on a remote computer? Is it really that hard? I am already copying the .bat file with xcopy... I just need to run it.

1
  • have a look at WMI or DCOM
    – zero_r
    Sep 1, 2010 at 9:48

3 Answers 3

5

You can execute a script, or binary, remotely using WMI. This is a minimal example, written in VBS, which runs the batch file C:\test.cmd located on the remote computer FCSD-ISC1.

strComputer = "FCSD-ISC1"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2:Win32_Process")
objWMIService.Create "C:\test.cmd", null, null, intProcessID

This is covered in more detail in this Scripting Guy article.

2

I recommend mounting the C$ share, testing for the .\Temp directory (creating if it doesn't exist), and copying there. (There is an "admin$" administrative share, but I recommend against using it.)

You can do this from the command line via net use * \\servername\c$ /user:domain/account or specify a drive as net use t: \\servername\c$ /user:domain/account

This should be well documented in MSDN. If writing for a script, there are a lot of examples in the Microsoft Script Center Repository

2
  • Even if you mount the remote share, execution of the batch file would occur on the local computer. @Luca says he's using xcopy place the file on the remote machine.
    – jscott
    Sep 1, 2010 at 11:18
  • Yup, I missed that.
    – gWaldo
    Sep 1, 2010 at 14:57
0

I know is not relevant anymore but for the sake of completness(this page is high on google) i'll add here RemCom, which is an open source version of Psexec get it here: http://sourceforge.net/projects/rce/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .