0

Well going all in: assigning all my 72 point as bounty to this question!

How to run a command line program on remote Windows computers with out installing additional software (aka ssh). All recommendations on the web/stackoverflow fail following basic needs:

  1. The remote program shall be able to access a network share (read/write)!
  2. The output of the program shall be captured (back to controlling computer)
  3. Automat-able to run from a script (i.e. python)

I have looked at following:

  1. WMI -- can run a program but it cannot access network shares and output is not visible (fire and pray method?)
  2. WinRM -- supposedly can access network shares but setup is beyond complicated (seems to require not self-signed certificates and entring password, which fails C)
  3. PsExec -- cannot run executable from network path

Environment: all Win 7, can run as local admin

3
  • 1
    Seriously, this is a hard problem which has been solved pretty well by ssh authentication. I'd use that solution. Mar 17, 2013 at 17:25
  • +1 for ssh. Is there any reason you wouldn't want to use ssh, besides having to install it?
    – Xymostech
    Mar 17, 2013 at 17:27
  • I wish this was a linux question -- it's really mesmerizing that Windows makes it so convoluted. A. requires install, B. from what I've seen all operations run under services user account vs running in context of the calling user (security issue, no?)
    – okigan
    Mar 17, 2013 at 17:28

3 Answers 3

1

I would recommend PowerShell remoting. But answer to question how? depends very much on environment (domain/ workgroup) and your rights (on server/ within domain).

That's one command in AD environment:

Set-ADComputer -TrustedForDelegation $true -Identity <your target server>

And later:

Invoke-Command -ComputerName <target server> -ScriptBlock { your command }

... but that will not work in workgroup environment, so I guess you need to be more specific here.

2
  • Tried calling "Set-ADComputer", per error message it needs to be called on main Active Directory system and by domain admin -- which is outside of my rights of Local Admin
    – okigan
    Mar 19, 2013 at 5:01
  • That's why answer to question at the beginning of my answer is crucial if you want to get answer that's applicable for your environment/ account/ rights.
    – BartekB
    Mar 20, 2013 at 7:04
0

The psexec tool, originally created by Sysinternals, but now a part of Microsoft Technet, should do what you need.

With it you can run any command on a remote Windows computer, including copying over any executable, running it, and returning the results. You don't have to install anything on the remote computer.

Of course you have to have administrative or equivalent rights on the target machine to perform execution. In essence, if you cannot remote desktop or login to the machine, you won't be able to use it. That's pretty obvious.

Here is the product page: http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx

You can find many tutorials and guides on the Internet on how to use it.


I don't understand what you mean by "it cannot access the network".

Do the following:

  1. Write a script, a batch file, or an executable so that if you physically copy it to the target machine and double-click on it, it does everything you need (connects to the remote share and reads / writes data to it.) How to do that is beyond this question and actually depends on the technology you are going to use to write the script.
  2. Use psexec to run it on another target machine.

My understanding is that you are currently failing step 1, but the current question is about step 2.

4
  • ah, yes, I forgot to mention i tried that -- it cannot access to the network, can it?
    – okigan
    Mar 17, 2013 at 17:39
  • What do you mean it cannot access the network? You can use it to run any terminal command and launch any executable on the remote machine, including copying over and running any program you just wrote in C++, VBScript or whatever. Of course you can access the network from the target machine.
    – Tobia
    Mar 17, 2013 at 17:41
  • Intended to run executable itself from network: \\path.exe. This does not require copying when running even in Remote Desktop
    – okigan
    Mar 17, 2013 at 18:50
  • Your original question asks "The remote program shall be able to access a network share", not "The remote program shall reside on a network share".
    – Tobia
    Mar 17, 2013 at 18:58
0

Have you tried mapping the network share to a drive letter on the remote PC? PSExec would then be able to see the files in that share as local.

1
  • Yes, have tried that -- does not work: PsExec comes back with "The system cannot find the path specified." I have double checked the path, but running a local program ie. 'ipconfig' works...
    – okigan
    Mar 18, 2013 at 4:37

You must log in to answer this question.

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