我想使用Windows命令提示符(而不是Visual Studio命令提示符)安装Windows服务。

我怎么做呢?


当前回答

1.从开始菜单中,选择Visual Studio目录,然后为VS选择开发人员命令提示符。

2.出现Visual Studio的开发人员命令提示符。

3.访问项目已编译的可执行文件所在的目录。

4.以项目的可执行文件作为参数,从命令提示符运行InstallUtil.exe

其他回答

在你的windows service exe文件旁边创建一个*.bat文件,使用以下上下文进行安装:

CLS
ECHO Installing My Windows Service 

START %windir%\Microsoft.NET\Framework\v4.0.30319\installutil.exe "%~d0%~p0\YourWindowsServiceExeName.exe"

在windows service exe文件旁边创建一个*.bat文件,使用以下上下文进行卸载:

CLS
ECHO Uninstalling My Windows Service 

START %windir%\Microsoft.NET\Framework\v4.0.30319\installutil.exe -u "%~d0%~p0\YourWindowsServiceExeName.exe"

以Admin身份运行每个bat文件来安装或卸载windows服务。

以管理员身份打开命令提示符,转到.exe所在的文件夹。 将Exe作为服务安装

D:\YourFolderName\YourExeName /i

卸载时使用“/u”。

请执行以下操作:

以管理员权限启动命令提示符(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/

安装服务:

"C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe" 
"C:\Services\myservice.exe"

卸载服务:-

"C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe" -u "C:\Services\myservice.Service.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