Installing a self-developed Windows Service

梦想的初衷 提交于 2019-12-03 04:15:56
Matt Davis

I'm not sure what your specific problem is. It looks to me like the problem occurs while creating the EventLog source. Double-check that you've done that part correctly. You can reference the step-by-step here. EDIT: SPECIFICALLY LOOK AT STEP 9. The problem may be occuring because you're messing with the Application log instead of one specific to your application.

There's nothing wrong with using InstallUtil, but if you need to install your service on a foreign machine, InstallUtil is not guaranteed to be there. You can follow this step-by-step to make your Windows service executable install/uninstall itself without the need of InstallUtil. See here for those instructions.

I was just having this issue and it was because I wasn't running my visual studio command prompt as an administrator.

To solve this issue right click on your Visual Studio 2008 Command Prompt and click run as administrator then you run your command like installutil C:\mcWebService\bin\Debug\mcWebService.exe then it will show you successful message. Hope this will solve your solution.

The LocalSystem account doesn't normally have permission to read the Security event log (or to create event sources for that matter).

The easiest and safest solution is to create an event source installation program that you can run under your own administration-level credentials on any machine for which you'll want to run this. It might be even worth trying this as a simple test, just to see if your account has the permission to do this.

class Program {
    static void Main(string[] args) {
        EventLog.CreateEventSource("TestSource", "Application");
    }
}

If you execute that, does it succeed? You can check it by looking at the Application log's properties and browsing the Event sources on its Filter tab.

Alternately, since services have to be installed anyway, you could add an EventLogInstaller (which is misnamed - it's really an 'EventSourceInstaller' that will create EventLogs as needed) to the assembly instead of using EventLog.CreateEventSource in the service's constructor.

My issue was a window was popping to enter credentials and I was entering my username without the domain. Once I entered domain\username all was fine.

I got the same unexplainable errors when installing windows services. In our case the user was the problem.

Installing the server with the administrator-user worked, but not for a local admin. This, however, is not a preferred solution, so we used this information to create a different user that could install the service.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!