What is the difference between uninstall and uninstall in the context of a windows service?

Please help me understand the difference between uninstalling a Windows service using the "sc delete" command and uninstalling a Windows service using the "installutil / u" command.

After a little research, I understand that to use the installutil command, you need to stop the Windows service first, while the sc delete command takes care to stop the service. Please correct me if you are mistaken.

+3
uninstall windows-services
Apr 30 '13 at 6:09
source share
1 answer

A related SO question and answers (two in particular - here and here ) explain the difference, since basically sc delete does not require a reboot and installutil /u does. Other answers to a related question deserve attention for other differences.

(a bit) UPDATE:

As you point out in your revised question, yes, another significant difference is that the other answers to the related question emphasize that sc delete will take care of the first stop of the service that needs to be deleted.

(BIG) UPDATE:

I was not happy just to trust related questions and answers, without further confirming: it turns out that they are not quite correct - at least as far as my experiments install and uninstall services in Windows 7 Pro x64.

What I see is that in most cases you can use service uninstalls that go as described with each tool; but uninstalls with commands do not always follow these patterns.

There may be a little more, but the main determinants of behavior that I see are:

  • whether the service is running when it is deleted
  • Does a service perform a service (un) installer like System.Configuration.Install.Installer (A CodeProject article I found - and admittedly think I read it years ago - describes it well.)

Instead of a table for determining the conditions and results that I found, here is some pseudo code to explain:

 // pseudocode to explain the empirically observed logic of "sc delete" vs. // "installutil /u" (on Windows 7 Pro x64) // // services developed for the investigative experiment: // S[1-4]: simple Windows services that do *not* implement an // (un)installer // SWI[1-4]: simple Windows services that implement an (un)installer if serviceIsRunning { if "sc delete" { // Using: S1, SWI1 // Result: The service is not stopped but disabled and marked for deletion, requiring a reboot. } else // "installutil /u" { if serviceImplementsInstaller { // Using: SWI2 // Result: The service is stopped, disabled, and marked for deletion, requiring a reboot. } else { // Using: S2 // Result: The service is not stopped, disabled, or marked for deletion - still installed post-reboot. } } } else // serviceIsRunning == false { if "sc delete" { // Using: S3, SWI3 // Result: The service is deleted - no reboot required. } else // "installutil /u" { if serviceImplementsInstaller { // Using: SWI4 // Result: The service is deleted - no reboot required. } else { // Using: S4 // Result: The service is not disabled or marked for deletion - still installed post-reboot. } } } 

These results are consistent with sc delete own documentation:

 C:\Windows\system32>sc delete DESCRIPTION: Deletes a service entry from the registry. If the service is running, or another process has an open handle to the service, the service is simply marked for deletion. USAGE: sc <server> delete [service name] 

Same thing with installutil /u 's:

 C:\Windows\system32>installutil /u Microsoft (R) .NET Framework Installation utility Version 4.0.30319.1 Copyright (c) Microsoft Corporation. All rights reserved. Usage: InstallUtil [/u | /uninstall] [option [...]] assembly [[option [...]] assembly] [...]] InstallUtil executes the installers in each given assembly. If the /u or /uninstall switch is specified, it uninstalls the assemblies, otherwise it installs them. 

Note that when using installutil /u in a service that does not implement the installer (un), the following message appears in its output:

There are no public installers with the RunInstallerAttribute.Yes attribute.

+8
Apr 30 '13 at 6:29
source share



All Articles