Click here to Skip to main content
14,427,818 members

The "Silent Process Service"

Rate this:
4.32 (16 votes)
Please Sign up or sign in to vote.
4.32 (16 votes)
3 May 2006
Convert an application to a service without modifying any code.


Recently, I ran into a situation where I needed to make an application launch automatically on start up. The problem was that the program that I needed to launch was designed as a WinForms application. Therefore, the only way to make it launch automatically was to make the computer automatically login and run the application. Unfortunately, the company I was working for had a strict security policy, and forcing a computer to automatically login was out of the question.

Originally, I thought about converting the entire application to an NT service. However, I was on a tight deadline, and removing the UI code would have required some extensive work and additional testing. Therefore, I needed an alternative solution. After digging around on the internet for a while, I discovered the ProcessStartInfo class. Suddenly, the light bulb turned on in my head, and I starting developing a new service which I have dubbed as the "Silent Process"...

Using the code

The code is very simple, and for the most part, self-explanatory. The service contains an OnStart and an OnStop method.

In the OnStart method, I instantiate a new ProcessStartInfo object. I then set the CreateNoWindow property to true. This way, I can run the WinForms application in the background. I also set the WindowStyle property to Hidden just as an extra precaution. The remaining properties are read from the app.config file. By modifying the configuration file, you can virtually make any application run as a service!

In the OnStop method, I check for any processes that I may have launched. If I find any matching processes, I kill them.

protected override void OnStart(string[] args){

    try {
        ProcessStartInfo startInfo = new ProcessStartInfo();
        startInfo.CreateNoWindow = true;
        startInfo.WorkingDirectory = 
        startInfo.FileName = 
        startInfo.WindowStyle = ProcessWindowStyle.Hidden;
        Process.Start( startInfo );
    catch( Exception ex ) {
        Console.WriteLine( ex.Message );

private void KillExistingProcesses(){
    Process[] processes = Process.GetProcessesByName( 
      ".exe", String.Empty ) );
    foreach( Process process in processes ) {

protected override void OnStop(){


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Michael Ceranski
Software Developer (Senior) Concepts2Code
United States United States
Michael is the co-founder and master consultant for Concepts2Code, a software consulting company based in Buffalo, New York. He's been programming since the early 1990's. His vast programming experience includes VB, Delphi, C#, ASP, ASP.NET, Ruby on Rails, Coldfusion and PHP. Michael also is a Microsoft Certified Application Developer and a Certified Technology Specialist for SQL Server.

Visit his blog.

Comments and Discussions

GeneralGood Pin
loyal ginger5-Nov-09 7:30
Memberloyal ginger5-Nov-09 7:30 
GeneralMy vote of 1 Pin
Paresh Gheewala1-Dec-08 21:13
MemberParesh Gheewala1-Dec-08 21:13 
GeneralWindows Server 2003 Pin
longg20-Sep-07 9:46
Memberlongg20-Sep-07 9:46 
GeneralRe: Windows Server 2003 Pin
Michael Ceranski20-Sep-07 10:58
MemberMichael Ceranski20-Sep-07 10:58 
GeneralGUI applications should not be services Pin
palmer_tr16-May-06 17:09
Memberpalmer_tr16-May-06 17:09 
GeneralRe: GUI applications should not be services Pin
Michael Ceranski17-May-06 3:16
MemberMichael Ceranski17-May-06 3:16 
GeneralRe: GUI applications should not be services Pin
chefZ10-Jun-07 18:57
MemberchefZ10-Jun-07 18:57 
GeneralApplication doesn't display Pin
jmlfdcguy11-May-06 4:00
Memberjmlfdcguy11-May-06 4:00 
GeneralRe: Application doesn't display Pin
Michael Ceranski17-May-06 3:19
MemberMichael Ceranski17-May-06 3:19 
GeneralRe: Application doesn't display Pin
bytebugs29-Jun-06 0:21
Memberbytebugs29-Jun-06 0:21 
QuestionKill? Pin
windrago9-May-06 7:38
Memberwindrago9-May-06 7:38 
AnswerRe: Kill? Pin
Michael Ceranski17-May-06 3:22
MemberMichael Ceranski17-May-06 3:22 
GeneralRe: Kill? Pin
P@trickP15-Oct-07 22:58
MemberP@trickP15-Oct-07 22:58 
QuestionWhat about GUI interface? Pin
varnk9-May-06 3:46
Membervarnk9-May-06 3:46 
GeneralWorkarounds... Pin
Fabrice Vergnenegre3-May-06 12:22
MemberFabrice Vergnenegre3-May-06 12:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 3 May 2006


73 bookmarked