TaskKill /F /FI "Services eq [service name as diplayed in the service's properties]"This will get your process knocked off so that you can resume debugging and building.
Showing posts with label windows services. Show all posts
Showing posts with label windows services. Show all posts
Wednesday, August 14, 2013
Journey to robust windows services: killing a service that failed during OnStartup and now won't stop (even though Stop() has been called)
I've found that sometimes I don't exactly get my service configuration right the first time, and this can cause a failure when calling OnStartup. As a result, when I call Stop() during the exception handling in OnStartup(), the service gets stuck in the 'Stopping' state in the services manager. Here's a quick command line to help you out with that :
Tuesday, January 15, 2013
Journey to robust Windows Services
Because I have the need for it in several projects, I'm going to be working with Windows Services implemented with .NET quite a bit in the next little while. That said, I'd like to refer to some resources for working with Windows Services:
- The MSDN page on creating windows services
- The MSDN page on debugging a Windows Service
- The MSDN page on installing and uninstalling Windows Services
Also, there are some issues that I ran into while working on my first service. I had originally planned to expose a WCF endpoint through WS-HTTP, however, I can into an unpleasant exception when I tried to do so: AddressAccessDeniedException. Apparently, the cause of this is the fact that http bindings are reserved for processes run as administrators. Fool me once, shame on me. In light of that fact, I'm switching over to using net.tcp for my local Windows Service-hosted WCF service. I'll post more here as I learn it.
Adding the Network Service account to the permissions for a file/folder/registry key etc
I'm currently developing a Windows Service that's to be run under the Network Service account (owing to the fact that it requires substantial network access). I'm just starting to learn how to program Windows Services, so this is very new to me. I just started developing a simple service to start, and when I followed the instructions on this MSDN page, I was surprised when, after trying to start my service, I got the error 005: Permission denied. I later found out that I needed to give the network service account to the folder from which the service was running, i.e. the debug output folder of my project. Doing this isn't as simple as setting the permissions for other users. To add the network service account to the permissions list in Windows 7, do the following :
- Right click on the folder containing the service you want to debug, and go to Properties
- Go to the Security tab, and under the box marked "Group or user names", click on Edit ...
- Under the window that pops up, you'll see another box marked "Group or user names". Underneath that box, click on Add ...
- In the "Select Users or Groups" dialog that pops up, click on the Advanced... button at the bottom left.
- In the advance "Select Users or Groups" dialog that pops up, click on Find Now to find all the users, groups and built in security principals.
- Once the search results are populated, scroll down and select "NETWORK SERVICE" (not "NETWORK") and click on Ok, then Ok again in the Select Users or Groups dialog.
- One you're back to the Permissions window, ensure that you give the Network Service account Full Control over the folder in the Permissions box, then click Ok.
- Click Ok one last time to close the properties for your folder, and you're done.
Subscribe to:
Posts (Atom)