Friday, August 10, 2012 11:32 PM
Please need some help for Starting a Service written in C#:
- I wrote a small example of writing services with C#.
- I built the project.
- I install the service with installUtil (that I run as administrator). Is was successful.
- When I tried to start the service, I got: "Windows could not start the myService Service on Local Computer. Error 5: Access denied"
- This happens in W7 and also with XP.
- I opened the cmd box and the Service window as Admin (Run as Administrator) (local system). I also logged in as Administrator. I do not know what else to do.
Appreciate a hint
Thanks a alot
Saturday, August 11, 2012 1:48 AM
I think the "Access denied" error could be emitted by your service ifself.
Check to see if your service emit any output (including file and Windows event log), and if so, check whether the account being used to run to service have right to write to them.
If your service is supported to be run as console application or GUI program, you should try to run it directly in the account you're going to run in order to check for this possibility.
Saturday, August 11, 2012 4:50 AM
Thanks a lot Cheong. Unfortunately the problem persists.
I removed all the code in the "onStart" and "onStop" methods. The program does nothing now. However I still get the Error 5 mentioned in my first post.
Any other suggestions?
Thanks and best regards
Saturday, August 11, 2012 7:00 AM
What kind of Service you are trying to start.
Is it some application???
Saturday, August 11, 2012 7:09 AM
I am guessing it is a Window Service. can you change the account under which this service run and check how it goes
If this post is helpful, please vote as helpful. If this answers your question, please Mark as the Answer.
Saturday, August 11, 2012 7:20 AM
Add a System.Serviceprocess as reference to your solution
include headerfile as Using System.ServiceProcess
This is my part of Code where i am starting and stopping a service:Print Spooler
private void button3_Click(object sender, EventArgs e)
ServiceController startService = new ServiceController();
startService.DisplayName = "Print Spooler";
There are some services that are reluctant to start and stop because of certain restrictions such as administrator privileges or dependencies on other applications. That you need to check with system configuration.
But as of now this above piece of code will control print spooler
If you want to create a new service of your own you can refer this
With Warm Regards
- Edited by amit_kumar Saturday, August 11, 2012 7:44 AM
Monday, August 13, 2012 2:18 AM
Try use this NuGet plugin to assist debug and see if you can find anything abnormal.
It's strange that the service fails to run even if OnStart code is removed. Maybe if you still can't find source of problem, you can try posting your Main() content here.
- Marked As Answer by Lisa ZhuMicrosoft Contingent Staff, Moderator Monday, September 10, 2012 4:18 AM
Monday, August 13, 2012 8:36 AMCan you change the service account property to LocalSystem ?
programmer on .net