views:

71

answers:

2

Hi there,

I've built a Windows Service in C# using Visual Studio 2008. I've built it, navigated to the folder in which it's stored using the Visual Studio command prompt, and used the command: installutil MyWindowsService.exe. It installs just fine and I can see it in the services manager. However, when I go to run it, it will not execute any of my code. The code is supposed to send an email to my Gmail address confirming that it actually works. I've tested this code in a console application and it work just fine. The Service will not execute it, however.

Any ideas on what I should try?

Thanks in advance.

+4  A: 

Check Event Viewer for errors. If that doesn't lead to the problem, add Debugger.Break() in your OnStart() method so you can attach a debugger as soon as the service starts up.

Sam
+2  A: 

Under what account permissions is the service installed to? If it's Local Service, that might explain your issue as I don't believe Local Service is allowed Network Access. If you require network access, then you need to use Network Service for the service user, but be aware that you give up certain admin rights for that service on the local box when you do that.

As part of the Service trust model, you can have really good right on the local machine with no network rights, or network rights with severely restricted rights on the local machine.

If you need both, then you'll have to have your service run as a locally created user where you can control the rights yourself.

Nick
Turns out what happened was that the user account it was installed under (LocalHost) does not allow network connections. You were exactly right. Thank you.
Sam Youtsey