How to install a Windows Service?

#1
Background: I am a developer. I write Windows software for a living, have done for many years. And this problem has got me flummoxed :(

I've written a simple Windows service. It was working just great on Windows XP. So I ported the source code across and recompiled it. No problems experienced so far.

Then came the time to load the service and start it. And I seem to have entered a world of pain.

With XP it was pretty easy to load a service, using the Microsoft supplied InstallUtil.exe utility. Then you could use the service control manager to start/stop it at will. Well the SCM is there because I can see lots of services, but can I get my service to join the ranks? Can I **&%**.

Tried the InstallUtil trick. It doesn't want to play ball. And I have identified the right InstallUtil utility. Also installed the Windows 7 SDK and a pile of stuff has taken up residence on my hard disk.

So I have to ask the question. Given an NT service which comes as an EXE, how do I persuade Windows 7 to get that service ready for action?

Andrew
 


#2
Perhaps I was a little hasty in seeking advice. Some additional information might be useful!

The service I am trying to load in Windows 7 is my first ever WCP service, written in C#. It was working a treat for Windows XP, but in Windows 7 using exactly the same environment it just refuses to install. Herewith the text from the InstallUtil.InstallLog:

Running a transacted installation.

Beginning the Install phase of the installation.
See the contents of the log file for the D:\DotNet2008\KlintSvc\KlintSvc\bin\Debug\KlintSvc.exe assembly's progress.
The file is located at D:\DotNet2008\KlintSvc\KlintSvc\bin\Debug\KlintSvc.InstallLog.

An exception occurred during the Install phase.
System.Security.SecurityException: The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security.

The Rollback phase of the installation is beginning.
See the contents of the log file for the D:\DotNet2008\KlintSvc\KlintSvc\bin\Debug\KlintSvc.exe assembly's progress.
The file is located at D:\DotNet2008\KlintSvc\KlintSvc\bin\Debug\KlintSvc.InstallLog.

The Rollback phase completed successfully.

The transacted install has completed.
I made no changes to the service or any configuration files - I just loaded Visual Studio 2008 under Windows 7 and recompiled, and that worked fine with no complaints. But I just can't get the darn service to register in the Service Control Manager!

I feel like I'm tussling with a Tiger with a blindfold on.

Andrew
 


#3
Solved it! I think.....

I have been trying to use the CMD window which comes with Windows 7, but decided I would try again with JPSoft's Take Command - JP Software - Console and Backup Products

Still wouldn't have it. Service refused to load never mind run.

So I found the Take Command executable in Windows Explorer, right clicked it, and chose "Run as Administrator". Up comes Take Command, run the InstallUtil command (with no changes whatsoever), and the service loads no problem. It then started no problem.

So basically it looks like this was down to the new security envelope which Windows 7 implements. Now all I have to do is figure out how to implement the changes to ensure that this works all the time.

Andrew
 


#4
You can also use the CMD window under Visual Studio's Tools directory. You will need to run as administrator.
 


#5
Similar problem

I am having a similar problem. I created a basic windows service in VS 2008 (NOT a WPF service, but a "regular" service). I also created in install for it. I've done this dozens of times pre-win7, and it always works great. But with Win7, it doesn't. The installer reports that the service installed successfully. When I re-run it, the appropriate "repair or remove" options appear. But the service never shows up in the services window. What happened to the service? Why isn't it showing up?
 


#6
Re: Similar problem

KazMax, thanks man you saved my day!

Best Regards,
Vaseem.
 


This website is not affiliated, owned, or endorsed by Microsoft Corporation. It is a member of the Microsoft Partner Program.