Reputation: 11356
i am trying to shutdown a remote computer on my network from a c# windows service. When i run the code below in a test app it works fine but when its run from the service nothing happens.
I have a feeling it may have something to do with permissions but not sure.
Does anyone have any suggestions?
Process p = new Process();
p.StartInfo.FileName = "shutdown";
p.StartInfo.Arguments = @"/s /f /m \\pc-name /t 0";
p.Start();
Upvotes: 0
Views: 134
Reputation: 2433
shutdown will fail if the account that you are logging in to on the remote PC doesn't have the SE_SHUTDOWN_NAME privilege.
This MSDN article contains a code snippet showing you how to set the SE_SHUTDOWN_NAME privilege from a program (and how to shutdown/restart the PC using the Windows API instead of calling the shutdown command).
But since you are running remotely and you may not be able to set those permissions programmatically, you can do so by logging in to the remote machine interactively and:
You will only have to do that once.
Good luck.
Upvotes: 0
Reputation: 3318
The service normaly runs with other credentials (Local System, Network Service etc) than your test app. You should consider creating a domain user that has the proper rights and add that user to your service.
Upvotes: 1