Tôi đang sử dụng mã C# để bắt đầu và dừng phục vụ cửa sổ nhưng tôi nhận được lỗi này.System.ComponentModel.Win32Exception: Truy cập bị từ chối Lỗi
System.ComponentModel.Win32Exception: Access is denied
Hãy giúp tôi.
Mã của tôi:
public void StartService(string serviceName, int timeoutMilliseconds)
{
ServiceController service = new ServiceController(serviceName);
try
{
TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds);
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running, timeout);
lblMessage.Text = "Service Started.";
}
catch (Exception ex)
{
//lblMessage.Text = "Error in Service Starting.";
lblMessage.Text = ex.ToString();
}
}
Bạn có chắc chắn rằng tài khoản người dùng có các quyền bắt buộc để bắt đầu dịch vụ không? Bạn có thể đăng bài theo dõi ngăn xếp không? –
Xem thêm tại đây: http://stackoverflow.com/questions/6070295/starting-a-service-in-asp-net-c-with-the-right-permissions –
Dấu vết ngăn xếp là System.InvalidOperationException: Không thể mở aspnet_state dịch vụ trên máy tính '.'. ---> System.ComponentModel.Win32Exception: Truy cập bị từ chối --- Kết thúc của dấu vết ngăn xếp ngoại lệ bên trong --- tại System.ServiceProcess.ServiceController.GetServiceHandle (Int32 mongAccess) tại System.ServiceProcess.ServiceController.Start (String [] args) tại System.ServiceProcess.ServiceController.Start() tại _Default.StartService (String serviceName, Int32 timeoutMilliseconds) – Mahesh