C# run powershell script (remote start/stop service) -
in c# have script, remotely stops , start service. problem is, work stop service.
i need start/stop service, because service must stopped else. may not servicecontroller, because have disabled wmi.
initialsessionstate initial = initialsessionstate.createdefault(); runspace runspace = runspacefactory.createrunspace(initial); runspace.open(); powershell ps = powershell.create(); ps.runspace = runspace; ps.addcommand("get-service"); //stop ps.addparameter("computername", textbox7.text); ps.addparameter("name", "spooler*"); ps.addcommand("stop-service"); ps.addparameter("force"); //ps.addcommand("remove-item"); //queue ps.addcommand("get-service"); //start ps.addparameter("computername", textbox7.text); ps.addparameter("name", "spooler*"); ps.addcommand("start-service"); ps.invoke();
oh, found solution: need add.statement between commands.
ps.addcommand("get-service"); ps.addparameter("computername", textbox7.text); ps.addparameter("name", "spooler*"); ps.addcommand("stop-service"); ps.addparameter("force"); ps.addstatement(); ps.addcommand("get-service"); ps.addparameter("computername", textbox7.text); ps.addparameter("name", "spooler*"); ps.addcommand("start-service");
wiki
Comments
Post a Comment