0
A
回答
0
这不是一个好方法IMO。 Web应用程序应该在浏览器中进行沙盒处理,不应以任何方式访问系统资源。您可能想要创建一个WCF Web服务,它将由Windows服务调用,然后您的Web应用程序可以访问Web服务。
为了回答这个问题的缘故:
Original Link for Code:
private void Page_Load(object sender, System.EventArgs e)
{
string PcName = "PC Name";
WindowsImpersonationContext wic = null;
try
{
IPrincipal p = this.User;
WindowsIdentity id = (WindowsIdentity)p.Identity;
Response.Write("Running as:" + WindowsIdentity.GetCurrent().Name + "<br>");
wic = id.Impersonate();
Response.Write("Running as:" + WindowsIdentity.GetCurrent().Name + "<br>");
ServiceController[] services = ServiceController.GetServices();
for(int i = 0; i < services.Length; i++)
{
if (services[i].DisplayName == "COM+ System Application")
{
Response.Write(services[i].DisplayName + " - ");
Response.Write(services[i].Status.ToString());
Response.Write("<br>");
ServiceController sc = new ServiceController(services[i].DisplayName,PcName);
if (sc.Status == ServiceControllerStatus.Running)
{
sc.Stop();
}
if (sc.Status == ServiceControllerStatus.Stopped)
{
sc.Start();
}
}
}
}
catch(Exception err)
{
Response.Write(err.Message);
}
finally
{
wic.Undo();
}
}
但是,你可能会遇到的安全问题,所以看看线程中的所有响应。
相关问题
- 1. 使用ASP.NET Web应用程序部署WCF服务
- 2. 部署Web应用程序
- 3. 在ASP.NET中部署Web应用程序
- 4. 在SUP2.0中部署Web应用程序
- 5. 使用Web服务部署Web应用程序后出现“java.lang.NoSuchMethodError”
- 6. 在AWS上部署Web应用程序
- 7. 在JBoss上部署Web应用程序
- 8. 使用Web部署与Web应用程序部署Web作业
- 9. 如何在特定的Web应用程序中部署WCF服务
- 10. 将Web服务部署到我的Google App Engine应用程序
- 11. Web应用程序,WCF服务和Sharepoint Web服务
- 12. 使用Web部署在IIS Express上发布WCF服务应用程序
- 13. 在WebLogic服务器上部署Java Web应用程序
- 14. 部署多个web应用程序在同一台服务器
- 15. 网络应用程序和Web服务部署在一起?
- 16. 在Web应用程序的AppDomain中使用Ninject和WCF服务?
- 17. 远程部署Web应用程序(.war)
- 18. 通过ASP.NET Web应用程序在IIS上自动部署Web应用程序?
- 19. 如何在WCF Web服务应用程序中引用文件?
- 20. 无法使用Web部署工具部署Web应用程序
- 21. 使用ECLIPSE部署Web应用程序
- 22. Web服务与Web应用程序
- 23. Web服务,Web应用程序
- 24. Symfony2的Web应用程序部署
- 25. 部署一个Web应用程序,该应用程序引用与WCF服务通信的类库
- 26. 部署Web应用程序到Tomcat服务器使用Maven
- 27. jQuery/WCF Web应用程序
- 28. 部署WCF应用程序
- 29. Python web应用程序部署多个应用程序实例
- 30. 将Web应用程序部署到Tomcat服务器的问题