首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用InstallUtil卸载不存在的服务

使用InstallUtil卸载不存在的服务
EN

Stack Overflow用户
提问于 2010-10-26 00:10:38
回答 3查看 10.4K关注 0票数 8

我使用服务的预构建事件和post构建事件卸载和安装服务。唯一的问题是,当另一个开发人员第一次使用预构建事件时,它会失败,因为服务尚未安装。

我当前卸载的预构建事件是

代码语言:javascript
运行
复制
%WinDir%\Microsoft.NET\Framework\v4.0.30319\InstallUtil /u $(TargetPath)

当服务已经安装时,我如何使用它只用于卸载?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2010-10-26 01:10:56

您可以使用Microsoft工具(Sc.exe)查询服务的状态,甚至可以创建或删除服务。下面是一篇关于使用此命令的文章:http://support.microsoft.com/kb/251192

从命令提示符窗口(为强调而编辑的内容):

代码语言:javascript
运行
复制
C:\windows\system32>sc
DESCRIPTION:
        SC is a command line program used for communicating with the
        Service Control Manager and services.
USAGE:
        sc <server> [command] [service name] <option1> <option2>...

       The option <server> has the form "\\ServerName"
       Further help on commands can be obtained by typing: "sc [command]"
       Commands:
         query-----------Queries the status for a service, or
                         enumerates the status for types of services.
         queryex---------Queries the extended status for a service, or
                         enumerates the status for types of services.
         start-----------Starts a service.
         pause-----------Sends a PAUSE control request to a service.
         continue--------Sends a CONTINUE control request to a service.
         stop------------Sends a STOP request to a service.
         delete----------Deletes a service (from the registry).
         create----------Creates a service. (adds it to the registry).

运行此命令查询(A)存在且(B)不存在的服务将导致:

(A)

代码语言:javascript
运行
复制
C:\Windows\System32>sc query W32Time

SERVICE_NAME: W32Time
        TYPE               : 20  WIN32_SHARE_PROCESS
        STATE              : 1  STOPPED
        WIN32_EXIT_CODE    : 1077  (0x435)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0

(B)

代码语言:javascript
运行
复制
C:\Windows\System32>sc query nothere
[SC] EnumQueryServicesStatus:OpenService FAILED 1060:

The specified service does not exist as an installed service.

因此,在尝试使用以下方法删除服务之前,您可以测试服务是否存在

代码语言:javascript
运行
复制
set svcname=W32Time
set svc=exists
for /f "delims=" %%o in ('sc query %svcname% ^| find "FAIL"') do set svc=notexists

if "%svc%"=="exists" sc delete %svcname%
票数 14
EN

Stack Overflow用户

发布于 2011-12-21 16:20:20

我正在使用Visual 2008构建一个服务,并且,和您一样,我希望它在我需要重新构建服务时为我重新安装它。

我的预建是

代码语言:javascript
运行
复制
net stop P2PSN.Bridge.Service
$(FrameworkDir)\installutil.exe /u $(TargetPath)
Exit /b 0

我的职位建设是

代码语言:javascript
运行
复制
$(FrameworkDir)\installutil.exe /ShowCallStack $(TargetPath)
net start P2PSN.Bridge.Service

“退出/b 0”意味着,即使没有安装服务,它也不会失败。类似地,如果您还没有构建该服务,它仍将工作。在第一次之后,这两个命令显然都会成功。

若要使此操作正常,必须使用提升的权限运行VISUAL STUDIO。

希望这能有所帮助。

票数 0
EN

Stack Overflow用户

发布于 2013-02-05 17:01:34

要构建的解决方案并将其与.net 4.0一起使用,预构建如下:

净停止yourServiceName

%WinDir%\Microsoft.NET\Framework\v4.0.30319\InstallUtil /u "$(TargetPath)“

出口/b 0

至于岗位建设:

%WinDir%\Microsoft.NET\Framework\v4.0.30319\InstallUtil /i "$(TargetPath)“

净启动yourServiceName

快速rem出口/b 0

遗憾的是,$(FrameworkDir)没有扩展到.net 4.0路径中

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4019795

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档