2011-03-11 2 views

답변

0

이것은 좋은 접근 방법이 아닙니다. 웹 응용 프로그램은 브라우저 내에서 샌드 박싱되어야하며 어떤 방식 으로든 시스템 리소스에 액세스해서는 안됩니다. Windows 서비스에서 호출하는 래퍼 WCF 웹 서비스를 만들고 웹 응용 프로그램이 웹 서비스에 액세스 할 수 있습니다. 이 문제에 대답을 위해서

:

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(); 
      } 

     } 

하지만 보안 문제로 실행, 그래서 스레드에서 모든 응답에서 좀 걸릴 수 있습니다.

관련 문제