简体   繁体   中英

Windows Service application in c#

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

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

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 - eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM