Click here to Skip to main content
11,921,889 members (70,265 online)
Click here to Skip to main content
Add your own
alternative version


42 bookmarked

Windows Service Updater

, 13 Mar 2007
Rate this:
Please Sign up or sign in to vote.
Simple way to update a running windows service


This simple code shows how to update a Windows service without having to go through the manual process of starting/stopping it.

To make it work you put your new service .exe file in a specified directory and then the service itself looks at the file system. Once it sees an update for itself, it then calls serviceupdate.exe to stop the service, replace the executable, and then restart
the service again. This saves plenty of time when having to do lots of updates to a service.

These go in the windows service:

private void IntializeFileSystemWatcher()
    System.IO.FileSystemWatcher newexe=new   System.IO.FileSystemWatcher(
    newexe.Created += new FileSystemEventHandler(NewExecutable);
    newexe.EnableRaisingEvents = true;
private void NewExecutable(object source, FileSystemEventArgs e)
protected override void OnStart(string[] args)

Contents of serviceupdate.exe:

static void Main(string[] args)
    if (args.Length == 0)
    string filename=args[0];

    System.ServiceProcess.ServiceController target = new 

    while(target.Status != 
    File.Delete("c:\\services\\Updates\\" + filename + ".exe");

    File.Move("c:\\services\\Updates\\" + filename + 
        ".exe","c:\\services\\" + filename + ".exe");


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

Bruce Bayley
United Kingdom United Kingdom
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralA little off topic. Pin
smesser1-Apr-07 19:02
membersmesser1-Apr-07 19:02 
GeneralDoes the Trick Pin
Owen Hines26-Mar-07 5:18
memberOwen Hines26-Mar-07 5:18 
GeneralSend email through window service Pin
vidya_rpl16-Mar-07 7:19
membervidya_rpl16-Mar-07 7:19 
GeneralInnovation Pin
Behind The Scene12-Sep-06 8:17
memberBehind The Scene12-Sep-06 8:17 
GeneralRe: Innovation Pin
Anthony Rudovsky12-Sep-06 14:15
memberAnthony Rudovsky12-Sep-06 14:15 
GeneralRe: Innovation Pin
vik2012-Sep-06 20:59
membervik2012-Sep-06 20:59 
GeneralRe: Innovation Pin
steves013-Sep-06 0:09
membersteves013-Sep-06 0:09 
GeneralRe: Innovation Pin
Pepato30-Mar-07 0:20
memberPepato30-Mar-07 0:20 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.151120.1 | Last Updated 13 Mar 2007
Article Copyright 2006 by Bruce Bayley
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid