在IIS上运行的ASP站点中执行schtasks [英] Execute schtasks in a ASP site running on IIS
问题描述
我在IIS上运行了一个站点。我需要从网站运行schtasks.exe。我尝试了以下
I have a site running on IIS. I need to run the schtasks.exe from the site. I tried the following
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上托管的网站上工作。
The command when executed on cmd works fine but when I tried to execute it on a website running on IIS no task is being added. And also its working on sites that are not hosted on IIS.
编辑I:当网站的应用程序池标识设置为LocalSystem但我需要它作为网络服务时,它的工作。
Edit I: its working when the site's app pool identity is set to LocalSystem but I need it to be working as a Network Service.
缺少什么!!!
推荐答案
不是要使用的/ u和/ p。从远程机器访问它时应指定/ ru和/ rp,它们应该属于具有admin特权的用户e。命令如下:
It is not the /u and /p which is to be used. When accessing from a remote machine it should specify the /ru and /rp and they should belong to a user with admin privilege. The command is as following:
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);
这篇关于在IIS上运行的ASP站点中执行schtasks的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!