Error 5 : Access Denied when starting windows service

前端 未结 30 2367
滥情空心
滥情空心 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:22

    I had windows service hosted using OWIN and TopShelf. I was not able to start it. Same error - "Access denied 5"

    I ended up giving all the perms to my bin/Debug.

    The issue was still not resolved.

    So I had a look in the event logs and it turned out that the Microsoft.Owin.Host.HttpListener was not included in the class library containing the OWIN start up class.

    So, please make sure you check the event log to identify the root cause before beginning to get into perms, etc.

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

    This worked for me.

    1. Right-click on top-level folder containing the service executable. Go to Properties
    2. Go to "Security" Tab
    3. Click "EDIT"
    4. Click "ADD"
    5. Enter the name "SYSTEM", click OK
    6. Highlight SYSTEM user, and click ALLOW check-box next to "Full control"
    7. Click OK twice
    0 讨论(0)
  • 2020-12-04 19:25

    This error happens when there is a error in your OnStart method. You cannot open a host directly in OnStart method because it will not actually open when it is called, but instead it will wait for the control. So you have to use a thread. This is my example.

    public partial class Service1 : ServiceBase
    {
        ServiceHost host;
        Thread hostThread;
        public Service1()
        {
            InitializeComponent();
             hostThread= new Thread(new ThreadStart(StartHosting));
    
        }
    
        protected override void OnStart(string[] args)
        {
            hostThread.Start();
        }
    
        protected void StartHosting()
        {
            host = new ServiceHost(typeof(WCFAuth.Service.AuthService));
            host.Open();
        }
    
        protected override void OnStop()
        {
            if (host != null)
                host.Close();
        }
    }
    
    0 讨论(0)
  • 2020-12-04 19:26

    I have monitored sppsvc.exe using process monitor and found out that it was trying to write to the HKEY_LOCAL_MACHINE\SYSTEM\WPA key. After giving permissions to NETWORK SERVICE on this key, I was able to start the service and Windows suddenly recognized that it was activated again.

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

    I had this issue today on a service that I was developing, and none of the other suggestions on this question worked. In my case, I had a missing .dll dependency in the folder where the service ran from.

    When I added the dependencies, the issue went away.

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

    In may case system run out of free space on local disk.

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