简体   繁体   English

从计算机上托管的ASP.Net页重新启动计算机

[英]Rebooting a computer from an ASP.Net page hosted on the computer

I have a computer A which hosts different kind of things: 我有一台计算机A,可以承载不同类型的事物:

  • A website (is developped using C# and ASP.Net ) 网站(使用C#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). 我们的客户可以访问该网站,有时他们会希望重新启动计算机A(知道它将在重新启动过程中切断网站)。

My question is simple : does it exist a way of : 我的问题很简单:它是否存在一种方式:

  • Rebooting a computer by simply clicking a button on an ASP.Net page ? 只需单击ASP.Net页面上的按钮即可重新启动计算机? 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 ? 同样,单击ASP.Net页面上的按钮时是否可以执行某些批处理脚本(在计算机A上执行)?

Thanks for your help! 谢谢你的帮助!

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

You can do it using System. 您可以使用系统来完成。 Diagnostics.Process namespace, Please look at the following link for full process. Diagnostics.Process命名空间,请查看以下链接以获取完整过程。

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

It would be pretty easy to implement, but the question is if IIS will allow it. 这将很容易实现,但是问题是IIS是否允许它。 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. 如果您确实想继续执行此操作,则可以简单地设置一个触发以下代码的Web Service调用。

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. 对于安全性而言,管理软件具有向用户提供特定特权的能力非常重要,例如可以限制用户仅重新启动服务器的访问权限。

You can execute "shutdown -r" command from C# in command line, see this SO question how to do it. 您可以在命令行中的C#中执行“ shutdown -r”命令,请参阅 SO问题如何执行。 Mind you that the application has to be very well secured, and the application running under IIS will have to have enough user rights. 请注意,应用程序必须非常安全,并且在IIS下运行的应用程序必须具有足够的用户权限。

Edit: Fuji's proposed way works well and doesn't even require elevated process (I didn't expect it to work, whoops ;)) 编辑:Fuji提出的方法行之有效,甚至不需要经过改进的过程(我没想到它会起作用,哎呀;))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM