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服務器的問題