Bona Botse
A little insight goes a long way
- Joined
- Oct 10, 2005
- Messages
- 5,227
UPDATE 2013/03/23:
Version 0.3 released.
I've added some features which I've needed since the initial release. Maybe they'll be useful to others as well.
- Duplication is now possible, i.e. you can run the same application more than once, like multiple "cmd" processes.
- You can send arguments to an application.
- You can set an application to close when you stop the service.
- You can set the logging level to minimal (only logs errors) and verbose (logs pretty much everything that happens, for troubleshooting).
All these features can be accessed by changing the config file "ApplicationService.exe.config" in "C:\Program Files\Blaq Entertainment\Application Service Maker" or wherever you elected to install to. If you don't need the new features then there's no need to alter your current settings as they're backward compatible.
PLEASE MAKE A BACKUP OF YOUR CURRENT CONFIG FILE BEFORE UNINSTALLING OR UPDATING!
The new format for defining applications is
where
app is the name of the application to run (e.g. python)
path is the path to the application (e.g. C:\Python27\python.exe)
can_duplicate is either "Y" or "N" to indicate if the service can run the application even if it was already started.
arguments is whatever arguments you want to send to the application (e.g. "C:\Program Files\SickBeard\SickBeard.py")
close_on_exit is either "Y" or "N" to indicate if the service should close the application when the service is stopped
You can also see the "LoggingMode" setting, this should be "M" for minimal and "V" for verbose.
A few notes on duplications:
- If duplicate is set to "Y", then the service will run the application only if the currently running application instance wasn't started by the service. So if "python.exe" is already running and you start the service, another "python.exe" will be started by the service, but when the service checks for running applications after the interval, it will not run "python.exe" again (unless it stopped for some reason). The service will know which python it started by using process IDs.
- Normally if you use duplication, you'll probably want to set "close_on_exit" to "Y" as well, because when you stop the service, the service "forgets" which applications it started to it will start the process again when you start the service again.
Anywho, get the new shiny version here:
Installer: https://www.box.com/s/qm8fhfygcjw4rs1zwpbf
Source: https://www.box.com/s/2a3cnb4datb2ey6878h8
UPDATE 2013/03/20:
Version 0.2 released.
Not really much in this release, just a fix for Calibre's calibre-server not playing nice with the service.
Install: https://www.box.com/s/bbbdsscjafajo9cuzdwi
Source: https://www.box.com/s/j5qtizv2aq2pjhx6grzx
[Original Post]
Hi all,
I've written a service (C# Windows service) that allows you to run any program like a service.
First, some background:
I have a few programs that I want to always be running (SickBeard, CouchPotato, No-IP DUC and some others), and due to power cuts/surges/dips, my computer restarts quite often. I set the computer up so that it comes on automatically after a power cut, but the other problem is that unless I log into my user account, the programs won't start because they're not services.
So I decided to just make my own service that will run the programs automatically. You install the service and define a list of programs that you want to always be running, and the service will check periodically (interval can also be defined) if the programs are running and run any programs that are in your list and are not currently running. If a problem occurs while trying to run a program, the service will not try to run that program again until the service is restarted. It logs all errors and some messages to the event log.
I've been running it for 2 days now and it's working nicely
. I figured maybe it will be of use to others as well, and so I decided to release a version 0.1 beta. I'm also releasing the source code for scrutiny.
Installation:
Download the installer linked to below and run it. Select a download location and install. During installation you will need to enter the credentials of a user that you want to run the programs as (probably your account), and can write to the event log (an admin account).
Setup:
After installation, go to your installation directory (default C:\Program Files\Blaq Entertainment\Application Service Maker) and open the file ApplicationService.exe.config with notepad or any other text editor. Find the following section:
TimerIntervalMinutes is the time in minutes that the service should wait before checking/running programs.
ApplicationList is the list of programs that you want the service to check and run. The format is "{app;path}{app;path}{appn;path}".
"app" is the exe's name e.g. SickBeard (you can find this by opening the Windows task manager and clicking the processes tab).
"path" is the path to the exe (in the task manager, right click the process and select "Open file location").
Here are my current settings to give you a real example:
After configuring the settings, save the file and close it.
Now go to services (start, type "services.msc" and enter), find the service named "Application Service Maker", right click it and select "Start". You should then receive a call from a strange fellow named Bob, claiming to be your uncle.
Now what?:
At this point it might seem like nothing spectacular happened, but behind the scenes there was a bit of action.
Go to the event viewer, expand Windows Logs and then Application on the left. The service will write messages to the event viewer under the source "ApplicationService".
When the service starts, it will write
When the service runs an application, it will write
If something goes wrong while trying to run a program, it will write (this will change depending on the error)
If the program is already running, it will write
There's a few other messages, but I'm sure you get the picture, the messages are meant to give you a good enough idea of what's going on.
Now your computer can restart and the service will automatically launch your programs.
Downloads:
Phew, this is probably my longest post yet
. Without further ado, here's some links.
Installer: http://www.box.com/s/3imdtksvyz2k89f7r2la
Source code: http://www.box.com/s/5qujeg4n61hfitbts18k
The source code is in a 7zip archive: http://www.7-zip.org/download.html
If the concept interests you, please give it a bash and leave your feedback here. I'll welcome all comments with a
. Enjoy!
Version 0.3 released.
I've added some features which I've needed since the initial release. Maybe they'll be useful to others as well.
- Duplication is now possible, i.e. you can run the same application more than once, like multiple "cmd" processes.
- You can send arguments to an application.
- You can set an application to close when you stop the service.
- You can set the logging level to minimal (only logs errors) and verbose (logs pretty much everything that happens, for troubleshooting).
All these features can be accessed by changing the config file "ApplicationService.exe.config" in "C:\Program Files\Blaq Entertainment\Application Service Maker" or wherever you elected to install to. If you don't need the new features then there's no need to alter your current settings as they're backward compatible.
PLEASE MAKE A BACKUP OF YOUR CURRENT CONFIG FILE BEFORE UNINSTALLING OR UPDATING!
The new format for defining applications is
Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="ApplicationService.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<ApplicationService.Settings>
<setting name="TimerIntervalMinutes" serializeAs="String">
<value>20</value>
</setting>
<setting name="ApplicationList" serializeAs="String">
<value>{app;path;can_duplicate;args;close_on_exit}</value>
</setting>
<setting name="LoggingMode" serializeAs="String">
<value>M</value>
</setting>
</ApplicationService.Settings>
</userSettings>
</configuration>
where
app is the name of the application to run (e.g. python)
path is the path to the application (e.g. C:\Python27\python.exe)
can_duplicate is either "Y" or "N" to indicate if the service can run the application even if it was already started.
arguments is whatever arguments you want to send to the application (e.g. "C:\Program Files\SickBeard\SickBeard.py")
close_on_exit is either "Y" or "N" to indicate if the service should close the application when the service is stopped
You can also see the "LoggingMode" setting, this should be "M" for minimal and "V" for verbose.
A few notes on duplications:
- If duplicate is set to "Y", then the service will run the application only if the currently running application instance wasn't started by the service. So if "python.exe" is already running and you start the service, another "python.exe" will be started by the service, but when the service checks for running applications after the interval, it will not run "python.exe" again (unless it stopped for some reason). The service will know which python it started by using process IDs.
- Normally if you use duplication, you'll probably want to set "close_on_exit" to "Y" as well, because when you stop the service, the service "forgets" which applications it started to it will start the process again when you start the service again.
Anywho, get the new shiny version here:
Installer: https://www.box.com/s/qm8fhfygcjw4rs1zwpbf
Source: https://www.box.com/s/2a3cnb4datb2ey6878h8
UPDATE 2013/03/20:
Version 0.2 released.
Not really much in this release, just a fix for Calibre's calibre-server not playing nice with the service.
Install: https://www.box.com/s/bbbdsscjafajo9cuzdwi
Source: https://www.box.com/s/j5qtizv2aq2pjhx6grzx
[Original Post]
Hi all,
I've written a service (C# Windows service) that allows you to run any program like a service.
First, some background:
I have a few programs that I want to always be running (SickBeard, CouchPotato, No-IP DUC and some others), and due to power cuts/surges/dips, my computer restarts quite often. I set the computer up so that it comes on automatically after a power cut, but the other problem is that unless I log into my user account, the programs won't start because they're not services.
So I decided to just make my own service that will run the programs automatically. You install the service and define a list of programs that you want to always be running, and the service will check periodically (interval can also be defined) if the programs are running and run any programs that are in your list and are not currently running. If a problem occurs while trying to run a program, the service will not try to run that program again until the service is restarted. It logs all errors and some messages to the event log.
I've been running it for 2 days now and it's working nicely
Installation:
Download the installer linked to below and run it. Select a download location and install. During installation you will need to enter the credentials of a user that you want to run the programs as (probably your account), and can write to the event log (an admin account).
Setup:
After installation, go to your installation directory (default C:\Program Files\Blaq Entertainment\Application Service Maker) and open the file ApplicationService.exe.config with notepad or any other text editor. Find the following section:
Code:
<ApplicationService.Settings>
<setting name="TimerIntervalMinutes" serializeAs="String">
<value>20</value>
</setting>
<setting name="ApplicationList" serializeAs="String">
<value>{app1;path}{app2;path}</value>
</setting>
</ApplicationService.Settings>
ApplicationList is the list of programs that you want the service to check and run. The format is "{app;path}{app;path}{appn;path}".
"app" is the exe's name e.g. SickBeard (you can find this by opening the Windows task manager and clicking the processes tab).
"path" is the path to the exe (in the task manager, right click the process and select "Open file location").
Here are my current settings to give you a real example:
Code:
<ApplicationService.Settings>
<setting name="TimerIntervalMinutes" serializeAs="String">
<value>20</value>
</setting>
<setting name="ApplicationList" serializeAs="String">
<value>{SickBeard;C:\SickBeard\SickBeard.exe}{DUC30;C:\Program Files (x86)\No-IP\DUC30.exe}{LogMeIn;C:\Program Files (x86)\LogMeIn\x64\LogMeIn.exe}</value>
</setting>
</ApplicationService.Settings>
Now go to services (start, type "services.msc" and enter), find the service named "Application Service Maker", right click it and select "Start". You should then receive a call from a strange fellow named Bob, claiming to be your uncle.
Now what?:
At this point it might seem like nothing spectacular happened, but behind the scenes there was a bit of action.
Go to the event viewer, expand Windows Logs and then Application on the left. The service will write messages to the event viewer under the source "ApplicationService".
When the service starts, it will write
Code:
Application service started.
TimerIntervalMinutes: 20
Applications to start:
SickBeard (C:\SickBeard\SickBeard.exe)
DUC30 (C:\Program Files (x86)\No-IP\DUC30.exe)
LogMeIn (C:\Program Files (x86)\LogMeIn\x64\LogMeIn.exe)
Code:
Attempting to start application: SickBeard (C:\SickBeard\SickBeard.exe)
Code:
An error has occured in the application ApplicationService.
Error Location: ServiceStartApplications.StartApplication.
System.Exception: An error occurred when starting an application.
ApplicationName: SickBeard
PathToProcess: C:\SickBeard\SickBeard.exe
---> System.ComponentModel.Win32Exception: The system cannot find the file specified
at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start(String fileName)
at ApplicationService.ServiceStartApplications.StartApplications()
--- End of inner exception stack trace ---
Code:
Application LogMeIn (C:\Program Files (x86)\LogMeIn\x64\LogMeIn.exe) has started, no need to start it.
Now your computer can restart and the service will automatically launch your programs.
Downloads:
Phew, this is probably my longest post yet
Installer: http://www.box.com/s/3imdtksvyz2k89f7r2la
Source code: http://www.box.com/s/5qujeg4n61hfitbts18k
The source code is in a 7zip archive: http://www.7-zip.org/download.html
If the concept interests you, please give it a bash and leave your feedback here. I'll welcome all comments with a
Last edited: