次のように、サービス コントローラーの executecommand 関数を使用しています。
ServiceController serviceController = new ServiceController("a Service",
Environment.MachineName);
serviceController.ExecuteCommand(129);
そして、サービスコントローラーで:
protected override void OnCustomCommand(int command)
{
base.OnCustomCommand(command);
// Depending on the integer passed in, the appropriate method is called.
switch (command)
{
case 129:
RestartSpooler();
break;
case 131:
InstallPrinter();
break;
case 132:
DeletePrinter();
break;
}
}
ただし、呼び出し元のコードからコマンドを呼び出しても (コードが行にヒットし、ステップオーバーし、例外は発生しません)、何も起こりません。なんで?これはすべてローカル マシン上にあり、私には完全な管理者権限があります。
ありがとう