IIS 7.5 でホストされている WCF サービスに、呼び出されたときにコンピューターをシャットダウンまたは再起動する機能があります。
組み込みのコマンドラインを使用し、「shutdown.exe -t 0 -r」を渡して再起動するか、「shutdown.exe -t 0 -s」を渡してシャットダウンします。
Try
Using process As New System.Diagnostics.Process()
Dim startInfo As New System.Diagnostics.ProcessStartInfo()
With startInfo
.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden
.CreateNoWindow = True
.UseShellExecute = False
.RedirectStandardError = True
.RedirectStandardInput = True
.RedirectStandardOutput = True
.FileName = "shutdown.exe"
.Arguments = "-t 0 -r"
End With
If System.Environment.OSVersion.Version.Major >= 6 Then process.StartInfo.Verb = "runas"
process.StartInfo = startInfo
process.Start()
process.WaitForExit()
If process.ExitCode = 0 Then
Return True
Else
Return False
End If
End Using
Catch ex As Exception
Return False
End Try
コマンドプロンプトで手動で実行すると、コマンドラインは正常に機能します。ただし、WCF サービス内で実行されている場合は機能しません。