![]() |
Platforms, Frameworks & Libraries »
.NET Framework »
Utilities
Beginner
License: The Code Project Open License (CPOL)
A simplified .NET 2.0 version of XYNTService built for XP and VISTABy Xiangyang Liu 刘向阳The only Windows service you will ever need, hopefully |
C#.NET 2.0, Win2K, WinXP, Win2003, VistaVS2005, CEO, Architect, DBA, Dev, QA, Design, SysAdmin, Sales, Marketing
|
|
Advanced Search |
|
|
|
||||||||||||||||
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.
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:
XYWinService starts. XYWinService. XYWinService stops. To install and start this service, you need to:
xywinservice.exe -i " to install the service. 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 ".
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.
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.
You can avoid disabling UAC by using administrator console (thanks to kalme's comment). Here is how:
Here is a sample configuration file:
<?xml version="1.0" encoding="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). 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.
Here are the likely problems if you use XYWinService:
Most likely XYWinService can't find the program. Please check the full path (spelling) in the configuration file.
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.
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.
The log file contains information on XYWinService, including what it is currently doing and all exceptions.
Hope you like the new service. Thanks.
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 7 Aug 2008 Editor: Deeksha Shenoy |
Copyright 2008 by Xiangyang Liu 刘向阳 Everything else Copyright © CodeProject, 1999-2009 Web16 | Advertise on the Code Project |