5

My PC is in Domain A and a remote server in Domain B, I want to restart a service on server from my PC using c# or any other language or script.

Notes:

  1. I am connected to the server via VPN that means i can manually RDP the server and can manually restart the service.
  2. I am not able to access services on server using connect to other computer under action button from local services window.
  3. I have admin rights to the server.
  4. I can't(not allowed) add any component to server.
  5. I have different set of credentials for Remote machine
j.w.r
  • 4,136
  • 2
  • 27
  • 29
user1675935
  • 121
  • 2
  • 11

2 Answers2

3

You should first try the sc command to make sure you're able to start that service remotely using the current permissions and credentials. If that works, take a look at System.ServiceProcess.ServiceController.

When you say you're an admin on the remote machine, I'm assuming that means you're logging in with different credentials. I don't believe either of those will allow you to use alternate credentials -- i.e., the commands will execute with Domain A privileges and those privileges are most likely insufficient for what you're trying to do.

Brenda Bell
  • 1,139
  • 8
  • 10
  • Using ServiceController I can access (stop/start/ restart) services on machines in my domain but not in Other domain. I have a different set of credentials for the other domain. I need to use these credentials to do any thing on remote machine manually(using RDP), but don't have any idea how this can be done using a windows form(without using RDP tool in .net). – user1675935 Sep 17 '12 at 02:28
  • @user1675935: I don't know if this will work and I don't have an environment where I can test it out... but have you tried using the `runas` command to launch your program? I can't locate online doc, but I believe it would be something like `runas /noprofile /netonly /user:@ `. – Brenda Bell Sep 18 '12 at 00:04
  • Brenda It worked, I tried displaying all services in server, I have not tested to restart or stop a service but I think it should also work. Thanks alot. – user1675935 Sep 22 '12 at 13:21
3

Can you use a batch file? I usually use something like this:

NET USE \\computername\IPC$ /U:domainname\username password
SC \\computername START service
Gabe
  • 84,912
  • 12
  • 139
  • 238