Reboot the server from the ASP.NET application when AppPool starts under the LocalSystem or LocalService account

Is it possible to restart the server from an ASP.NET application that is hosted in a LocalSystem or LocalService account? This works when I create a user admin account and run AppPool under this account:

Process.Start("shutdown", "/r /d 4:1 /t 10"); 

However, I do not want to have custom accounts (due to the expiration of the password and the need to update all AppPools applications when the user password is changed - I need to support multiple servers).

So is this possible?

+4
source share
2 answers

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.

+6
source

You may have a code that represents a particular account when you make this call, or create a web service with one account. I recommend a web service, in the worst case you upgrade one application pool. You can also block the web service only for your applications.

A small C # class to impersonate a user

+2
source

Source: https://habr.com/ru/post/1383255/


All Articles