0

We have the PsService.exe tool provided by Windows Sysinternals to start or Stop any remote machine's service.But in order to use this exe in our C# we need to use the a traditional approach where we invoke a process from C# code.

Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = @"C:\Path\PsService.exe";
p.StartInfo.Arguments = @"\\server64 restart spooler";
p.Start();

string output = p.StandardOutput.ReadToEnd();

p.WaitForExit();

With this approach we have very little control (exception handling, logging etc) and is a bit cumbersome to use. Is there any C# library through which we can achieve the same rather than invoking a process.

I did some Googling with very little luck.

The same applies to other tools like PsExec, PsKill etc

  • 1
    You can use the .Net approach to solve this, without using external tools. See [this question](http://stackoverflow.com/questions/467367/how-can-i-programmatically-stop-start-a-windows-service-on-a-remote-box). – Adrian Fâciu Sep 08 '14 at 08:30
  • Aahhh.. Nice pointer @Adrian... What a fool I was, didnt check out the 3rd overloaded method in [MSDN](http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicecontroller%28v=vs.110%29.aspx) – Darshan Sudhakar Sep 08 '14 at 08:43
  • I did get one for the [PsKill](http://weblogs.asp.net/stanleygu/tip-13-kill-a-process-from-local-to-remote). This is what happens when we google around using different permutations and combinations. – Darshan Sudhakar Sep 08 '14 at 08:47

0 Answers0