Error 1001: The specified service already exists. Unable to delete existing service

I have a service. I installed it a while ago. I need to do an update for the service. I went to "Add or Remove Programs" and looked for my service, and it is not installed there. I looked at services.msc, and he stopped there. I was able to start it and stop it. I ran the command line as administrator and ran sc delete [Service Name] and got "The specified service does not exist as the installed service." I made a sc request on the command line and it does not return. I right-click on the installer, clicked on the uninstall and got "This action only applies to products that are currently installed." I also tried the repair and received the same message.

I restarted the machine several times and you will not be able to remove this service. I am using the basic installation project template installed in Visual Studio. I tried to change the name of the program and increase the version number.

How to delete an existing service and prevent it in the future?

+8
c # windows visual-studio-2008 windows-services
source share
6 answers

If you have a .exe that includes a service installer, use InstallUtil.exe /u <process.exe> InstallUtil.exe is located in \Windows\Microsoft.Net\Framework\v4.0.30319

In the installation project, include the service in all user actions, as well as uninstall

(right click on the project, custom action)

Hth

Mario

+6
source share

It’s normal that the service is not listed in the Add or Remove Programs section, this is a list for software packages, not services. (A single package or program may contain several services, but it usually does not install them.)

Apparently, the service was installed manually, and not as part of the product, even if this one, in particular, will usually be installed with a product that has an installation package.

Using sc delete correct. You will need to specify the (short) name of the service in double quotes (unless it is just one word), but nothing else.

Otherwise, visit HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services in your registry, both 32-bit and 64-bit ( regedt32.exe and regedit.exe , respectively). You can even delete the service there directly, but you obviously should start with reversible changes to diagnose how your service is exactly named, and why sc does not see its name and uses only direct registry access after everything else has failed and after that, I created a backup copy of the registry (follow this procedure, specifying the operating system).

+3
source share

** If you need to perform only the configuration, follow these steps:

This can be done by explicitly implementing an existing service uninstall (uninstall), and then to install a newer version. To do this, we need to update ProjectInstaller.Designer.cs, as shown below:

Consider adding the following line at the beginning of InitializeComponent (), which fires an event to delete an existing service before your current installer tries to install the service again. Here we delete the service if it already exists.

Add the following namespaces:

 using System.Collections.Generic; using System.ServiceProcess; 

Add the line of code below as described above:

 this.BeforeInstall += new System.Configuration.Install.InstallEventHandler(ProjectInstaller_BeforeInstall); 

Example:

 private void InitializeComponent() { this.BeforeInstall += new System.Configuration.Install.InstallEventHandler(ProjectInstaller_BeforeInstall); this.serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller(); this.serviceInstaller1 = new System.ServiceProcess.ServiceInstaller(); // // serviceProcessInstaller1 // this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem; this.serviceProcessInstaller1.Password = null; this.serviceProcessInstaller1.Username = null; // // serviceInstaller1 // this.serviceInstaller1.Description = "This is my service name description"; this.serviceInstaller1.ServiceName = "MyServiceName"; this.serviceInstaller1.StartType = System.ServiceProcess.ServiceStartMode.Automatic; // // ProjectInstaller // this.Installers.AddRange(new System.Configuration.Install.Installer[]{ this.serviceProcessInstaller1, this.serviceInstaller1 } ); } 

The following code raised by the event will then delete the service, if one exists.

 void ProjectInstaller_BeforeInstall(object sender, System.Configuration.Install.InstallEventArgs e) { List<ServiceController> services = new List<ServiceController>(ServiceController.GetServices()); foreach (ServiceController s in services) { if (s.ServiceName == this.serviceInstaller1.ServiceName) { ServiceInstaller ServiceInstallerObj = new ServiceInstaller(); ServiceInstallerObj.Context = new System.Configuration.Install.InstallContext(); ServiceInstallerObj.Context = Context; ServiceInstallerObj.ServiceName = "MyServiceName"; ServiceInstallerObj.Uninstall(null); break; } } } 

PS: Along with the above changes, please consider updating the Version, ProductCode (and optional UpgradeCode) code for good practice, better version control, tracking, and maintenance

+3
source share

The same thing happened to me today. The only solution was to restore the installation file from the Add or Remove Windows tool. After restoring the installation file, delete it and install again.

+1
source share

Have you tried looking in the Windows registry for any garbage related to this service?

You should look in this folder: HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \

0
source share

Just in case, someone is faced with this problem:

What worked for me is updating my installer's name, version and ProductCode. In any case, you should definitely stick to good versioning practices.

0
source share

All Articles