1

This is my first time in C#, and I was following this tutorial in order to test out a Directory Monitoring Service. The relevant installation steps is in Step 6:

http://www.rhyous.com/2012/11/27/c-creating-a-service-to-monitor-a-directory/

Step 6 – Install the Service
Open the Developer Command Prompt by right-clicking and choosing Run as   
Administrator.
In the command prompt, change to the bin\debug folder in your project 
directory.
Run this command to install the service:
installutil.exe DirectoryMonitoring.exe

Start the service with this command.
net start DirectoryMonitoringService

After following the tutorial, my service was able to install and run after building using the Visual Studio Development Console. I then updated my code a little and built it again.

I tried using the same steps to install or run the service via the VSD console again, but I get an Accessed Denied error when I try to do either commands.

I get the following error for the installation:

System.InvalidOperationException: Cannot open Service Control Manager on     
computer '.'. This operation might require other priviledges.
The inner exception System.ComponentModel.Win32Exception was thrown with the 
following error message: Access is denied.

I also get the following error for net start:

The service name is invalid.

What is going on? I was able to do everything perfectly the first time. Why is it not working now?

somethingstrang
  • 1,079
  • 2
  • 14
  • 29

1 Answers1

0

If you have the services window open, close it and then try doing the reinstall again.

Also, don't forget to uninstall the service before reinstalling it. However, in my experience, I'm pretty sure that once the service is installed just replacing the EXE with the updated service and restarting it is sufficient and I have gotten away without having to reinstall the service. YMMV.

John Hodge
  • 1,645
  • 1
  • 13
  • 13
  • Where is the exe located when I complete a debug build? I assumed by building the solution, the exe will already be replaced? – somethingstrang May 15 '15 at 02:22
  • You are correct, it should already be replaced if you installed the service from your bin\debug location, which it appears that you did. – John Hodge May 15 '15 at 02:23
  • I ended the service exe from task manager and tried again, but it still gave me the same error – somethingstrang May 15 '15 at 02:29
  • With the EXE being ended and the Services window closed, run the following command from the developer prompt in order to uninstall the service: `installutil.exe -u DirectoryMonitoring.exe` – John Hodge May 15 '15 at 02:30
  • I got an error: "System.SecurityException: Requested registry access is not allowed." How do I get around that? – somethingstrang May 15 '15 at 02:37
  • Are you absolutely sure that when you opened the command prompt you right-clicked and chose "Run as Administrator"? – John Hodge May 15 '15 at 02:38
  • 2
    Run as Administrator did the trick....God I feel stupid but lesson learned...thank you!! – somethingstrang May 15 '15 at 03:25