Search code examples
c#.netwindowswindows-servicesrestart

How Restart Windows Server 2003 PC use C# in windows service?


The Server state is locked. C# in windows service, So I try use :

Process.Start("shutdown -r");

But looks like it's not working....

Is there any good way to Restart , Shutdown, Lock, Unlock use C# in windows service?


Solution

  • I don't know what restrictions apply for a windows service to spawn a child process.. For your needs, it may be worth trying and make a difference if you call the windows APIs directly.

    See which one might suit your needs from - http://msdn.microsoft.com/en-us/library/windows/desktop/aa376883(v=vs.85).aspx

    You can use http://pinvoke.net/ to find out how to declare almost any win api functions in your .net app.

    Hope this helps.