0

I'm struggling with starting a service from another application.

Ok, first, that's my starting point: I got a usual service wrapped into my own class which inherits from ServiceBase. Furthermore I got a ProjectInstaller instance, which inherits from System.Configuration.Install.Installer and takes care of installing my service on the system in the right way.

it's got these parameters:

serviceInstaller1.ServiceName = "NameOfService";
serviceInstaller1.StartType = System.ServiceProcess.ServiceStartMode.Manual;
serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalService;

This ProjectInstaller output is installed through a usual C# .NET installation project.

The service is shown in the GUI list of services within system control -> administration -> services. But what I'm wondering about is that the service does not appear in the list of services, if I use the cmd.exe and type "net start".

That's waht I have so far. Now I want to start my service from another application. This application inherits from

ServiceController

If I want to call now the

Start()

method, I get an error telling me that the service could not be opened of the local machine.

I use the same Service Name as stated above. T'm confused about that, because I thought the service is installed correctly through my installer. Or does my application (and the cmd.exe too) does not have enough rights to access the service?

Cœur
  • 37,241
  • 25
  • 195
  • 267
inva
  • 751
  • 2
  • 13
  • 28
  • 1
    Does the account the application runs under have permissions to start services? – Oded Oct 24 '11 at 12:33
  • it's currently the only account on the system having administrator rights, I guess it's allowed to start services, yes. Installing and Starting the service is done using the same account. – inva Oct 24 '11 at 12:39
  • Are you able to start the service manually? – Oded Oct 24 '11 at 12:40
  • yes, but only from the user Interface, not from the command line. Starting the service from the command line encounters an error telling me that the access is denied. – inva Oct 24 '11 at 12:43
  • starting the cmd.exe explicit with administrator right works fine. But I hope that there is a way to avoid the need of having administrative rights for starting a service?! – inva Oct 24 '11 at 12:45
  • Then you need to look at accounts and permissions. Access denied points to that. – Oded Oct 24 '11 at 12:45
  • hm, ok, maybe I shall point out that i'm using Windows 7. That means i'll have to say explicit using right click "start with administrative rights" that an application has administrative rights. thats a kind of tricky – inva Oct 24 '11 at 12:51

2 Answers2

1

I found this article on stackoverflow. I think this answer posted there can be applied here too.

see the link below ServiceController permissions in Windows 7

Community
  • 1
  • 1
inva
  • 751
  • 2
  • 13
  • 28
0

I've run into this issue before, and it was permissions-based for me, too. I wish that error message was a little more clear.

I'd recommend taking a look at this SO article: C#.NET: Acquire administrator rights? - it looks like there's a good tutorial about upgrading to administrative rights provided in the answers.

Community
  • 1
  • 1
Matt DeKrey
  • 11,582
  • 5
  • 54
  • 69