Windows service not showing up in installed services (and hence unable to start)

筅森魡賤 提交于 2020-02-01 07:28:26

问题


I just built a very simple Windows service to test something and built it to get the .exe. As per this article in MSDN, I also installed the service using the Visual Studio Command Prompt 2010 (ran as administrator) installutil TestService.exe.

When using the installutil command, everything runs fine and I get a message saying that the service has been installed. Further, to start the service when I check inside the Services node (in Server Explorer in Visual Studio), I do not see any service named TestService.exe.

Also, Start Menu -> My Computer (Right Click) -> Manage -> Services and Application -> Services does not show the TestService.exe through which I could start the service.

Any suggestions how do I start the service?

Code inside OnStart function:

Process[] testProcess = Process.GetProcessesByName("notepad.exe");
if (testProcess.Length == 0)
    File.WriteAllText(@"C:\Users\User1\Desktop\service.txt", "nothing");

else
    File.WriteAllText(@"C:\Users\User1\Desktop\service.txt", "run");

回答1:


I have had problems with installutil before and found using the sc command works whereas installutil didn't.

Try installing your service with this command:

sc create servicename binPath= serviceexe.exe



回答2:


I just had this issue and was able to resolve it with the following steps. If you skip these steps, your setup project will build and copy your files to the correct directory; however, they will not register your binary as a service without these steps.

  1. In Solution Explorer, right-click the setup project, point to View, then choose Custom Actions. The Custom Actions editor appears.

  2. In the Custom Actions editor, right-click the Custom Actions node and choose Add Custom Action. The Select Item in Project dialog box appears.

  3. Double-click the application folder in the list box to open it, select primary output from MyNewService (Active), and click OK. The primary output is added to all four nodes of the custom actions: Install, Commit, Rollback, and Uninstall.

  4. Build the setup project.




回答3:


While working in VS 2013, I ran into this issue when I added the installer by right clicking on the project and adding a new item of type Installer Class. The key difference is that you need to right click on the Design View of the Windows Service and click Add Installer.

For full details on .Net 4.5 and 4.6 see Creating a service, Adding Installers, and Installing a Service



来源:https://stackoverflow.com/questions/10716333/windows-service-not-showing-up-in-installed-services-and-hence-unable-to-start

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