Click here to Skip to main content
15,507,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to stop a windows service in a server(on different domain) from my C#.NET windows application using ServiceController I am getting following error

Inner Exception: <br />
{"Access is denied"}<br />
Exception Message: <br />
"Cannot open Service Control Manager on computer 'x.y.z.a'. This operation might require other privileges."<br />
Enviroment:<br />
      Windows application running on Windows 7, C#.NET, 3.5 on "ABC" DOMAIN <br />
      Target service running on Windows 2003 server. on "XYZ" DOMAIN<br />
      Port 445,135 opened between two systems<br />
Code:<br />
      ServiceController lo_WinSC = new ServiceController();<br />
      lo_WinSC.MachineName = "SYSTEMIPAddress";<br />
      lo_WinSC.ServiceName = "ServiceToBeStopped";


Some forum suggesting to impersonate account of target domain but failed to Impersonate. Error:

The security database on the server does not have a computer account for this workstation trust relationship.


Question 1: Is it possibile to impersonate account of different domain. i.e My application running on "XYZ" domain, I would like to impersonate an account "ABC" domain. Note: Port LDAP port 389 is opened between two systems. Is possbile, help me with the above error. If not, any suggestions for my primary problem.

Question 2: For impersonating any specific port needs to be opened between application system and Domain controller/target server.

Question 3: Is there any other way to solve my primary problem or Is there any way to pass login credential in ServiceController.
Posted
Updated 25-Aug-10 3:34am
v3
Comments
#realJSOP 25-Aug-10 8:35am    
Try to put a little effort into making sure your question is presented in such a way as to make it readable, and stop using the funky quote characters. They come across as upper-ascii characters and bork up the display.

Question 3:

Maybe look into PsExec

http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx[^]

This would certainly let you stop a service on a remote computer, you can pass in credentials valid on the remote domain + password etc. I've used this internally for automated build + deploy processes.

Possibly security issues you need to consider in this scenario, if you pass user credentials they are passed plain text
 
Share this answer
 
You can't access Service Controller related permission on remote machine even if you impersonate with administrator privileges.

I got another solution for this:
Do the web service with Service Controller implementation and host on the remote machine with the necessary permissions. So you get Primary privileges for service controller related access.

Now add web service reference in your Windows application project and invoke the service method. The web service will take care of service start and stop.
 
Share this answer
 
v2
Thank you. but i am looking for a agent less solution
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900