赞
踩
本文翻译自: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? 我该怎么做呢?
参考:https://stackoom.com/question/YG3H/使用Windows命令提示符安装Windows服务吗
Perform the following: 执行以下操作:
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]
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/
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"
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"
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
cd C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\
to go to folder 粘贴此代码: cd C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\
转到文件夹 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
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。