tags:

views:

65

answers:

4

I'm using .NET, and going crazy trying to find any helpful API that lets me transfer a file across a LAN network (trough admin credentials of course) and then execute it on that machine.

I've read some thing using WMI, but googling for ".net WMI copy files" or ".net WMI execute files" isn't helping me at all.

Any references would be greatly appreciated.

EDIT

I can't use a third party tool such as PsExec (although it does perfectly what I need). This is because of the license involved with PsExec I cannot distribute it with my application.

A: 

On machines that don't have PowerShell 2.0 remoting enabled, I find the PsExec commandline tool very useful. It requires administration permissions on the remote machine.

kbrimington
+1  A: 

I don't think that this is easily achieved. You can however copy the exe with .net. And then (also from .net, with Process.Start) invoke psExec and make it execute the program remotely.

klausbyskov
Unfortunately I can't use third party tools like PsExec. I need to do this directly through the .NET api.. or other native means.
Luca Matteis
Also the official link on microsoft says this about the Process class: `Provides access to local and remote processes and enables you to start and stop local system processes.` So Process.Start only works to start **local** processes.
Luca Matteis
@Luca Matteis, you are correct, but I was talking about using Process.Start to invoke psExec.
klausbyskov
A: 

Ok, if you have admin rights, you can change the way .NET runs, but I've dealt with a similar problem and one thing I come up against is: .NET security doesn't allow execution of remote code on a computer (by default). what I mean by that is if:

Server (S) has a CIFS file share \\S\MyProg.exe then clients 1-n (C1-Cn) cannot simply execute that right off the server because of .NET security settings.

I understand the reasoning behind this, but it's somewhat frustrating when you're trying to store a library somewhere. Plus as long as it's not .NET you can execute the remote assembly as if it's on the local machine.

My solution was to go back in tech:

Source: execute.bat

@echo off
::: execute - calls a remote executable without DLL dependencies etc - will need modification if
:::           other files need to be downloaded.
::: syntax: execute $remote
:::   remote - a remote exe to run locally
if "%~1"=="" findstr "^:::" "%~f0"&GOTO:EOF

copy \\s\%1 %TEMP\%1
call %TEMP%\%1
del %TEMP%\%1

K so that's to get around the executing problem on remote machines, but presumably you also wish to initiate the app from the server (S). I'd build a listener for the clients... it can either be a full-fledged port listener, or something as simple as a CRON job that looks for a file and calls it if it's found. This file can then contain instructions as to which remote files to run locally. You could even create a local lock file to prevent multiple execution, or dual execution of long processes.

Rudu
A: 

You can consider to use Scheduler service (AT command) to start an application (see http://msdn.microsoft.com/en-us/library/aa384006.aspx) after the application code are copied to the remote computer.

Oleg