php服务器端schtasks.exe命令

php服务器端schtasks.exe命令,php,html,server-side,windows-task-scheduler,Php,Html,Server Side,Windows Task Scheduler,作为一个海报,我对这个网站还不熟悉,但在我为我的项目研究新方法的过程中,我已经使用了很长一段时间。我似乎找不到我当前项目所需的信息,很可能是因为我没有正确地进行搜索。我希望你们能给我指出一个方向,让我得到答案 问题: 我在一家用户遍布全球的公司工作,必须记住,我们的全球用户无法看到所有可用数据。考虑到这一点,我有一个系统,其中一些计划任务是由我们的一些全球用户设置的,然后该系统仅限于我们的用户。一旦在系统上设置了此限制,用户就无法访问这些计划任务,不幸的是,这些任务必须保留在此系统上 为了解决这

作为一个海报,我对这个网站还不熟悉,但在我为我的项目研究新方法的过程中,我已经使用了很长一段时间。我似乎找不到我当前项目所需的信息,很可能是因为我没有正确地进行搜索。我希望你们能给我指出一个方向,让我得到答案

问题: 我在一家用户遍布全球的公司工作,必须记住,我们的全球用户无法看到所有可用数据。考虑到这一点,我有一个系统,其中一些计划任务是由我们的一些全球用户设置的,然后该系统仅限于我们的用户。一旦在系统上设置了此限制,用户就无法访问这些计划任务,不幸的是,这些任务必须保留在此系统上

为了解决这个问题,我的任务是设置一个内部web应用程序,我们的全球用户可以访问该应用程序,该应用程序将显示计划任务信息,并允许用户在需要时手动运行任何任务。请记住,当用户运行任务时,命令将需要来自承载站点的服务器,因为它将使用对服务器具有管理员访问权限的用户帐户(域帐户),并且可以运行任务,因为全局用户无权访问此系统

我目前已经完成了大部分工作。我有一个很好的PHP页面,它遍历一个填充了计划任务名称的数组,在服务器上运行SCHTASKS.EXE命令(带有必要的参数和开关),并检索每个任务的信息。然后,它对数据进行排序,并以表格格式显示所需的数据,供用户查看。我还为表的每一行上的每个任务创建了一个基本按钮

这是我正在讨论的问题。如何配置此按钮和PHP页面,以告诉服务器运行SCHTASKS.exe/run命令(同样,来自服务器而不是用户系统)以运行任务

这可能吗?在过去的几个小时里,我一直在做这件事,只是为了走到死胡同

我对PHP相当陌生,所以我一直在学习

抱歉这么冗长的解释,我只是想弄清楚我在这里想做什么。我希望我没有过度解释任何事情

这是我到目前为止的代码。我需要使用AJAX还是其他什么

<?php
//Create colors for table
$success_color ="#E68080";         //row color when machine is occupied (light green)
$failed_color="#91FF6C";   //row color when machine is available (light red)

//Declare array with task names
$tasknames = array("\"TASK1\"", "\"TASK2\"");
//Declare array with TASK log network share
$tasklogs = array("\\\Task1Log\share", "\\\Task2Log\share");
//count the number in array
$numberoftasks = count($tasknames);

//Create table and column headers
echo '<table border ="1" cellpadding="5" cellspacing="0" style="border: 1px solid #c0c0c0;">';
echo '<tr>';
    echo '<th>Task Name</th>';
    echo '<th>Status</th>';
    echo '<th>Next Run Time</th>';
    echo '<th>Last Run Time</th>';
    echo '<th>Last Result</th>';
    echo '<th>Trigger</th>';
    echo '<th>Run As User</th>';
    echo '<th>Run Task</th>';
    echo '<th>Logs</th>';
echo '</tr>'; 
echo '<br><br>';

//Loop to create the rest of the table rows with Task information retrieved from system
for($x = 0; $x < $numberoftasks; $x++){
    $status = "0";
    $schtasksinst = "schtasks.exe /S SystemName /Query /TN $tasknames[$x] /FO LIST /V";
    $runtaskinst = "schtasks.exe /S SystemName /Run /TN $tasknames[$x]";
    exec($schtasksinst, $output);

//If statement to assign the appropriate color to a row based on if the task run successfully or had issues 
if ($status = (substr($output[8], 38))){
    $color = $success_color;
} else {
    $color = $failed_color;
}

//Fill table with Task info
    echo '<tr style="background: '.$color.';">';
    echo "<td>".substr($output[3], 39)."</td>";
    echo "<td>".substr($output[5],8)."</td>";
    echo "<td>".substr($output[4], 15)."</td>";
    echo "<td>".substr($output[7], 15)."</td>";
    echo "<td>0x".substr($output[8], 38)."</td>";
    echo "<td>".substr($output[20], 15)."</td>";
    echo "<td>".substr($output[16], 13)."</td>";
    echo "<td><button type=\"button\" onclick=\"???????????????????????????????\">Run Task</button></td>";
    echo "<td>".$tasklogs[$x]."</td>";
    unset($schtasksinst);
    unset($runtaskinst);
    unset($output);
}

