1. Create a Windows Service project
Project Name: Servicedemo
2. Add load start and unload service scripts
Load and start batch processing:
1 @echo off2 if exist"%systemroot%/microsoft.net/framework/v4.0.30319"GotoInstall3 EchoPlease install.NetFramework v4.0 first.4 Pause5 Goto End6 : Install7%systemroot%/microsoft.NET/framework/v4.0.30319/installutil "ServiceDemo.exe"8 Net Start"ServiceDemo.exe"9 PauseTen : End
To uninstall a batch process:
1 @echo off2 if exist"%systemroot%/microsoft.net/framework/v4.0.30319"GotoUninstall3 EchoPlease install.NetFramework v4.0 first.4 Pause5 Goto End6 : Uninstall7%systemroot%/microsoft.NET/framework/v4.0.30319/installutil/uninstall "ServiceDemo.exe"8 Pause9 : End
3. Here's the problem.
The service was loaded successfully but did not start successfully.
4. Analysis
From the first diagram you can see that the service is Service1, so change the load script to:
1 @echo off2 if exist"%systemroot%/microsoft.net/framework/v4.0.30319"GotoInstall3 EchoPlease install.NetFramework v4.0 first.4 Pause5 Goto End6 : Install7%systemroot%/microsoft.NET/framework/v4.0.30319/installutil "ServiceDemo.exe"8 Net StartService19 PauseTen : End
Successfully started:
Windows services cannot start with scripts