tags:

views:

105

answers:

2

Hi,

I have requirement to restart MSDTC service on a remote server throw code of my application . Could you please help me through a code example.

Thanks and Regards ShaBeg

A: 

You can use the SC or Netsvc tools as described in this technet article.

sc \\machine stop "Distributed Transaction Coordinator"
sc \\machine start "Distributed Transaction Coordinator"
Oded
A: 

This should do the trick

System.ServiceProcess.ServiceController sc = 
    new System.ServiceProcess.ServiceController("Distributed Transaction Coordinator", "MachineName");
sc.Stop();
sc.Start();

The account under which the code is running will need to have admin rights on the remote box though. If not, you can do impersonation before running the code to impersonate a user with admin rights on the remote box.

MSDN info on the ServiceController class:
http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicecontroller.aspx

Tallek