2009-12-01 3 views

답변

0

먼저 System.ServiceProcess 어셈블리에 대한 참조를 추가해야합니다. 다음 코드는 당신이 (필자는 다음 messageLabel라는 Label 컨트롤 사용하고) 무엇을 원하는 약을 제공 : 그러나

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.ServiceProcess; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 

public partial class StartService : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     string serviceName = "Remote Registry"; 
     try 
     { 
      StartServiceByName(serviceName); 
     } 
     catch (Exception ex) 
     { 
      messageLabel.Text = ex.ToString().Replace("\r\n", "<BR>"); 
      return; 
     } 
     messageLabel.Text = String.Format("Service {0} started.", serviceName); 
    } 

    private void StartServiceByName(string serviceName) 
    { 
     ServiceController serviceController = new ServiceController(serviceName); 
     serviceController.Start(); 
    } 
} 

를 추가 것이 있습니다 - 당신은 웹 서버가 있어야합니다 이 서비스를 변경할 수있는 권한 - 일반적으로 관리 권한으로 만 수행 할 수있는 권한입니다.

0

테스트하지 않았습니다.

작동 여부를 확인하십시오. btn click 이벤트에서 다음 코드를 추가 할 수 있습니다.

dim controller as new ServiceController 

controller.MachineName = "." //try the machine name 
controller.ServiceName = "service name" 
dim status as string = controller.Status.ToString 

' Stop the service 
controller.Stop() 

' Start the service 
controller.Start() 
0

웹 사이트 계정의 권한에 따라 서비스를 시작/중지 할 수 있습니다.

다른 사람들이 대답 한 것 이외에도 적절한 매개 변수를 사용하여 NET START을 처리 할 수 ​​있습니다.

권한이 부여되는 한 원격 컴퓨터에서도이 작업을 수행 할 수 있습니다 (이 작업은 도메인 계정이어야 함).

관련 문제