By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,426 Members | 1,721 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,426 IT Pros & Developers. It's quick & easy.

Windows Service installation problem

P: n/a
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\inst allutil /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?
Jun 27 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Mika M" <mi*********************@kolumbus.fiwrote in message
news:Ol**************@TK2MSFTNGP06.phx.gbl...
...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.GetService s();
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
{

}
}
Jun 27 '08 #2

P: n/a
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" <mi*********************@kolumbus.fiwrote in message
news:Ol**************@TK2MSFTNGP06.phx.gbl...
>...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.GetService s();
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
{

}
}

Jun 27 '08 #3

P: n/a
In my case the correct event to start the service upon installation was ProjectInstaller_AfterInstall.
The event ProjectInstaller_Committed did not start the service.
Sep 19 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.