Click here to Skip to main content
13,193,551 members (37,263 online)
Click here to Skip to main content
Add your own
alternative version


42 bookmarked
Posted 12 Sep 2006

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 18:02
membersmesser1-Apr-07 18:02 
GeneralDoes the Trick Pin
Owen Hines26-Mar-07 4:18
memberOwen Hines26-Mar-07 4:18 
GeneralSend email through window service Pin
vidya_rpl16-Mar-07 6:19
membervidya_rpl16-Mar-07 6:19 
GeneralInnovation Pin
Behind The Scene12-Sep-06 7:17
memberBehind The Scene12-Sep-06 7:17 
GeneralRe: Innovation Pin
Anthony Rudovsky12-Sep-06 13:15
memberAnthony Rudovsky12-Sep-06 13:15 
GeneralRe: Innovation Pin
vik2012-Sep-06 19:59
membervik2012-Sep-06 19:59 
GeneralRe: Innovation Pin
steves012-Sep-06 23:09
membersteves012-Sep-06 23:09 
GeneralRe: Innovation Pin
Pepato29-Mar-07 23:20
memberPepato29-Mar-07 23: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.

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