You can always start the process with another person who can restart the server:
var info = new ProcessStartInfo("shutdown.exe", "/r /t 0"); info.UserName = "accountWithAdminPermissions"; //A not-so-secure use of SecureString var secureString = new SecureString(); var password = "abc123"; foreach (var letter in password) { secureString.AppendChar(letter); } info.Password = secureString; var restart = new Process(); restart.StartInfo = info; restart.Start();
If you just want to provide an account other than Administrator, permission to restart the server:
- Open
secpol.msc
. - Go to Local Policies \ User Rights Assignment.
- Find
Shutdown The System
. - Add an account.
This might be a good way to use an account to get the least privileges. Thus, you do not need to use a really big hammer, as an account in the Administrator group.
Shutdown.exe
(I believe) always requires administrator privileges. You can refer to this MSDN post when you restart the server without shutdown.exe.
source share