\\End table as all info has been displayed
echo '</table>';
echo '<br><br>';

\\Create basic table as color legend
echo "<H2>Color Legend</H2>";
echo '<table border ="1" cellpadding="5" cellspacing="0" style="border: 1px solid #c0c0c0;">';
echo '<tr>';
echo '<td>Scheduled Task is either running or encountered an issue on it\'s last run:</th>';
echo '<td BGCOLOR=' . $success_color . '>' . str_repeat('&nbsp;', 30) . '</th>';
echo '</tr>';
echo '<tr>';
echo '<td>Scheduled task ran with no issues:</th>';
echo '<td BGCOLOR=' . $failed_color . '>' . str_repeat('&nbsp;', 30) . '</th>';
echo '</tr>';
echo '</table>';

?>

以下是我最终如何解决这个问题的。我现在可以按预期操作按钮了

<form action="runtask.php" method="post">

<?php
//Create colors for table
$success_color ="#E68080";         //row color when machine is occupied (light green)
$failed_color="#91FF6C";   //row color when machine is available (light red)

//Declare array with task names
$tasknames = array("\"TASK1\"", "\"TASK2\"");
//Declare array with TASK log network share
$tasklogs = array("\\\Task1Log\share", "\\\Task2Log\share");
//count the number in array
$numberoftasks = count($tasknames);

//Create table and column headers
echo '<table border ="1" cellpadding="5" cellspacing="0" style="border: 1px solid #c0c0c0;">';
echo '<tr>';
    echo '<th>Task Name</th>';
    echo '<th>Status</th>';
    echo '<th>Next Run Time</th>';
    echo '<th>Last Run Time</th>';
    echo '<th>Last Result</th>';
    echo '<th>Trigger</th>';
    echo '<th>Run As User</th>';
    echo '<th>Run Task</th>';
    echo '<th>Logs</th>';
echo '</tr>'; 
echo '<br><br>';

//Loop to create the rest of the table rows with Task information retrieved from system
for($x = 0; $x < $numberoftasks; $x++){
    $status = "0";
    $schtasksinst = "schtasks.exe /S SystemName /Query /TN $tasknames[$x] /FO LIST /V";
    $runtaskinst = "schtasks.exe /S SystemName /Run /TN $tasknames[$x]";
    exec($schtasksinst, $output);

//If statement to assign the appropriate color to a row based on if the task run successfully or had issues 
if ($status = (substr($output[8], 38))){
    $color = $success_color;
} else {
    $color = $failed_color;
}

//Fill table with Task info
    echo '<tr style="background: '.$color.';">';
    echo "<td>".substr($output[3], 39)."</td>";
    echo "<td>".substr($output[5],8)."</td>";
    echo "<td>".substr($output[4], 15)."</td>";
    echo "<td>".substr($output[7], 15)."</td>";
    echo "<td>0x".substr($output[8], 38)."</td>";
    echo "<td>".substr($output[20], 15)."</td>";
    echo "<td>".substr($output[16], 13)."</td>";
    echo "<td><input type=submit name=runtask value=\"Run $tasknames[$x]\"></td>";
    echo "<td>".$tasklogs[$x]."</td>";
    unset($schtasksinst);
    unset($runtaskinst);
    unset($output);
}

\\End table as all info has been displayed
echo '</table>';
echo '<br><br>';

\\Create basic table as color legend
echo "<H2>Color Legend</H2>";
echo '<table border ="1" cellpadding="5" cellspacing="0" style="border: 1px solid #c0c0c0;">';
echo '<tr>';
echo '<td>Scheduled Task is either running or encountered an issue on it\'s last run:</th>';
echo '<td BGCOLOR=' . $success_color . '>' . str_repeat('&nbsp;', 30) . '</th>';
echo '</tr>';
echo '<tr>';
echo '<td>Scheduled task ran with no issues:</th>';
echo '<td BGCOLOR=' . $failed_color . '>' . str_repeat('&nbsp;', 30) . '</th>';
echo '</tr>';
echo '</table>';

?>


Hmm,我是否应该在运行此命令的服务器上设置脚本?我希望用PHP来完成这一切,但我愿意接受建议!您需要创建一个html表单,并将表单“发布”到另一个php页面,该页面将运行您的服务器端命令:)我尝试了这个方法,我使用了以下方法来构建按钮:echo“run Task”;;。。。。。我想知道我建桌子的方式是不是这个问题?另一个PHP文件运行exec(schtasks.exe…和命令的其余部分)。Naa如果您的表出错,它只会显示错误。页面是否导航到index_test.php?如果它这样做了,它就工作得很好,您可能只是在index_text.php中遇到了问题,该文件应该运行您的服务器站点命令。也许还可以尝试从index_text.php中提取一些内容,看看它是否正在运行。感谢britter的帮助,我找到了如何让它工作的方法。看下面,这正是我所期待的。我会在24小时后将其标记为答案。