是什么删除&安培之间的差在卸载Windows服务的情况下? [英] What is the difference between deleting & uninstalling in the context of a Windows Service?

查看:256
本文介绍了是什么删除&安培之间的差在卸载Windows服务的情况下?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助我了解删除windows服务使用命令SC删除和卸载Windows服务使用命令之间的差别installutil / U。

探索一点点我知道后,对使用installutil命令,你必须先停止Windows服务,而SC delete命令采取停止服务本身的照顾。如有错误请指正。

解决方案

一个相关的SO 问题及答案(两个特别是 - 这里这里 )解释的差异主要在于 SC删除并不需要重新启动和 installutil / U 一样。其他答案的链接的问题是值得一试的其他差异了。

(小)更新:

正如你在修订问题指出,是的,另一个主要区别是其他的答案的链接的问题亮点在于资深大律师删除将采取先停止服务关怀被删除。​​

(BIG)更新:

我并不满足于单纯的信任没有进一步的验证链接的问题和答案:原来,他们是不完全正确的 - 至少就我的实验安装和在Windows 7专业版64位卸载服务。

我看到的是一个的可以的主要经验,服务将卸载该走与每个工具描述; ,但的卸载与命令并不总是遵循这些模式。

有可能会多一点,但命令的行为的主要限定词,我看到的是:

  • 无论是服务正在运行时,它卸载
  • 服务是否实现服务(UN)的安装程序的作为 System.Configuration.Install.Installer (A $ C $的CProject文章,我发现 - 诚然想我读几年前 - 描述了这口井)

在代替表概述的条件和结果我发现,这里是有点伪code解释:

  //伪code解释的经验观察逻辑SC删除与
//installutil / U(在Windows 7专业版64位)
//
//服务,为侦查实验开发:
// S [1-4]:简单的Windows服务,做*不*实施
//(UN)的安装程序
// SWI [1-4]:简单的Windows服务,实现一个(UN)的安装程序
如果serviceIsRunning
{
    如果资深大律师删除
    {
        //使用:S1,SWI1
        //结果:服务没有停止,但禁用,标记为删除,需要重新启动。
    }
    否则//installutil / U
    {
        如果serviceImplementsInstaller
        {
            //使用:SWI2
            //结果:该服务被停止,禁用,标记为删除,需要重新启动。
        }
        其他
        {
            //使用:S2
            //结果:服务没有停止,禁用或标记为删除 - 仍然安装后重新启动。
        }
    }
}
否则// serviceIsRunning ==假
{
    如果资深大律师删除
    {
        //使用:S3,SWI3
        //结果:该服务被删除 - 无需重启。
    }
    否则//installutil / U
    {
        如果serviceImplementsInstaller
        {
            //使用:SWI4
            //结果:该服务被删除 - 无需重启。
        }
        其他
        {
            //使用:S4
            //结果:该服务没有被禁用或标记为删除 - 仍然安装后重新启动。
        }
    }
}
 

这些结果与一致SC删除自己的文档:

  C:\ WINDOWS \ SYSTEM32> SC删除
描述:
        删除从注册表服务项。
        如果该服务正在运行,或者另一个进程有一个
        打开的句柄到服务,该服务只被标记为
        为删除。
用法:
        SC<服务器>删除[服务名称]
 

同样的, installutil / U 的:

  C:\ WINDOWS \ SYSTEM32> installutil / U
微软(R).NET Framework安装实用程序版本4.0.30319.1
版权所有(c)Microsoft公司。版权所有。

用法:InstallUtil [/ U | /卸载] [选项[...]]汇编[选项[...]]装配] [...]

InstallUtil执行每个给定程序的安装程序。
如果/ u或/卸载指定开关,它卸载
该组件,否则安装它们。
 

请注意,当您使用 installutil / U 在不实施(联合国)安装服务,出现在其输出以下消息:

  

没有公共的安装与RunInstallerAttribute.Yes属性可以找到

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 /u ".

After exploring a little bit I realize that for using the installutil command you have to first stop the windows service while sc delete command take care of stopping the service itself. Please correct me if wrong.

解决方案

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:

  • whether a service is running when it is uninstalled
  • whether a service implements a service (un)installer as a 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

这篇关于是什么删除&安培之间的差在卸载Windows服务的情况下?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