Introduction
I developed XYNTService eight years ago. It turns out to be my most widely used program. Funny thing is, more than once I found third party programs modified from XYNTService
running on my own computers.
Here I am presenting a .NET 2.0 version of XYNTService
for XP and VISTA. It is a simplified version, some features in the original version are dropped. For example, if you use the new version to run a program with a user interface, you won't be able to see it on your desktop. This is because VISTA and some versions of XP have tighter security for services: all services are running in a separate/isolated session, therefore you won't be able to see any window created by a service program.
XYWinService
This is a .NET 2.0 Windows service written for XP and VISTA. The only purpose of XYWinService
is to run other programs. The programs you want to run by XYWinService
are defined in an XML configuration file. All programs run by XYWinService
behave like a Windows service:
- The programs will be started one by one when
XYWinService
starts.
- The programs will be run under the same account that runs
XYWinService
.
- The programs will be stopped in reverse order when
XYWinService
stops.
To install and start this service, you need to:
- Copy XYWinService.exe and XYWinService.xml into a folder on the target machine.
- Modify XYWinService.xml file to define your programs.
- Run command "
xywinservice.exe -i
" to install the service.
- Run command "
xywinservice.exe -r
" to start the service. You can also start the service by rebooting the machine.
To stop this service, run command " xywinservice.exe -k
". To uninstall this service, run command " xywinservice.exe -u
".
Note for VISTA
You may have problems installing and running XYWinService
on VISTA. This is because UAC is enabled, even if you are logged on as admin, you don't have the proper privilege to install the service. In fact, the above commands won't work while UAC is enabled.
Disable UAC
You can disable UAC temporarily. To disable UAC, double click the included DisableUAC.reg file then reboot the machine. After installing XYWinService
, you can re-enable UAC by double clicking the included EnableUAC.reg file and rebooting the machine.
Administrator Console
You can avoid disabling UAC by using administrator console (thanks to kalme's comment). Here is how:
- Click the window logo in VISTA on the bottom left corner of the screen (it used to be called the Start button).
- Type cmd.exe in the "Start Search" text box.
- Press Ctrl + Shift + Enter. You will see a dialog box asking whether you want to continue or not, click the Continue button. A command prompt window (administrator console) will be opened for you.
- In the command prompt, navigate to the folder where XYWinService.exe is located. Run the above commands to install, start, stop, and uninstall the service, without the interference from UAC.
Configuration Options
Here is a sample configuration file:
="1.0" ="utf-8"
<Configuration>
<ServiceName>CoolestService</ServiceName>
<ServiceDisplay>Coolest Service (Author: Xiangyang Liu)</ServiceDisplay>
<ServiceDescription>????? (??: ???)</ServiceDescription>
<CheckProcessSeconds>30</CheckProcessSeconds>
<RunAs>LocalSystem</RunAs>
<PauseStart>1000</PauseStart>
<PauseEnd>1000</PauseEnd>
<LogFilePath></LogFilePath>
<Process>
<FilePath>c:\windows\system32\MyProgram.exe</FilePath>
<Arguments></Arguments>
<WorkingDir>c:\windows\system32</WorkingDir>
<Restart>Yes</Restart>
</Process>
</Configuration>
You can specify the following options in this XML file:
ServiceName
: This is the name of the service. You can change it to the name you prefer.
ServiceDisplay
: The service display name.
ServiceDescription
: The description text of the service.
CheckProcessSeconds
: The number of seconds to wait before XYWinService
checks the status of the programs defined in this configuration file. If you specify value 60
, then XYWinService
will check every 60
seconds, if one of the programs is dead, it may restart it (depending on how the program is configured, see explanation of the Process
element later).
RunAs
: The value allows you to specify what account you want to use to run XYWinService
. The default is LocalSystem
, you can also use LocalService
, NetworkService
, and User
. If you pick User
, you will be asked to provide user name and password when installing XYWinService
.
LogFilePath
: If you don't specify log file path, it will be XYWinService.log located in the same folder as the XYWinService.exe file.
The Process
element in the above configuration file defines a program to be run by XYWinService
. This element can appear multiple times in the configuration file, that is, you can run as many programs as you wish with a single service installation. Here are the properties you can specify for each program:
FilePath
: The path of the executable file. If you don't specify the full path, XYWinService
will assume that the executable file is located in the WorkingDir folder.
Arguments
: The command line arguments for this program.
WorkingDir
: The working directory. The default is the folder where XYWinService.exe is located.
Restart
: This value indicates whether you want XYWinService
to restart this program if it stopped (exited).
How To Run Multiple Instances of XYWinService
I stated that you will need only one Windows service, i. e. XYWinService
. Why? Because one instance of this service can run multiple programs for you. What if you need the programs to be run under different user accounts with different privileges? That's easy, all you have to do is copy XYWinService.exe and XYWinService.xml to a different folder, modify the XML file (change the service name, user account, define new programs, etc.), and install the new service.
Some Possible Issues
Here are the likely problems if you use XYWinService
:
- Program defined in configuration file won't start.
Most likely XYWinService
can't find the program. Please check the full path (spelling) in the configuration file.
- Program stopped abnormally.
It may need resource it can't find or privilege it doesn't have. You need to configure the service to run with a proper account.
- Program can't find network resource.
Again you need to configure the service to run with a proper account. If you use LocalSystem
, LocalService
, or NetworkService
, your program won't be able to access anything on the LAN.
- Where do I look for debug information?
The log file contains information on XYWinService
, including what it is currently doing and all exceptions.
Hope you like the new service. Thanks.
History
- 7th August, 2008: Initial post