473,626 Members | 3,365 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 11076
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\upd ates 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.e xe is located at c:\services\ for updating a
services automatically
Now, the solution is described as the following steps:

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

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

2.Listen to the Created or Changed event of the FileSystemWatch er instance,
the code looks like:
//the following code is put in the method IntializeFileSy stemWatcher()
newexe.Created += new FileSystemEvent Handler(NewExec utable);
newexe.Changed += new FileSystemEvent Handler(NewExec utable);
newexe.EnableRa isingEvents = true;

private void NewExecutable(o bject source, FileSystemEvent Args e)
{
Process.Start(" c:\\services\\s erviceupdate.ex e","service" ,
"newservice ");
}

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

3.Creating the serviceupdate.e xe 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.ServiceP rocess.ServiceC ontroller target = new
System.ServiceP rocess.ServiceC ontroller(oldna me);
target.Stop();

while(target.St atus
!=System.Servic eProcess.Servic eControllerStat us.Stopped)
{
target.Refresh( );
}
Thread.Sleep(20 00);

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

target.Start();
}

Serviceupdate.e xe 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\upd ates 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.mic rosoft.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****@microsof t.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.mic rosoft.comwrote in message
news:%2******** ********@TK2MSF TNGHUB02.phx.gb l...
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\upd ates 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.e xe is located at c:\services\ for updating a
services automatically
Now, the solution is described as the following steps:

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

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

2.Listen to the Created or Changed event of the FileSystemWatch er
instance,
the code looks like:
//the following code is put in the method IntializeFileSy stemWatcher()
newexe.Created += new FileSystemEvent Handler(NewExec utable);
newexe.Changed += new FileSystemEvent Handler(NewExec utable);
newexe.EnableRa isingEvents = true;

private void NewExecutable(o bject source, FileSystemEvent Args e)
{
Process.Start(" c:\\services\\s erviceupdate.ex e","service" ,
"newservice ");
}

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

3.Creating the serviceupdate.e xe 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.ServiceP rocess.ServiceC ontroller target = new
System.ServiceP rocess.ServiceC ontroller(oldna me);
target.Stop();

while(target.St atus
!=System.Servic eProcess.Servic eControllerStat us.Stopped)
{
target.Refresh( );
}
Thread.Sleep(20 00);

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

target.Start();
}

Serviceupdate.e xe 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\upd ates 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.mic rosoft.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****@microsof t.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
3262
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 scripts working on a new server with the most recent version of PHP. I've pretty much taken care of all the various errors that were popping up. Most only pointed out out non-fatal undefined or assumed variables. I've been able to cure most of...
37
12724
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
3057
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 exploit .Net technology to implement this? Any idea on this? Thanks.
2
14940
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 https://username:password@members.dyndns.org/nic/update?system=dyndns&hostname=MyHostNameHere&myip=MyCurrentIpHere&wildcard=on I get the response nochg 80.146.122.175 which means "No change". IP hasn´t changed. Fine.
0
4006
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 say the service started and stopped automatically. ----------------------------------------------------------------------------------------------- The dicer service on Local Computer started and then stopped. Some services stop automatically if...
2
4576
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 Here's the scenario: 1. .NET Windows Client on a remote machine makes a web service call to update tables on a Web Server running SQL Server 2000. 2. The Update is updating about 1000 - 3000 records doing simple update statements like "Update...
2
2247
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 p.m. daily. I have to develop the application in VB.net My first question is which Visual Basic.Net Project type do I use- Windows Service Or Class Library? Second Question is What are the necessary initial steps I have to take during development?...
2
2584
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 and reference excel or to create the code in EXCEL and reference access? My Software: Microsoft Windows XP Professional Version 2002 w/Service Pack 2 Microsoft Office Professional Edition 2003 Access 2003 (11.5614.5703)
0
8196
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8705
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8637
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7193
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4092
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4197
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1808
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1511
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.