阅读 136

microsoft 如何:安装和卸载 Windows 服务

如何:安装和卸载 Windows 服务

					

					
						

如果正使用 .NET Framework 开发 Windows 服务,可以使用 InstallUtil.exe 命令行实用工具或 PowerShell 快速安装服务应用。If you‘re developing a Windows service with the .NET Framework, you can quickly install your service app by using the InstallUtil.exe command-line utility or PowerShell. 如果开发人员希望发布用户可安装和卸载的 Windows 服务,则可以使用免费的 WiX 工具集高级安装程序InstallShield 等其他商业工具。Developers who want to release a Windows service that users can install and uninstall can use the free WiX Toolset or commercial tools like Advanced Installer, InstallShield, or others. 有关详细信息,请参阅创建安装程序包(Windows 桌面)For more information, see Create an installer package (Windows desktop).

警告

如果要从计算机中卸载服务,请勿按照本文中的步骤进行操作。If you want to uninstall a service from your computer, don‘t follow the steps in this article. 而是找出安装了该服务的程序或软件包,然后在“设置”中选择“应用”来卸载该程序。Instead, find out which program or software package installed the service, and then choose Apps in Settings to uninstall that program. 请注意,许多服务是 Windows 不可或缺的部分;如果你删除它们,可能导致系统不稳定。Note that many services are integral parts of Windows; if you remove them, you might cause system instability.

要使用本文中的步骤,首先需要将服务安装程序添加到 Windows 服务。To use the steps in this article, you first need to add a service installer to your Windows service. 有关详细信息,请参见。For more information, see .

无法通过按 F5 从 Visual Studio 开发环境直接运行 Windows 服务项目。You can‘t run Windows service projects directly from the Visual Studio development environment by pressing F5. 必须先在项目中安装服务,然后才能运行该项目。Before you can run the project, you must install the service in the project.

提示

可以使用“服务器资源管理器”验证是否已安装或卸载服务。You can use Server Explorer to verify that you‘ve installed or uninstalled your service.

使用 InstallUtil.exe 实用程序安装Install using InstallUtil.exe utility

  1. 从“开始”菜单中选择“Visual Studio <version>”目录,然后选择“VS <version> 开发人员命令提示” 。From the Start menu, select the Visual Studio <version> directory, then select Developer Command Prompt for VS <version>.

    出现“Visual Studio 开发人员命令提示”。The Developer Command Prompt for Visual Studio appears.

  2. 访问你的项目的已编译可执行文件所在的目录。Access the directory where your project‘s compiled executable file is located.

  3. 将项目的可执行文件作为参数,通过命令提示运行 InstallUtil.exe:Run InstallUtil.exe from the command prompt with your project‘s executable as a parameter:

    控制台
    installutil .exe
    

    如果使用的是 Visual Studio 开发人员命令提示,InstallUtil.exe 应该在系统路径上。If you’re using the Developer Command Prompt for Visual Studio, InstallUtil.exe should be on the system path. 如果不在,可以将其添加到该路径,或使用完全限定的路径来调用它。Otherwise, you can add it to the path, or use the fully qualified path to invoke it. 此工具随 .NET Framework 安装在 %WINDIR%\Microsoft.NET\Framework[64]\ 中。This tool is installed with the .NET Framework in %WINDIR%\Microsoft.NET\Framework[64]\.

    例如:For example:

    • 对于 32 位版的 .NET Framework 4 或 4.5 以及更高版本,如果 Windows 安装目录是 C: \ Windows,则默认路径是 C:\Windows\ Microsoft.NET \ Framework \ v4.0.30319 \ InstallUtil.exe 。For the 32-bit version of the .NET Framework 4 or 4.5 and later, if your Windows installation directory is C:\Windows, the default path is C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe.
    • 对于 64 位版的 .NET Framework 4 或 4.5 以及更高版本,默认路径是 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe。For the 64-bit version of the .NET Framework 4 or 4.5 and later, the default path is C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe.

使用 InstallUtil.exe 实用程序卸载Uninstall using InstallUtil.exe utility

  1. 从“开始”菜单中选择“Visual Studio <version>”目录,然后选择“VS <version> 开发人员命令提示” 。From the Start menu, select the Visual Studio <version> directory, then select Developer Command Prompt for VS <version>.

    出现“Visual Studio 开发人员命令提示”。The Developer Command Prompt for Visual Studio appears.

  2. 将项目的输出作为参数,通过命令提示运行 InstallUtil.exe:Run InstallUtil.exe from the command prompt with your project‘s output as a parameter:

    控制台
    installutil /u .exe
    
  3. 删除服务的可执行文件后,该服务可能仍然会出现在注册表中。After the executable for a service is deleted, the service might still be present in the registry. 如果发生这种情况下,请使用命令 从注册表中删除服务的条目。If that‘s the case, use the command to remove the entry for the service from the registry.

使用 PowerShell 安装Install using PowerShell

  1. 从“开始”菜单中,选择“Windows PowerShell”目录,然后选择“Windows PowerShell”。From the Start menu, select the Windows PowerShell directory, then select Windows PowerShell.

  2. 访问你的项目的已编译可执行文件所在的目录。Access the directory where your project‘s compiled executable file is located.

  3. 运行 cmdlet,并将项目的输出和服务名称作为参数:Run the cmdlet with the with your project‘s output and a service name as parameters:

    PowerShell
    .exe
    ">New-Service -Name "YourServiceName" -BinaryPathName .exe
    

使用 PowerShell 卸载Uninstall using PowerShell

  1. 从“开始”菜单中,选择“Windows PowerShell”目录,然后选择“Windows PowerShell”。From the Start menu, select the Windows PowerShell directory, then select Windows PowerShell.

  2. 运行 cmdlet,并将服务名称作为参数:Run the cmdlet with the name of your service as parameter:

    PowerShell
    Remove-Service -Name "YourServiceName"
    
  3. 删除服务的可执行文件后,该服务可能仍然会出现在注册表中。After the executable for a service is deleted, the service might still be present in the registry. 如果发生这种情况下,请使用命令 从注册表中删除服务的条目。If that‘s the case, use the command to remove the entry for the service from the registry.

    PowerShell
    sc.exe delete "YourServiceName"
    

请参阅See also

					

					

原文:https://www.cnblogs.com/sunny3158/p/14598728.html

文章分类
代码人生
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