1

I have created a Windows Service application using c#. I have followed the steps from this msdn documentation but the service is not listing in the services section in Computer -> Manage -> Service pane.

Am I missing something? its Windows 7.

Want to run my service to check the functionality.

Thanks

RajeshKdev
  • 6,365
  • 6
  • 58
  • 80
Jibran Khan
  • 3,236
  • 4
  • 37
  • 50

2 Answers2

2

You must install the service. This can easily be done with the installutil in your .net framework folder like this:

installutil yourproject.exe

If you then want to debug the service just attach it from visual studio via "Debug" - "Attach to process". For more details see: http://msdn.microsoft.com/en-us/library/sd8zc8ha.aspx

Chief Wiggum
  • 2,784
  • 2
  • 31
  • 44
  • 1
    Tried but no success, still the service not listed in services section. – Jibran Khan May 09 '13 at 06:15
  • @JibranKhan: Your service probably does not implement a service (un)installer as a `System.Configuration.Install.Installer`. See [my related answer](http://stackoverflow.com/a/16293612/1810429) or the [Code Project article](http://www.codeproject.com/Articles/14353/Creating-a-Basic-Windows-Service-in-C) linked therein for more info; or just use `sc create` as I describe in my answer to this question. – J0e3gan May 09 '13 at 06:34
1

You need to install your service for the Windows Service Control Manager (SCM) to know about it (by virtue of a resulting registry entry).

You have (at least) two options to do this:

sc create "SERVICENAME" binpath = "C:\whatever\Service.exe"

installutil "C:\whatever\Service.exe"

For sc create, any command prompt should do. For installutil, Visual Studio Command Prompt is the easiest way to run it - since the VS Command Prompt's PATH environment variable makes using .NET command-line tools easy; and your service needs to implement a service (un)installer in my experience.

After you install and reality check your service, you will almost certainly want to uninstall it at some point - e.g. to then install a final version of it in a non-dev location or to just clean up dev service entries littering your list of installed services. You have corresponding options in sc delete and installutil /u - with the same caveats I explained above regarding installation options.

I have written more about some subtleties of uninstalling & installing Windows services that you might find interesting and/or helpful - particularly implementing a service (un)installer if you decide to take that route.

Community
  • 1
  • 1
J0e3gan
  • 8,740
  • 10
  • 53
  • 80
  • Great ! this did it, listing in the services pane now. When i start the service it says that service started but stopped due to not in use by any other program or service? How i can test the service working ? – Jibran Khan May 09 '13 at 06:37
  • @JibranKhan: Glad to hear it. Kindly mark my answer accepted if you would. I will follow up with a comment to point you in the right direction to test your service now. – J0e3gan May 09 '13 at 06:44
  • @JibranKhan: If your service writes to a DB or file(s), the easiest way to test it is to look for output in the DB or file(s). Services do not usually have a UI lean to them by nature; but you can also configure your service to interact with the Windows desktop if it runs as Local System (Administrative Tools > Services, then the Log On tab in your service's properties) so that you can show message boxes (i.e. `MessageBox.Show`) for reality checks. A bit cleaner, you can also write info events to a Windows event log or debug output that you can pick up with Sysinternals DebugView (free). – J0e3gan May 09 '13 at 06:54