Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.NET Process.start赢得';无法在Windows Server 2012上运行_C#_Asp.net_Windows Server 2012 R2_Windows Task Scheduler - Fatal编程技术网

C# ASP.NET Process.start赢得';无法在Windows Server 2012上运行

C# ASP.NET Process.start赢得';无法在Windows Server 2012上运行,c#,asp.net,windows-server-2012-r2,windows-task-scheduler,C#,Asp.net,Windows Server 2012 R2,Windows Task Scheduler,我正在使用process.start执行schtasks.exe。在我的开发PC(Windows 10)上运行的代码既不能在旧的Windows Server 2012上运行,也不能在Windows 2012生产服务器上运行。我确信这是某种权限问题,但我已经用尽了尝试的方法。我比较了IIS设置和文件管理器权限,但没有发现Windows 10和Windows Server 2012之间有任何不同,这会导致代码仅在服务器上无法工作。我们在事件日志中看到的错误是conhost.exe出错,然后是scht

我正在使用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:\Windows\System32\schtasks.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();
它可能很挑剔

我想尝试的方式是这样

  • 为服务器创建新的服务帐户
  • 将您的凭据更改为服务帐户名和服务帐户密码
  • 按Windows按钮
  • 搜索跑步
  • 运行secpol.msc
  • 导航到安全设置->本地策略->用户权限分配
  • 双击右侧的“作为批处理作业登录”
  • 添加您的服务帐户

  • 谢谢你Zounds博士-我真的很感谢你花时间来帮助我。就在今天,我放弃了让它发挥作用。相反,我正在将事件写入Windows事件查看器。我正在使用该事件触发计划任务的开始。有点混乱,但我没有沮丧。我保留了所有的非工作代码,以备将来使用。我会遵守你的建议。希望下一个站在我的立场上的人现在能把你的解决方案放在手边。再次感谢。