Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

How to deploy and start Windows Service?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mika M - 13 Mar 2008 09:56 GMT
I'm doing Windows Service programming using C# 2005. My solution
contains Windows Service project. Then I added Setup and Deployment
project into the same solution. Both service- and Setup and Deployment
project are working fine. After running setup, it made files into the
C:\Program Files\MyCompany\MyService, but how can I install service into
the services and start this service using only Setup and Deployment project?

Now I can do this using install.bat-file containing...

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\installutil /i MyService.exe
NET START MyService

...and uninstall it using ininstall.bat-file containing...

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\installutil /u MyService.exe

Or am I doing this correct way at all? What is the correct way to
install this kind of service easily?

--
Thanks in advance!

Mika
Claire - 13 Mar 2008 10:15 GMT
Go into visual studio help and look for "services, adding installers"

In my vis studio 2005 help it's at url
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_radcon/html/8b698e9a-b88e-4f44-ae45-e0c5ea0ae5a8.htm
I've not worked out yet how to get the service to start after installation,
so if you work it out then please post back here lol
Mika M - 13 Mar 2008 10:44 GMT
My deployment project was missing Custom Actions. I found instructions
of the address http://support.microsoft.com/kb/816169

Now it's going into services ok, but I'm having the same problem as you
- how to start this service using only Setup and Deployment project without:

1. booting computer
2. or going into Start/Control Panel/Administrative Tools/Services and
start it there.
3. or using NET START MyService -command

thanks for the tip anyway!

Claire kirjoitti:
> Go into visual studio help and look for "services, adding installers"
>
> In my vis studio 2005 help it's at url
> ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_radcon/html/8b698e9a-b88e-4f44-ae45-e0c5ea0ae5a8.htm
> I've not worked out yet how to get the service to start after installation,
> so if you work it out then please post back here lol
Claire - 13 Mar 2008 12:05 GMT
Hi again :)
Try adding something like the following into the OnInstalled/Committed event
of your ProjectInstaller class. I've only tested the following inside a
regular form so far as Im not quite sure which event I should be trapping

using System.ServiceProcess;

[RunInstaller(true)]
public partial class ProjectInstaller : Installer
{
public ProjectInstaller()
{
InitializeComponent();
}
private void ProjectInstaller_Committed(object sender, InstallEventArgs e)
{
string servicename = "my.service";
System.ServiceProcess.ServiceController[] services;
services = System.ServiceProcess.ServiceController.GetServices();
bool Found = false;
foreach (ServiceController sc in services)
if (string.Compare(servicename, sc.ServiceName, true) == 0)
 Found = true;
if (Found)
{
ServiceController Controller = new ServiceController(servicename);
if (Controller.Status == ServiceControllerStatus.Stopped)
Controller.Start();
}
}
}

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.