Windows Service installation problem

M

Mika M

I'm programming quite simple Windows Service using C# 2005. I also made
setup for it into same solution.

When I run setup to install service, it's going fine into C:\Program
Files\MyCompany\My Service, and Event Log tells...

Event Type: Information
Event Source: MsiInstaller
Event Category: None
Event ID: 11707
Date: 11.6.2008
Time: 10:37:28
User: ...\...
Computer: MYCOMPUTER
Description:
Product: My Service -- Installation completed successfully.

For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.

....but when I check Computer Management/Services, it is not there in
services list!


I made earlier another service same way, and it installed that service
into services list fine (but is not starting the service automatically).
When I'm comparing these services, I don't find what is wrong with this
new service intallation.

Anyway I can install this new service into services list using
C:\Program Files\MyCompany\My Service\install.bat-file containing...


@ECHO OFF
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\installutil /i MyService.exe

NET START MyService
PAUSE

and then the Event Log tells...

Event Type: Information
Event Source: MyService
Event Category: None
Event ID: 0
Date: 11.6.2008
Time: 10:54:44
User: N/A
Computer: MYCOMPUTER
Description:
Service started successfully.

For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.


Any succestions what might be wrong with my installation?
 
C

Claire

Mika M said:
...but when I check Computer Management/Services, it is not there in
services list!
I made earlier another service same way, and it installed that service
into services list fine (but is not starting the service automatically).
When I'm comparing these services, I don't find what is wrong with this
new service intallation.

1) First, did you add a project installer to your service?
To do this in VS2005, have service1.cs (or whatever your service1.cs file
was renamed as) open in the design mode window. Right click on it and select
"Add Installer" from the context menu. This 2nd installer installs your
service into windows services when the main application setup is run.
Doing this causes file ProjectInstaller.cs file to be added to the project.
Double click that in solution explorer to show design window (if it's not
already open) and you'll see a blank page with 2 embedded controls,
serviceProcessInstaller1 and serviceInstaller1.
Set the properties for serviceInstaller1 and serviceProcessInstaller1 as you
like. (I have serviceProcessInstaller1.Account set to LocalMachine for
accessing my database and serviceInstaller1.ServiceName set to
myservice.service, set serviceInstaller1.Description to some useful text to
describe your service)
That should be enough to get your service installed in windows services.

2) To make run your service after installation...
Open the file "ProjectInstaller.cs" in design view. Select the "background"
in the designer window (not the embedded controls) and switch to the events
section of the property editor. Double click the "Committed" event to
generate an event handler in the code.
The following code works on my installation

private void ProjectInstaller_Committed(object sender, InstallEventArgs
e)
{
try
{
// Change the following to your service name. Should be
serviceInstaller1.ServiceName
string servicename = "myservice.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();
}
}
catch
{

}
}
 
M

Mika M

Thanks for the reply!

My setup project was only missing "Custom Actions". That was why it
didn't install my application into services list. I noticed it by myself
at last.

That is good to know how to start service after installation! I'll try
it on monday.
--

Claire kirjoitti:
Mika M said:
...but when I check Computer Management/Services, it is not there in
services list!
I made earlier another service same way, and it installed that service
into services list fine (but is not starting the service
automatically). When I'm comparing these services, I don't find what
is wrong with this new service intallation.

1) First, did you add a project installer to your service?
To do this in VS2005, have service1.cs (or whatever your service1.cs
file was renamed as) open in the design mode window. Right click on it
and select "Add Installer" from the context menu. This 2nd installer
installs your service into windows services when the main application
setup is run.
Doing this causes file ProjectInstaller.cs file to be added to the
project. Double click that in solution explorer to show design window
(if it's not already open) and you'll see a blank page with 2 embedded
controls, serviceProcessInstaller1 and serviceInstaller1.
Set the properties for serviceInstaller1 and serviceProcessInstaller1 as
you like. (I have serviceProcessInstaller1.Account set to LocalMachine
for accessing my database and serviceInstaller1.ServiceName set to
myservice.service, set serviceInstaller1.Description to some useful text
to describe your service)
That should be enough to get your service installed in windows services.

2) To make run your service after installation...
Open the file "ProjectInstaller.cs" in design view. Select the
"background" in the designer window (not the embedded controls) and
switch to the events section of the property editor. Double click the
"Committed" event to generate an event handler in the code.
The following code works on my installation

private void ProjectInstaller_Committed(object sender,
InstallEventArgs e)
{
try
{
// Change the following to your service name. Should be
serviceInstaller1.ServiceName
string servicename = "myservice.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();
}
}
catch
{

}
}
 
A

Arthur Z

In my case the correct event to start the service upon installation was ProjectInstaller_AfterInstall.
The event ProjectInstaller_Committed did not start the service.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top