Error 5 : Access Denied when starting windows service

前端 未结 30 2368
滥情空心
滥情空心 2020-12-04 18:49

I\'m getting this error when I try to start a windows service I\'ve created in C#:

\"alt

My Code

相关标签:
30条回答
  • 2020-12-04 19:28

    I got the solution:

    1. Go to local service window(where all services found)
    2. Just right click on your service name: 
    3. click on "properties" 
    4. go to "log on" tab
    5. select "local system account"
    6. click "ok"
    

    now you can try to start the service.

    0 讨论(0)
  • 2020-12-04 19:28

    I don't know if my answer would make sense to many, but I too faced the same issue and the solution was outrageously simple. All I had to do was to open the program which I used to run the code as an administrator. (right-click --> Run as Administrator).

    That was all.

    0 讨论(0)
  • 2020-12-04 19:29

    if you are a having an access denied error code 5. then probably in your code your service is trying to interact with some files in the system like writing to a log file

    open the services properties select log on tab and check option to allow service to interact with the desktop,

    0 讨论(0)
  • 2020-12-04 19:29

    Your code may be running in the security context of a user that is not allowed to start a service.

    Since you are using WCF, I am guessing that you are in the context of NETWORK SERVICE.

    see: http://support.microsoft.com/kb/256299

    0 讨论(0)
  • 2020-12-04 19:29

    For the error 5, i did the opposite to the solution above. "The first Error 5: Access Denied error was resolved by giving permissions to the output directory to the NETWORK SERVICE account."

    I changed mine to local account, instead of network service account, and because i was logged in as administrator it worked

    0 讨论(0)
  • 2020-12-04 19:29

    After banging my had against my desk for a few hours trying to figure this out, somehow my "Main" method got emptied of it's code!

    ServiceBase[] ServicesToRun;
    ServicesToRun = new ServiceBase[] 
    { 
        new DMTestService()
    };
    ServiceBase.Run(ServicesToRun);
    

    Other solutions I found:

    • Updating the .NET framework to 4.0
    • Making sure the service name inside the InitializeComponent() matches the installer service name property

      private void InitializeComponent()
      ...
      this.ServiceName = "DMTestService";
      
    • And a nice server restart doesn't hurt

    Szhlopp

    0 讨论(0)
提交回复
热议问题