-1

I want to call a process on a remote pc. The following code works for local but i can`t make it work for remote pc

Process proc1 = new Process();

if (File.Exists("C:\\myApp.exe"))
{
    proc1.StartInfo.FileName = "C:\\myApp.exe";
    proc1.Start();
    proc1.Close();

}
chaliasos
  • 9,659
  • 7
  • 50
  • 87
pharaon450
  • 493
  • 3
  • 9
  • 21

2 Answers2

3

A similar question has been asked here:

How to execute a command in a remote computer?

One of the answers was to use sysinternals psexec

Another one of the answers was to use WMI

Community
  • 1
  • 1
Seth Flowers
  • 8,990
  • 2
  • 29
  • 42
  • Im sorry i cannot use psexec i was just wondering if there is an easy to lanch process from my pc to another pc in c# without installing anything, only with c# code – pharaon450 May 23 '12 at 18:43
  • @pharaon450 You can use WMI, as the answer already states. http://msdn.microsoft.com/en-us/library/windows/desktop/aa389769(v=vs.85).aspx and http://social.msdn.microsoft.com/forums/en-US/Vsexpressvb/thread/580953f5-2b6e-4dda-8d94-fbe2b9809f29/ – Seth Flowers May 23 '12 at 18:50
0

I'd agree with Seth Flowers - psexec is a good way to go about it.

--

Since you tagged your question as C# I'll add:

If you are asking because you're creating a distributed system where a host machine is spawning off jobs on child machines then you could create a C# host app and a C# client app and link them together using Windows Communication Foundation (WCF.) This would give you a service class to communicate with the other machines from the host. Once you can communicate between the machines, you could simply have the host tell the child "run this app" and you can use your process code on the child side.

This is a good article explaining the concept, I've used it before (side note, run VS as administrator if you use this or the metadataBehavior object will throw an exception): http://www.codeproject.com/Articles/16765/WCF-Windows-Communication-Foundation-Example

Brent Orford
  • 153
  • 1
  • 5
  • No i am asking because i create an app that is going to work on my pc (local) and this app will launch application on other pc of my network, what i really want to do is : with the app that is gonna be on my pc, i want to schedule task on others pc on my network – pharaon450 May 23 '12 at 19:13