使用Windows命令提示符安装Windows服务吗?

本文详细介绍了如何使用Windows命令提示符(CMD)而非Visual Studio命令提示符来安装Windows服务。关键步骤包括以管理员权限启动CMD,定位到.NET Framework目录,并使用installutil.exe工具指定服务的EXE文件路径进行安装。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文翻译自:Install a Windows service using a Windows command prompt?

I want to install a Windows service using a Windows command prompt (not the Visual Studio command prompt). 我想使用Windows命令提示符(而不是Visual Studio命令提示符)安装Windows服务。

How do I do this? 我该怎么做呢?


#1楼

参考:https://stackoom.com/question/YG3H/使用Windows命令提示符安装Windows服务吗


#2楼

Perform the following: 执行以下操作:

  1. Start up the command prompt (CMD) with administrator rights. 以管理员权限启动命令提示符(CMD)。
  2. Type c:\\windows\\microsoft.net\\framework\\v4.0.30319\\installutil.exe [your windows service path to exe] 键入c:\\windows\\microsoft.net\\framework\\v4.0.30319\\installutil.exe [your windows service path to exe]
  3. Press return and that's that! 回车键 ,就是这样!

It's important to open with administrator rights otherwise you may find errors that come up that don't make sense. 以管理员权限打开很重要,否则您可能会发现没有道理的错误。 If you get any, check you've opened it with admin rights first! 如果有,请先检查您是否已使用管理员权限打开它!

To open with admin rights , right click 'Command Prompt' and select 'Run as administrator'. 要以管理员权限打开 ,请右键单击“命令提示符”,然后选择“以管理员身份运行”。

Source: http://coderamblings.wordpress.com/2012/07/24/how-to-install-a-windows-service-using-the-command-prompt/ 来源: http : //coderamblings.wordpress.com/2012/07/24/how-to-install-a-windows-service-using-the-command-prompt/


#3楼

If the directory's name has a space like c:\\program files\\abc 123 , then you must use double quotes around the path. 如果目录名称的空格类似c:\\program files\\abc 123 ,则必须在路径周围使用双引号。

installutil.exe "c:\program files\abc 123\myservice.exe"

从命令提示符安装Windows服务

It makes things much easier if you set up a bat file like following, 如果您设置bat文件(例如,

eg To install a service, create a "myserviceinstaller.bat" and " Run as Administrator " 例如,要安装服务,请创建“ myserviceinstaller.bat”和“ 以管理员身份运行

@echo off
cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
installutil.exe "C:\Services\myservice.exe"

if ERRORLEVEL 1 goto error
exit
:error
echo There was a problem
pause

to uninstall service, 卸载服务,

Just add a -u to the installutil command. 只需在installutil命令中添加-u即可。

cd C:\Windows\Microsoft.NET\Framework\v4.0.30319

C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil.exe -u "C:\Services\myservice.exe"

#4楼

when your assembly version and your Visual studio project Biuld setting on dot net 2 or 4 install with same version. 当您的程序集版本和Visual Studio项目在点网2或4上的Biuld设置安装为相同版本时。

install service with installutil that same version 使用相同版本的installutil安装服务

if build in dot net 4 如果内置于点网4

Type c:\\windows\\microsoft.net\\framework\\v4.0.30319\\installutil.exe 键入c:\\windows\\microsoft.net\\framework\\v4.0.30319\\installutil.exe

if build in dot net 2 如果内置点网2

Type c:\\windows\\microsoft.net\\framework\\v2.0.11319\\installutil.exe 键入c:\\windows\\microsoft.net\\framework\\v2.0.11319\\installutil.exe


#5楼

  1. start up the command prompt (CMD) with administrator rights. 以管理员权限启动命令提示符(CMD)。
  2. Type c:\\windows\\microsoft.net\\framework\\v4.0.30319\\installutil.exe [your windows service path to exe] 键入c:\\ windows \\ microsoft.net \\ framework \\ v4.0.30319 \\ installutil.exe [您的exe的Windows服务路径]
  3. Press return 按回车

#6楼

  1. Run Windows Command Prompt as Administrator 管理员身份运行Windows命令提示符
  2. paste this code: cd C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\ to go to folder 粘贴此代码: cd C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\转到文件夹
  3. edit and run this too: installutil C:\\ProjectFolder\\bin\\Debug\\MyProject.exe 也编辑并运行: installutil C:\\ProjectFolder\\bin\\Debug\\MyProject.exe

Note: To uninstall: installutil /u C:\\ProjectFolder\\bin\\Debug\\MyProject.exe 注意:要卸载: installutil /u C:\\ProjectFolder\\bin\\Debug\\MyProject.exe

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值