我想使用Windows命令提示符(而不是Visual Studio命令提示符)安装Windows服务。
我怎么做呢?
我想使用Windows命令提示符(而不是Visual Studio命令提示符)安装Windows服务。
我怎么做呢?
当前回答
您可以使用命令提示符并写入: C:\windows\microsoft.net\framework\v4.0.30319\InstallUtil.exe -i " windows服务的exe文件"
其他回答
以下代码,安装和卸载服务,
打开命令提示符,以管理员身份运行程序,输入以下命令并按enter。
语法
安装
C:\windows\microsoft.net\framework\v4.0.30319>InstallUtil.exe + Your copied path + \your service name + .exe
我们的道路 InstallUtil.exe C: \ MyFirstService \ bin \ \ MyFirstService.exe调试
要卸载
C:\windows\microsoft.net\framework\v4.0.30319>InstallUtil.exe -u + Your copied path + \your service name + .exe
例如:我们的路径InstallUtil.exe -u C:\MyFirstService\bin\Debug\MyFirstService.exe
要获得更多帮助,您可以查看以下链接:示例程序
以管理员权限启动命令提示符(CMD)。 输入c:\windows\microsoft.net\framework\v4.0.30319\installutil.exe[你的windows服务路径到exe] 按return键
在你的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服务。
以管理员身份运行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
如果目录名有空格,如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"