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

前端 未结 10 1695
离开以前
离开以前 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.

    0 讨论(0)
  • 2020-12-03 02:44

    Run it from Task Scheduler with highest privileges and it will work.

    0 讨论(0)
  • 2020-12-03 02:45

    A user account with administrator rights will prompt “are you sure?” in situations where the administrator account is not prompted. I had this problem with net stop netprofm.

    To remove the prompt do this.

    Control Panel, User Accounts, Change User Account Control settings, never notify

    This seems to provide the user account with admin rights the same behavior as a the administrator account.

    0 讨论(0)
  • 2020-12-03 02:53

    I had the same problem because my project and its source code was in a folder that had NTFS's Encrypting File System (EFS) enabled. This caused by compiled assemblies being encrypted aswell and the user running my service didn't have permissions to decrypt them. Removing EFS was the easy solution for this. It can be done by command line using CIPHER.EXE, which is a Windows tool.

    0 讨论(0)
  • 2020-12-03 02:54

    Had the same issue.

    Fixed by running the service under "Local System Account"

    enter image description here

    0 讨论(0)
  • 2020-12-03 02:55

    Just ran into this issue after I had run an 'sc config' to change binPath of the service.

    The only fix that worked for me was to 'sc delete' the service and install again.

    Things worked perfectly after that.

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