We are going to use winsw to add a program called dosomething
to Windows service, and the program will be started automatically when the Windows is started(before a user logged in).
Suppose our working directory is D:\dosomething
, and our main program is D:\dosomething\dosomething
Prepare the winsw executable file
Download the winsw exe file called WinSW
, and put it into the working directory.
Create a confile file for winsw
Create a file winsw.xml
and put it into the working directory.
cat winsw.xml
<service>
<id>dosomething</id>
<name>dosomething</name>
<description>dosomething client</description>
<executable>dosomething</executable>
<arguments>-c dosomething.ini</arguments>
<logmode>reset</logmode>
</service>
Register the service
open CMD, and change directory into the working directory:
d:
cd dosomething
Register the service
WinSW.exe install winsw.xml
By now, the dosomething service is not started yet. We should start it manually in the service list.
Restart the Windows to test
Restart the Windows to see the dosomething
process and its tcp/udp port is started.