ASP.NET Process.start 无法在 Windows Server 2012 上运行



我正在使用process.start执行schtasks.exe。在我的开发PC(Windows 10(上运行的代码在旧的Windows Server 2012上无法运行,在Windows 2012生产服务器上也无法运行。我确信这是某种权限问题,但我已经用尽了办法。我比较了IIS设置和文件管理器权限,但没有发现Windows 10和Windows Server 2012之间有任何不同,这会导致代码无法仅在服务器上运行。我们在事件日志中看到的错误是conhost.exe出错,然后是schtasks.exe出错。计划任务设置为使用具有相应密码的管理员用户运行。

以下是适用于Windows 10但在Windows Server 2012上出现故障的代码。

var proc = new Process
{
StartInfo =
{
UseShellExecute = false,
FileName = @"C:WindowsSystem32schtasks.exe",
Arguments = "/run /tn NameOfExistingScheduledTask",
UserName = "AdminUser",
Password = securePass,
RedirectStandardError = true,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
if (!proc.Start())
{
StreamReader myStreamReader = proc.StandardError;
Console.WriteLine(myStreamReader.ReadLine());
Console.WriteLine(proc.StandardOutput.ReadToEnd());
}
proc.WaitForExit();

它可能很挑剔。

FWIW我会尝试这样做。

  1. 为服务器创建一个新的服务帐户
  2. 将您的信用更改为服务帐户名称和服务帐户密码
  3. 按下Windows按钮
  4. 搜索Run
  5. 运行secpol.msc
  6. 导航到"安全设置"->本地策略->用户权限分配
  7. 双击右侧的"作为批处理作业登录">
  8. 添加您的服务帐户

最新更新