C++服务程序出现 could not delete service

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u011512808/article/details/79233945

开发环境: Vs2013

OS 名称:          Microsoft Windows 10 专业版
OS 版本:          10.0.14393 暂缺 Build 14393
OS 制造商:        Microsoft Corporation
OS 配置:          独立工作站
OS 构件类型:      Multiprocessor Free

预先生成事件  "$(SolutionDir)$(Configuration)\UnInstall.bat"

cd /d %~dp0


REM 将引号内部分改成你要查找的服务名称  
sc query |find /i "BackUpServer" >nul 2>nul  
REM 如果服务存在,跳转至exist标签  
if not errorlevel 1 (goto exist) else goto notexist  
  
:exist  
REM 这里写服务存在时用的代码  
echo exist BackUpServer server 
net Stop BackUpServer

ping -n 3 127.0.0.1>nul

sc delete BackUpServer 
goto :end  
  
:notexist  
REM 这里写服务不存在时用的代码  
echo not exist BackUpServer server  
  
goto :end  
  
:end 




"$(SolutionDir)$(Configuration)\Install.bat"

cd /d %~dp0
REM 注册系统服务,如果 services.msc 有弹窗没有关掉,就会提示 could not delete service,最后还要关闭 
services.msc重新编译
BackUpServer.exe /Service ping -n 3 127.0.0.1>nulREM 启动服务net start BackUpServer
 
 


猜你喜欢

转载自blog.csdn.net/u011512808/article/details/79233945