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
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
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"
精彩评论