繁体   English   中英

在IIS上运行的ASP站点中执行schtasks

[英]Execute schtasks in a ASP site running on IIS

我有一个在IIS上运行的网站。 我需要从该站点运行schtasks.exe。 我尝试了以下

Process proc = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.FileName = @"C:\Windows\System32\schtasks.exe";
proc.StartInfo.Arguments = "/create /tn mylbat /tr MYLExe.exe /s xxx /u xxx\xxx /p xxx /sc daily;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.CreateNoWindow = false;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
proc.Start();
proc.WaitForExit();

在cmd上执行时,该命令运行良好,但是当我尝试在IIS上运行的网站上执行该命令时,未添加任何任务。 以及它在非IIS上托管的网站上的工作。

编辑I:当站点的应用程序池标识设置为LocalSystem时,它可以工作,但是我需要它作为网络服务来工作。

什么东西少了!!!

不是使用/ u和/ p。 从远程计算机访问时,应指定/ ru和/ rp,它们应属于具有管理员特权的用户。 命令如下:

            startInfo.UseShellExecute = false;
            startInfo.WorkingDirectory = @"C:\Windows\System32";
            startInfo.FileName = @"C:\Windows\System32\schtasks.exe";
            startInfo.Arguments = "/create /tn <taskname> /tr <theEXE> /ru <user> /rp <password> /sc daily ";
            startInfo.RedirectStandardError = true;
            startInfo.RedirectStandardOutput = true;
            startInfo.CreateNoWindow = false;
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            proc = Process.Start(startInfo);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM