我想使用Windows命令提示符(而不是Visual Studio命令提示符)安装Windows服务。
我怎么做呢?
我想使用Windows命令提示符(而不是Visual Studio命令提示符)安装Windows服务。
我怎么做呢?
当前回答
如果目录名有空格,如c:\program files\abc 123,则必须在路径周围使用双引号。
installutil.exe "c:\program files\abc 123\myservice.exe"
如果你像下面这样设置一个bat文件,事情就会简单得多,
例如,要安装一个服务,创建一个“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
要卸载服务,
只需在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"
其他回答
以管理员身份运行Windows命令提示符 cd C:\Windows\Microsoft.NET\Framework\v4.0.30319\到文件夹 installutil C:\ProjectFolder\bin\Debug\MyProject.exe
卸载方法:installutil /u C:\ProjectFolder\bin\Debug\MyProject.exe
请执行以下操作:
以管理员权限启动命令提示符(CMD)。 输入c:\windows\microsoft.net\framework\v4.0.30319\installutil.exe[你的windows服务路径到exe] 按回车键,就是这样!
使用管理员权限打开是很重要的,否则您可能会发现出现一些毫无意义的错误。如果你得到任何,检查你已经打开它与管理权限第一!
要以管理员权限打开,右键单击“命令提示符”并选择“以管理员身份运行”。
来源: http://coderamblings.wordpress.com/2012/07/24/how-to-install-a-windows-service-using-the-command-prompt/
如果你正在使用Powershell并且你想要安装。net服务,你可以使用install - service模块。它是InstalUtil工具的包装器。
它公开了3个命令
Install-Service -调用InstallUtil.exe pathToExecutable命令 Install-ServiceIfNotInstalled -首先检查服务是否存在 如果不执行Install-Service方法,则安装 Uninstall-Service-它卸载服务。可执行文件路径的ServiceName可以使用。
这个模块的代码可以在这里查看
当您的程序集版本和您的Visual studio项目在dot net 2或4上的biild设置安装相同的版本时。
使用installutil安装相同版本的service
如内置点网4个
输入c: \ windows \ microsoft.net \ framework \ v4.0.30319 \ installutil.exe
如内置点网2
输入c: \ windows \ microsoft.net \ framework \ v2.0.11319 \ installutil.exe
以管理员权限启动命令提示符(CMD)。 输入c:\windows\microsoft.net\framework\v4.0.30319\installutil.exe[你的windows服务路径到exe] 按return键