472,371 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,371 software developers and data experts.

Automatically update Winows .NET Service

Is there a way to automatically update a Windows .NET service, kind of like
Click-Once or put a file in the directory and the service would restart it's
self and replace the executables or at least replace its DLLs without
restarting? I know it's posible, (anything is posible) but is there
anything already in place?

Thank You
Peter

Oct 31 '08 #1
2 10932
Hello Peter,

Actually, from the MSDN document
http://msdn.microsoft.com/en-us/library/ms973805.aspx, we can see that the
ClickOnce does not support installing the .Net Windows Services. We have to
implement the self update logical by ourselves. The following is my simple
solution for this objective.

Firstly, I describe the scenario of my solution,

1.A .net Windows service named service.exe located at c:\services\
2.A folder named c:\services\updates stores the new version of a .net
Windows service
3.Now, you have a new version of the above mentioned service named
newservice.exe
4.An app named serviceupdate.exe is located at c:\services\ for updating a
services automatically
Now, the solution is described as the following steps:

1.Creating an instance of FileSystemWatcher to listen to the change of file
system, the code looks like:
private void IntializeFileSystemWatcher()
{
System.IO.FileSystemWatcher newexe = new System.IO.FileSystemWatcher(
"c:\\services\\Updates", "newservice.exe");
//other codes are described in step 2
}

protected override void OnStart(string[] args)
{
IntializeFileSystemWatcher();
}

2.Listen to the Created or Changed event of the FileSystemWatcher instance,
the code looks like:
//the following code is put in the method IntializeFileSystemWatcher()
newexe.Created += new FileSystemEventHandler(NewExecutable);
newexe.Changed += new FileSystemEventHandler(NewExecutable);
newexe.EnableRaisingEvents = true;

private void NewExecutable(object source, FileSystemEventArgs e)
{
Process.Start("c:\\services\\serviceupdate.exe","s ervice",
"newservice");
}

The above code listen to the changed and created event. When the event
occurs, serviceupdate.exe will be called to automatically update services.

3.Creating the serviceupdate.exe app. The app is a simply console
application that is used to stop the old service, replace the service file
and then restart new service. The code looks like:
static void Main(string[] args)
{
if (args.Length == 0)
return;

string oldname = args[0];
string newname = args[1];

System.ServiceProcess.ServiceController target = new
System.ServiceProcess.ServiceController(oldname);
target.Stop();

while(target.Status
!=System.ServiceProcess.ServiceControllerStatus.St opped)
{
target.Refresh();
}
Thread.Sleep(2000);

File.Delete("c:\\services\\" + oldname + ".exe");
File.Move("c:\\services\\Updates\\" + newname + ".exe", "c:\\services\\"
+ newname + ".exe");

target.Start();
}

Serviceupdate.exe needs two parameters. The first one is the name of old
services that is located at c:\seriveces in the solution. The second one is
the name of new services that is located at c:\services\updates in the
solution. Of course, you can set the same name for the old and new service
because they are in different folder.

Another solution is to create a separate AppDomain for each unique managed
service assembly and use Remoting to create and control the managed
service's IService implementation. There are two nice articles related to
this topic here.

http://www.15seconds.com/issue/040624.htm
http://www.15seconds.com/issue/040817.htm

