1

I have a computer A which hosts different kind of things:

  • A website (is developped using C# and ASP.Net)
  • Applications

Our customers have access to the website and sometimes, they will want to reboot the computer A (knowing that it will cut the website during the reboot).

My question is simple : does it exist a way of :

  • Rebooting a computer by simply clicking a button on an ASP.Net page ? How would I manage to do so ?
  • The same way, is it possible to execute some batch script (executes on the Computer A) when clicking on a button on an ASP.Net page ?

Thanks for your help!

Andy M
  • 5,945
  • 7
  • 51
  • 96

4 Answers4

3

This is secure enough way to do it (as long as password is stored securely)

ProcessStartInfo startInfo = new ProcessStartInfo("shutdown /r /f /t 5");
startInfo.UserName ="user with enough rights";
startInfo.Password ="password";
Process.Start(startInfo);

// /r - restart
// /f - force
// /t 5 - wait 5 seconds
Simon_Weaver
  • 140,023
  • 84
  • 646
  • 689
Anri
  • 6,175
  • 3
  • 37
  • 61
1

You can do it using System. Diagnostics.Process namespace, Please look at the following link for full process.

http://www.c-sharpcorner.com/UploadFile/yuanwang200409/RemoteRestartWindows09252006141003PM/RemoteRestartWindows.aspx

Rajesh Subramanian
  • 6,400
  • 5
  • 29
  • 42
1

It would be pretty easy to implement, but the question is if IIS will allow it. You will also open up for exploits, since if someone managed to exploit this, they could chain restart your server.

If you really want to go ahead and implement this, you could simply set up a Web Service call that triggers the following code.

System.Diagnostics.Process.Start("shutdown.exe", "-r -t 0");

Although, it does sounds more like you are looking for a management tool to handle this. I would recommend that you look at one of many tools available to help manage servers remotely. It is important for security that the management software has the ability to give the user specific privileges, like restricting them with access to only reboot the server.

eandersson
  • 25,781
  • 8
  • 89
  • 110
  • I was afraid of having rights problem with it... I didn't even tried it... I'll give it a try right now, thanks ! – Andy M Feb 12 '13 at 12:37
  • I would strongly recommend that you take a look at one of many remote administration solutions out there. That way you don't have to deal with all the security implications yourself. – eandersson Feb 12 '13 at 12:41
  • Actually, the website already contains users interface and security. I would simply allow administrator users to perform this tasks. Do you have examples of good administration tools ? – Andy M Feb 12 '13 at 12:46
  • Are you sure that they need to restart the whole PC, and not simply IIS? As for admin tools. I don't use Windows myself, but you could try http://www.webmin.com/ http://cpanel.net/ or http://www.parallels.com/products/plesk/ – eandersson Feb 12 '13 at 12:49
  • You are right, but you have to keep in mind that you would need the user to not only enter his normal website admin details, but also his Windows login details. This means that either he will need to input it at the website, or you need to store it locally. Both imposes massive security risks. – eandersson Feb 12 '13 at 12:53
  • If you need to do it. I would probably create a new Web Service with an app pool with a user dedicated for this. So that you can have an isolated user assigned to this app pool. This way you don't need to store credentials locally, and possible exploits wont have access to this app pool. – eandersson Feb 12 '13 at 12:58
1

You can execute "shutdown -r" command from C# in command line, see this SO question how to do it. Mind you that the application has to be very well secured, and the application running under IIS will have to have enough user rights.

Edit: Fuji's proposed way works well and doesn't even require elevated process (I didn't expect it to work, whoops ;))

Community
  • 1
  • 1
jhexp
  • 685
  • 4
  • 9
  • Yep, I'm aware it has to be very secure... It's a special kind of computer tho... Few people have access to it... – Andy M Feb 12 '13 at 12:36