Please help me understand the difference between deleting a windows service with the command \"sc delete \" and uninstalling a windows service with the command \"installutil
A related SO question and answers (two in particular - here and here) explain the difference as mostly being that sc delete
does not require a reboot and installutil /u
does. Other answers to the linked question are worth checking out for other differences too.
(Little) UPDATE:
As you point out in your revised question, yes, another major difference that other answers to the linked question highlight is that sc delete
will take care of first stopping the service to be deleted.
(BIG) UPDATE:
I wasn't content to simply trust the linked question and answers without verifying further: it turns out that they are not quite right - at least as far as my experiments installing and uninstalling services on Windows 7 Pro x64.
What I see is that one can largely experience service uninstalls that go as described with each tool; but uninstalls with the commands do not always follow these patterns.
There may be a bit more to it, but the main determiners of the commands' behaviors that I see are:
System.Configuration.Install.Installer
(A CodeProject article I found - and admittedly think I read years ago - describes this well.)In lieu of a table to outline the conditions and outcomes I found, here is a bit of pseudocode 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
's 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 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 you use installutil /u
on a service that does not implement an (un)installer, the following message appears in its output:
No public installers with the RunInstallerAttribute.Yes attribute could be found