C#ではリモートでサービスを停止してサービスを開始するスクリプトがあります。 問題は、作業停止サービスだけです。C#でPowerShellスクリプトを実行する(リモート起動/停止サービス)
サービスは何かのために停止する必要があるため、開始/停止サービスが必要です。 WMIが無効になっているため、ServiceControllerではない可能性があります。
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();
引用:「**私はWMIを無効にしているため、ServiceController **でない可能性があります。」 – Fildor