windows服务用脚本无法启动

1.创建windows服务工程

工程名:ServiceDemo

2.添加加载启动及卸载服务脚本

加载及启动批处理:

 1 @echo off
 2 if exist "%SystemRoot%/Microsoft.NET/Framework/v4.0.30319" goto install
 3 echo Please install .net framework v4.0 first.
 4 pause
 5 goto end
 6 :install
 7 %SystemRoot%/Microsoft.NET/Framework/v4.0.30319/installutil "ServiceDemo.exe"
 8 net start "ServiceDemo.exe"
 9 pause
10 :end

卸载批处理:

1 @echo off
2 if exist "%SystemRoot%/Microsoft.NET/Framework/v4.0.30319" goto uninstall
3 echo Please install .net framework v4.0 first.
4 pause
5 goto end
6 :uninstall
7 %SystemRoot%/Microsoft.NET/Framework/v4.0.30319/installutil /uninstall "ServiceDemo.exe"
8 pause
9 :end

3.问题来了

服务已装载成功,但未启动成功。

4.分析

从第一张图可以看出服务为Service1,所以将加载脚本改为:

 1 @echo off
 2 if exist "%SystemRoot%/Microsoft.NET/Framework/v4.0.30319" goto install
 3 echo Please install .net framework v4.0 first.
 4 pause
 5 goto end
 6 :install
 7 %SystemRoot%/Microsoft.NET/Framework/v4.0.30319/installutil "ServiceDemo.exe"
 8 net start Service1
 9 pause
10 :end

成功启动:

 

posted @ 2016-11-30 16:10  王小六Charles  阅读(1400)  评论(0编辑  收藏  举报