Click here to Skip to main content
6,306,412 members and growing! (17,094 online)
Email Password   helpLost your password?
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 VISTA

By 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
Version:2 (See All)
Posted:7 Aug 2008
Views:13,936
Bookmarked:40 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
16 votes for this article.
Popularity: 5.68 Rating: 4.72 out of 5
1 vote, 6.3%
1

2
1 vote, 6.3%
3

4
14 votes, 87.5%
5

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:

  1. Copy XYWinService.exe and XYWinService.xml into a folder on the target machine.
  2. Modify XYWinService.xml file to define your programs.
  3. Run command " xywinservice.exe -i " to install the service.
  4. 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:

  1. Click the window logo in VISTA on the bottom left corner of the screen (it used to be called the Start button).
  2. Type cmd.exe in the "Start Search" text box.
  3. 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.
  4. 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:

<?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).

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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Xiangyang Liu 刘向阳


Member

Location: United States United States

Other popular .NET Framework articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 21 of 21 (Total in Forum: 21) (Refresh)FirstPrevNext
GeneralProblem on Vista [modified] Pinmembersiggy384:26 21 Jan '09  
GeneralRe: Problem on Vista [modified] Pinmembersiggy387:32 21 Jan '09  
GeneralWhere is the OnStart override ? Pinmemberquantum198111:57 6 Dec '08  
GeneralUser NAme password required Pinmemberanildbest23:25 19 Oct '08  
GeneralService Install assemble location not in talking marks PinmemberTheChadOz18:46 14 Aug '08  
GeneralRe: Service Install assemble location not in talking marks [modified] PinmemberXiangyang Liu ???1:54 15 Aug '08  
GeneralUAC Pinmemberkalme1:51 12 Aug '08  
GeneralRe: UAC PinmemberXiangyang Liu ???21:17 12 Aug '08  
GeneralRe: UAC Pinmemberkalme22:05 12 Aug '08  
GeneralRe: UAC PinmemberXiangyang Liu ???3:15 13 Aug '08  
GeneralRe: UAC Pinmemberkalme2:12 14 Aug '08  
GeneralRe: UAC [modified] PinmemberXiangyang Liu ???3:54 14 Aug '08  
GeneralRe: UAC Pinmemberkalme22:55 14 Aug '08  
GeneralRe: UAC [modified] PinmemberXiangyang Liu ???1:57 15 Aug '08  
GeneralRe: UAC Pinmemberkalme11:10 19 Aug '08  
GeneralVery timely! PinmemberRavi Bhavnani11:53 7 Aug '08  
GeneralRe: Very timely! [modified] PinmemberXiangyang Liu ???16:04 7 Aug '08  
GeneralRe: Very timely! PinmemberRavi Bhavnani3:15 8 Aug '08  
GeneralAwesome! PinsupporterMarc Clifton11:23 7 Aug '08  
GeneralRe: Awesome! [modified] PinmemberXiangyang Liu ???15:59 7 Aug '08  
GeneralRe: Awesome! PinmemberMember 8352513:56 30 Oct '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin 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