Click here to Skip to main content
13,249,504 members (56,596 online)
Rate this:
Please Sign up or sign in to vote.

I have InvalidOperationException for an unknown reason to me. The code worked fine in an ad hoc network, but when you upgrade to Active Directory, I got this problem.

I have sufficient access rights. Windows tool "Services" give me the opportunity to change the status of services. However, I am InvalidOperationException when you try to do this with ServiseController.

a simple example:
ServiceController sc = new ServiceController(@"SomeService", @"SomeMachine");

Here I get an instance of service with all members values.

if (sc.Status == ServiceControllerStatus.Runing)

update and read state as well.


But (and any other attempt to change the state) are getting an InvalidOperationException.

Can you please tell what are the possible reasons for this execution of the code wiht fine working Services tool.

Thank you very much.
Posted 29-Jun-12 4:40am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I believe the issue here is one of permissions. I know you stated you have the necessary permissions, but that doesn't mean your application does. First, if you are running on Windows 7, you will need to make sure you are running your app as administrator (the mode, not just logged in as admin).

Next, you might need to look at impersonation. It looks like this Stack Overflow question describes a similar issue and it has a listed solution:[^]

Here is another one with code listed:[^]
Labilis 2-Jul-12 12:50pm
You are right. It was in Windows 7 UAC. Run as administrator gave me the necessary authority. Thank you and I apologize for that.
But after there was another difficulty associated with the need to request necessary execution mode.
All described variants describe the manipulation of the application manifest.
(like this
And no more ways I have not found
But change the requestedExecutionLevel in manifest on any different from asInvoker gives me the error "does not support the request execution level <level>"
Could you tell me, please, how i can solve this?
Labilis 2-Jul-12 16:16pm
Found. Thank you any way.
Tim Corey 2-Jul-12 16:25pm
Great. Glad you figured it out. If you wouldn't mind, could you please accept this answer so that others that look at this question later know that it isn't still an issue? Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.171114.1 | Last Updated 29 Jun 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100