|
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:
- 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 low 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:
<?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.
| You must Sign In to use this message board. |
|
| | Msgs 1 to 16 of 16 (Total in Forum: 16) (Refresh) | FirstPrevNext |
|
|
 |
|
|
Hi,
I had an issue with the install of my services and it appears to be because the call to InstallUtil that passes the XYWinService.exe file location as an argument is not enclosed in talking marks. My XYWinService file was located in Program Files and the space causes a file not found error. I was able to run the InstallUtl command manually.
case "-i": case "/i": { WriteLog("Installing " + m_sServiceName); ProcessStartInfo oInfo = new ProcessStartInfo(); oInfo.FileName = Environment.GetEnvironmentVariable("SystemRoot") + "\\Microsoft.NET\\Framework\\v2.0.50727\\InstallUtil.exe"; oInfo.Arguments = m_sConfigFilePath.Replace(".xml", ".exe"); oInfo.CreateNoWindow = true; oInfo.UseShellExecute = false; Process.Start(oInfo); } break;
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
"You may have problems installing XYWinService on VISTA. This is because UAC is enabled, even if you logged on as admin, you don't have the proper privilege to install the service. You can either set up proper privileges (which is not easy) or disable UAC."
Why don't you add a manifest file that just tells Vista your application needs elevation? I consider it bad advice to suggest disabling UAC just because you as a developer don't know how to handle it. With a proper manifest file, the user does not need to set up or disable anything, is prompted for the required rights/credentials, and your application is still fine to be run as service. Take a look at this for a very nice introduction:
How-To-Tell-Vistas-UAC-What-Privelege-Level-Your-App-Requires[^]
In Visual Studio 2008 it's even easier - just add a manifest file and change the setting to fit your needs, done.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
kalme wrote: just because you as a developer don't know how to handle it
I know how to handle it. I just don't like it.
kalme wrote: I consider it bad advice to suggest disabling UAC
Why does every application has to be modified to ask for elevation in the first place? Is it so hard for VISTA to detect that a user is currently logged on as Admin and ask the user if he needs elevation for the program he is trying to run?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Xiangyang Liu ??? wrote: Why does every application has to be modified to ask for elevation in the first place? Is it so hard for VISTA to detect that a user is currently logged on as Admin and ask the user if he needs elevation for the program he is trying to run?
You mean like Vista asking for EVERY program the user starts, just because he's an admin? Wow, that would be even more annoying than UAC how it's built today... and what would you do with users who are not admins? Asked them too for EVERY program and let them provide admin credentials?
Btw. Vista indeed has built-in features to detect if a program needs elevation even if it does not provide a manifest. But this is targeted mainly at installers and does not work in your case. Obviously the long-term objective is to force developers think about their style of programming and make as much applications as possible to run without elevation. Of course there will always be the administrative tools that just need it (like your service), but that's no problem - as I said, you just need to tell Vista what you need.
Xiangyang Liu ??? wrote: I just don't like it.
Wow, that's... mature. Things are the way they are, and often things may not evolve in a way you like. Heck, I don't like a lot of Vista's new stuff too. But you just cannot blind yourself to the facts and force users of your software to do stupid things (yes, I consider turning off UAC stupid) just because you "don't like it". You always have to modify your applications when a new generation of OS's is released because some things don't work like before or have to be done different. But that's something I like about our jobs: being forced to develop yourself and never stop learning and adopting new techniques. Maybe you should too .
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
kalme wrote: You mean like Vista asking for EVERY program the user starts, just because he's an admin?
Ask only if it is needed. Most of the programs do not need elevation, right? So, if a program won't be able to run because lack of privilege, the OS should ask user if he is logged on as admin, as if the program is built with elevation mechanism. How is that more annoying?
kalme wrote: and what would you do with users who are not admins? Asked them too for EVERY program and let them provide admin credentials?
I did not say that. But for non-admin users, not allowing the programs to run is definitely less annoying, they won't be able to run many programs on XP today.
That said, new programs written for VISTA can still be built with mechanism to ask for elevation. Don't break other existing programs when there is no need to. Is that too much to ask (of Microsoft)?
kalme wrote: But you just cannot blind yourself to the facts and force users of your software to do stupid things (yes, I consider turning off UAC stupid) just because you "don't like it".
Stupidity is in the eyes of beholders. I don't think Microsoft is that sure about UAC either. Otherwise they won't let you turn it off so easily.
kalme wrote: But that's something I like about our jobs: being forced to develop yourself and never stop learning and adopting new techniques. Maybe you should too
Thank you for the advice. It is always good to see and hear from young optimists.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Xiangyang Liu ??? wrote: Don't break other existing programs when there is no need to.
Actually they tried hard not to (virtualization of file system, registry etc.), but your program is not an existing one, right? You made a new version, it's only natural to add features needed for newer OS's.
Xiangyang Liu ??? wrote: Thank you for the advice. It is always good to see and hear from young optimists.
You would be surprised to learn that I'm an "old fart" too . At least regarding programming business :P
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
kalme wrote: but your program is not an existing one, right? You made a new version, it's only natural to add features needed for newer OS's.
I am not talking about my programs only. For example, iisreset.exe won't work any more. The error message says you have to have admin privilege for it to work. I am the damn admin, can't it tell? After disabling UAC, it works. Sign.
kalme wrote: You would be surprised to learn that I'm an "old fart" too
It is equally good to see and hear from an old optimist, too (it is so rare to find one).
modified on Thursday, August 14, 2008 9:08 AM
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Xiangyang Liu ??? wrote: For example, iisreset.exe won't work any more.
For these things I always have an administrator console at hand. Shortcut (you may already know that):
=> Windows key (to bring up the start menu) => "cmd.exe" (depending on your installed programs, "cmd" or even "cm" may be sufficient) => Press Ctrl+Shift+Enter
Oh and you can also choose to "elevate without prompting" in the Local Security Policy settings to make those annoying UAC messages go away without turning off UAC.
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
kalme wrote: For these things I always have an administrator console at hand. Shortcut (you may already know that):
=> Windows key (to bring up the start menu) => "cmd.exe" (depending on your installed programs, "cmd" or even "cm" may be sufficient) => Press Ctrl+Shift+Enter
I don't. I will try it. If I can install XYWinService this way, then it is a much better solution than modifying each program to work with UAC. Thanks.
kalme wrote: Oh and you can also choose to "elevate without prompting" in the Local Security Policy settings to make those annoying UAC messages go away without turning off UAC.
That is close, if not same, to disabling UAC for one or more users, right?
modified on Friday, August 15, 2008 7:29 AM
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi again!
Xiangyang Liu ??? wrote: That is close, if not same, to disabling UAC for one or more users, right? [Big Grin]
Not really. I agree it's a security risk to do that (they also say so in the description by the way), but it's quite a difference if your account always has the administrator token attached and any malicious software and/or security flaw can do any harm to your system (UAC disabled) or if malicious software has to be aware of UAC and try to find its way around it, right? For example, the latter handles any security flaws exploitable in previous Windows versions like XP.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Thanks, Ravi. There are guys/girls in my office that make me feel like a grandpa, I am glad that I can still be useful sometimes. BTW, I looked at your profile picture today, you haven't aged a bit after these years.
modified on Friday, August 8, 2008 6:21 AM
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Xiangyang Liu ??? wrote: you haven't aged a bit after these years.
All that coding keeps us old farts looking young. 
/ravi
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I wish you had done this 6 months ago, when I went through the pain of making my server run as a service, which required some help from the fellow who wrote NetZ. 
Marc
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Sorry, 6 months ago I hated everything related to VISTA, I just concluded that VISTA is not that bad, at least it is something I can live with.
modified on Thursday, August 7, 2008 9:05 PM
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
General News Question Answer Joke Rant Admin
|