开发者

Installing windows service fails: service already exists

开发者 https://www.devze.com 2023-04-07 18:56 出处:网络
I\'m trying to reinstall a service I\'ve written using C#. The first time this worked. I used installutil to handle the install and the service showed up in the list of services and I could start it.

I'm trying to reinstall a service I've written using C#. The first time this worked. I used installutil to handle the install and the service showed up in the list of services and I could start it. Then I made some updates to the code and uninstalled the service. After figuring out I had to close the services window, the service seemed to have disappeared (i.e. successfully uninstalled). However, upon trying to install the service again I got the message saying:

System.ComponentModel.Win32Exception: The specified service already exists

This seemed strange as I couldn't see it in the services window. I finally thought I found the problem after deleting a registry key regarding my service, but unfortunately this didn't solve anything.

Also, uninstalling again doesn't do much to solve the problem as this results in the contradictory message:

System.ComponentMode开发者_JS百科l.Win32Exception: The specified service does not exist as an installed service

What should I believe? Does or doesn't the service exists? I feel like a physicist trying to figure out whether the cat is dead or alive. I hope someone here knows something to help solve this problem.


A related SO-answer finally pointed me in the right direction (why I didn't find that in Google or SO's own search I don't know). Anyway, apparently the Designer.cs generated by Visual Studio also creates a process- and service-installer. Which of course install services with the same name as my manually created installers. Removing my own installers solved the problem.


Actual issue is that you have added the object of serviceProcessInstaller & serviceInstaller multiple times in your code .. It should only be added once..

Open the designer.cs file of projectinstaller you will see it is already added there...


I was also getting the same error, so to resolve, what I did was:

  • Open the ProjectInstaller.cs from solution Explorer
  • Go into view designer mode by right clicking, if code view is there

You will see a new installer apart from defaults 2, i.e. serviceprocessInstaller1 and ServiceInstaller1.

Just remove that installer which was automatically generated. Now build and install, it will work.


Check the Service Name Property in Service Installer.


I have tried all solution mentioned above. But my service was installed with some different name in registry. So just try to delete that registry.

Open below link in registry

Hkey_Local_Macine>System>CurrentControlSet>Service>

But I didnt find my service under this path. So I tried to find it out in registry. Just press ctrl + F and give the name of your service. or some guess name. You will get the exact location.

Just delete it. It will work.


Need to remove "Me.Installers.AddRange(New System.Configuration.Install.Installer() {Me.ServiceInstaller1, Me.ServiceProcessInstaller1})" line if same line is there already in designer, then it will get installed.

ServiceProcessInstaller1 is name in my project.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号