System.Diagnostics.Process を使用して、Web サービス内から Windows Server 2003 を再起動しようとしています。
public static string Dorestart()
{
var si = new Process();
si.StartInfo.UserName = "administrator"; // Credentials of administrator user
var sc = new SecureString();
foreach (char c in "AdminPassword")
{
sc.AppendChar(c);
}
si.StartInfo.Password = sc;
si.StartInfo.UseShellExecute = false;
si.StartInfo.FileName = "cmd.exe";
si.StartInfo.Arguments = "\"c:\\windows\\system32\\shutdown.exe\" -r -f -t 0 -c \"Restart Reason\" -d p:4:1";
si.StartInfo.CreateNoWindow = true;
string res = "";
try
{
si.Start();
si.WaitForExit();
res = "Minor Job done... wait 2 minutes to complete action";
}
catch (Exception ex)
{
res= ex.Message;
}
si.Close();
si.Dispose();
return res;
}
ファイル名と引数部分については、これもテストしました:
si.StartInfo.FileName = "shutdown.exe";
si.StartInfo.Arguments = "/r /f /t 0 /c \"" + UReason + "\" /d p:4:1";
RUN コマンドから直接ファイル名と引数を使用すると、実際には PC が再起動されますが、Web サービスでは次のエラーが発生します。
サーバー デスクトップ: アプリケーションが正しく初期化されません (0xC0000142)。[OK] をクリックしてアプリケーションを終了します。
イベントログには次のようなものがあります:
Process information:
Process ID: 2676
Process name: w3wp.exe
Account name: NT AUTHORITY\NETWORK SERVICE
Exception information:
Exception type: HttpException
Exception message: Request timed out.
Request information:
Request URL: http://mywebsite.com/webservice.asmx
Request path: /webservice.asmx
User host address: <IP Address>
User:
Is authenticated: False
Authentication Type:
Thread account name: NT AUTHORITY\NETWORK SERVICE
Thread information:
Thread ID: 7
Thread account name: NT AUTHORITY\NETWORK SERVICE
Is impersonating: False
Web アプリケーションではエラーはありません。
この問題を修正し、Web サービスを再起動できるようにする方法を教えていただければ幸いです。