5,426,531 members and growing! (14,617 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#, Windows (Win2K, WinXP, Win2003, Vista, Windows), .NET (.NET 2.0, .NET), Visual Studio (Visual Studio, VS2005), CEO, Architect, DBA, Dev, QA, Design, SysAdmin, Sales, Marketing

Posted: 7 Aug 2008
Updated: 7 Aug 2008
Views: 3,705
Bookmarked: 28 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
12 votes for this Article.
Popularity: 5.03 Rating: 4.66 out of 5
1 vote, 8.3%
1
0 votes, 0.0%
2
1 vote, 8.3%
3
0 votes, 0.0%
4
10 votes, 83.3%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Download XYWinService - 9.78 KB

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 run other programs. The programs you want to run by XYWinService are defined in a xml configuration file. All programs run by XYWinService behaves 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 low 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.

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 刘向阳



Location: United States United States

Other popular .NET Framework articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 16 of 16 (Total in Forum: 16) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralService Install assemble location not in talking marksmemberTheChadOz18:46 14 Aug '08  
GeneralRe: Service Install assemble location not in talking marks [modified]memberXiangyang Liu ???1:54 15 Aug '08  
GeneralUACmemberkalme1:51 12 Aug '08  
GeneralRe: UACmemberXiangyang Liu ???21:17 12 Aug '08  
GeneralRe: UACmemberkalme22:05 12 Aug '08  
GeneralRe: UACmemberXiangyang Liu ???3:15 13 Aug '08  
GeneralRe: UACmemberkalme2:12 14 Aug '08  
GeneralRe: UAC [modified]memberXiangyang Liu ???3:54 14 Aug '08  
GeneralRe: UACmemberkalme22:55 14 Aug '08  
GeneralRe: UAC [modified]memberXiangyang Liu ???1:57 15 Aug '08  
GeneralRe: UACmemberkalme11:10 19 Aug '08  
GeneralVery timely!memberRavi Bhavnani11:53 7 Aug '08  
GeneralRe: Very timely! [modified]memberXiangyang Liu ???16:04 7 Aug '08  
GeneralRe: Very timely!memberRavi Bhavnani3:15 8 Aug '08  
GeneralAwesome!supporterMarc Clifton11:23 7 Aug '08  
GeneralRe: Awesome! [modified]memberXiangyang Liu ???15:59 7 Aug '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:
Copyright 2008 by Xiangyang Liu 刘向阳
Everything else Copyright © CodeProject, 1999-2008
Web15 | Advertise on the Code Project