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.

  • have a look at WMI or DCOM – zero_r Sep 1 '10 at 9:48
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

  • 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 '10 at 11:18
  • Yup, I missed that. – gWaldo Sep 1 '10 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/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.