c# - How to restart service remotely? -


i can start or stop service remotely .net project.

connectionoptions options = new connectionoptions(); options.username = @"192.168.36.22\test"; options.password = "test"; managementscope scope = new managementscope(@"\\192.168.36.22\root\cimv2", options); scope.connect();   managementoperationobserver stop = new managementoperationobserver(); stop.completed += new completedeventhandler(stop_callback); try {     string nameservices = "arcgis server";     wqlobjectquery query = new wqlobjectquery("select * win32_service  name=\"" + nameservices + "\"");     managementobjectsearcher find = new managementobjectsearcher(scope, query);     foreach (managementobject spooler in find.get())     {         spooler.invokemethod("stopservice", new object[] { });         spooler.invokemethod(start, "stopservice", new object[] { });     }  } .... 

how can restart service?

you use servicecontroller class so:

servicecontroller sc = new servicecontroller("arcgis server", "192.168.36.22");  sc.start(); sc.stop(); 

this saves having write code interact wmi. note use servicecontroller class, you'll have add reference system.serviceprocess assembly.


Comments

Popular posts from this blog

Line ending issue with Mercurial or Visual Studio -

java - Jtable duplicate Rows -

java - Run a .jar on Heroku -