Please let me know if these help for your scenario. If you have any future
questions or concerns, please let me know.
Best regards,
Ji Zhou (v-****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/...tance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 3 '08 #2

"""Ji Zhou [MSFT]""" <v-****@online.microsoft.comwrote in message
news:%2****************@TK2MSFTNGHUB02.phx.gbl...
Hello Peter,

Actually, from the MSDN document
http://msdn.microsoft.com/en-us/library/ms973805.aspx, we can see that the
ClickOnce does not support installing the .Net Windows Services. We have
to
implement the self update logical by ourselves. The following is my simple
solution for this objective.

Firstly, I describe the scenario of my solution,

1.A .net Windows service named service.exe located at c:\services\
2.A folder named c:\services\updates stores the new version of a .net
Windows service
3.Now, you have a new version of the above mentioned service named
newservice.exe
4.An app named serviceupdate.exe is located at c:\services\ for updating a
services automatically
Now, the solution is described as the following steps:

1.Creating an instance of FileSystemWatcher to listen to the change of
file
system, the code looks like:
private void IntializeFileSystemWatcher()
{
System.IO.FileSystemWatcher newexe = new System.IO.FileSystemWatcher(
"c:\\services\\Updates", "newservice.exe");
//other codes are described in step 2
}

protected override void OnStart(string[] args)
{
IntializeFileSystemWatcher();
}

2.Listen to the Created or Changed event of the FileSystemWatcher
instance,
the code looks like:
//the following code is put in the method IntializeFileSystemWatcher()
newexe.Created += new FileSystemEventHandler(NewExecutable);
newexe.Changed += new FileSystemEventHandler(NewExecutable);
newexe.EnableRaisingEvents = true;

private void NewExecutable(object source, FileSystemEventArgs e)
{
Process.Start("c:\\services\\serviceupdate.exe","s ervice",
"newservice");
}

The above code listen to the changed and created event. When the event
occurs, serviceupdate.exe will be called to automatically update services.

3.Creating the serviceupdate.exe app. The app is a simply console
application that is used to stop the old service, replace the service file
and then restart new service. The code looks like:
static void Main(string[] args)
{
if (args.Length == 0)
return;

string oldname = args[0];
string newname = args[1];

System.ServiceProcess.ServiceController target = new
System.ServiceProcess.ServiceController(oldname);
target.Stop();

while(target.Status
!=System.ServiceProcess.ServiceControllerStatus.St opped)
{
target.Refresh();
}
Thread.Sleep(2000);

File.Delete("c:\\services\\" + oldname + ".exe");
File.Move("c:\\services\\Updates\\" + newname + ".exe", "c:\\services\\"
+ newname + ".exe");

target.Start();
}

Serviceupdate.exe needs two parameters. The first one is the name of old
services that is located at c:\seriveces in the solution. The second one
is
the name of new services that is located at c:\services\updates in the
solution. Of course, you can set the same name for the old and new service
because they are in different folder.

Another solution is to create a separate AppDomain for each unique
managed
service assembly and use Remoting to create and control the managed
service's IService implementation. There are two nice articles related to
this topic here.

http://www.15seconds.com/issue/040624.htm
http://www.15seconds.com/issue/040817.htm

Please let me know if these help for your scenario. If you have any future
questions or concerns, please let me know.
Best regards,
Ji Zhou (v-****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/...tance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
Thank you very much, just what I was looking for
Nov 3 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: laurie | last post by:
Hi all, I'm trying to help out a friend who has inherited a client with a PHP shopping cart application. Neither of us know PHP, but I've been muddling my way through, trying to get these old...
37
by: ajay | last post by:
How to make a web page getting refreshed after a given time interval automatically. HTML Code plz. Tx Ajay
2
by: joo | last post by:
Hi! I need to implement something similar to "Automatic Update" feature which we see in windows 2000. We need this support for our software, basically to provide the software update. How can I...
2
by: André Heuer | last post by:
Hi, i want to write a .net class that can update my ip address at the dyndns service (http://www.dyndns.org). When I open the page...
0
by: Eugene | last post by:
I have two window services that I created in C# and VB.net, one each, and set them to manual startup type. However, sometimes (not everytime) when I starts the service, an error message pops-up to...
2
by: Chris Langston | last post by:
I have a Web Server running IIS 5 or 6 on Windows 2K and Windows 2003 Server that is experiencing strange shutdown problems. We are using ASP.NET v1.1 and our application is written in VB.NET ...
2
by: aparnasinha26 | last post by:
Hi All, I have to develop an application .The application has to update database.It does not have any user interface.It needs to run on Windows XP/2000 automatically at a particular time say 4...
2
by: rlsj | last post by:
I noticed EXCEL can automatically update a list from SharePoint services. Is there a quick and easy way to update a list from an Access query? Is it "better" to create the code in ACCESS...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.