2013-01-07 588 views
11

C#コードを使用して、ウィンドウの開始と停止を行っていますが、このエラーが発生しています。System.ComponentModel.Win32Exception:アクセスが拒否されましたエラー

System.ComponentModel.Win32Exception: Access is denied 

私を助けてください。

マイコード:

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

サービスを開始するために必要な権限がユーザーアカウントに付与されていますか?スタックトレースを投稿できますか? –

+0

も参照してください:http://stackoverflow.com/questions/6070295/starting-a-service-in-asp-net-c-with-the-right-permissions –

+0

スタックトレースはSystem.InvalidOperationExceptionです:aspnet_stateを開くことができませんコンピュータ上のサービス '。' ---> System.ComponentModel.Win32Exception:アクセスが拒否されました---内部例外スタックトレースの終了--- System.ServiceProcess.ServiceController.Start(String [] args)のSystem.ServiceProcess.ServiceController.GetServiceHandle(Int32 desiredAccess) )System.ServiceProcess.ServiceController.Start()_Default.StartService(String serviceName、Int32 timeoutMilliseconds) – Mahesh

答えて

10

がサーバー上のアプリケーションプールIDアカウントがそのサービスを開始する権限を持っていることを確認してください。 既定のIIS構成では、このアカウントはネットワークサービスまたはApplicationPoolIdentity(IISバージョンによって異なる)であり、通常はサービスを管理できません。

したがって、IISマネージャー(アプリケーションプール/ NameOfYourYourPool /詳細設定)でプールアカウントを変更します。 組み込みのアカウントを使用することも、ドメインを使用することもできます。

apppool

3

管理者モードであなたのVSを実行し、それが動作するにdomainname \のusername.Hopeのようなコンピュータのドメイン名と管理者のmode.Give適切なユーザ名にcmdとVSあなたproject.Open開発者をロードします。

関連する問題