Kjell Liljegren

Kjell Liljegren

  • NA
  • 6
  • 23.9k

ServiceController under alternative user login

Oct 8 2010 9:24 AM

Hi all
Ref: Visual Studio 2008 (C#), windows application project for a Win2003 domain environment.
I'm having  a problem with System.ServiceProcess.ServiceController class if I want to run this under an alternative user credentials, It seems not be a simple way to do this.
If possible I would like to use the ServiceController class because it provides really nice implementations for handling all needed operations when it comes to operate Services, especially dependencies.
I've tested it running as a member of Domain admins and it works great, much easier than using WMI (ManagementObject...)
On the other hand, WMI provides a way to "run as" by adding a ConnectionOptions to the Scope object
I also tried Impersonation using a class created on the article http://support.microsoft.com/default.aspx?scid=kb;en-us;Q306158
The impersonation process works, but now the ServiceController fails due to privileges!?! and I was impersonating the domain Administrator himself.  Exception is: System.InvalidOperationException,  Text: Cannot open Service Control Manager on computer 'TESTPC'. This operation might require other privileges.
So my questions are.
Is it possible within .NET to use the ServiceController under alternative credentials?
if not, Is there another approach for using impersonation that will work with ServiceController class?
and finally if that's not available, any tip on where I can find WMI example (using .NET ManagementObject classes) on how to handle Services for both "Role=Dependent" and "Role=Antecedent"
I can post code if you think it should work as described.
Best regards and thanks in advanced
Kjell

Answers (1)