System error 5 Access is denied when starting a .NET service

前端 未结 10 1799
离开以前
离开以前 2020-12-03 02:32

When I try to start a service I created in Visual Studio I receive the following error:

System error 5 has occurred.

Access is denied.

I a

10条回答
  •  死守一世寂寞
    2020-12-03 02:44

    I see you've fixed the problem; but in reality, you shouldn't normally be running the service from a project's bin folder anyway - the files should be put somewhere project and profile independent (for example, under program files). For debugging purposes (when it will be in the bin folder), you can detect whether it is a service in Main(), and if it is being run interactively just run the service code directly, rather than the usual service-start setup.

    You can detect either by adding a command line argument, or you can try checking Environment.UserInteractive.

提交回复
热议问题