gpt4 book ai didi

PHP/Windows Task Scheduler - 如何从 PHP 创建新任务?

转载 作者:行者123 更新时间:2023-12-05 01:47:00 24 4
gpt4 key购买 nike

我有以下代码片段,我试图修改它以在 windows 中从 php 创建计划任务。我试过 exec,然后 pclose(popen($cmd)) 但没有成功。 php 脚本执行但没有调用任何命令,我在我的任务计划程序 gui 中看不到任何添加的计划任务。

问题

如何从 php 调用 schtasks.exe 来创建新任务?

代码片段

    $daysList = join(", ", $days);


$cmd = "c:\\windows\\system32\\schtasks.exe /CREATE /SC WEEKLY /D \"$daysList\" /TN \"Action Item Reminder\" /TR \"php.exe C:\\wamp\\www\\aim\\module\\Application\\src\\Application\\Controller\\sendmail.php\" /ST 00:01 /f";

pclose(popen("start /B ". $cmd, "r"));


//echo "c:\\windows\\system32\\schtasks.exe /CREATE /SC WEEKLY /D \"$daysList\" /TN \"Action Item Reminder\" /TR \"C:\\wamp\\bin\\php\\php5.5.12\\php.exe C:\\wamp\\www\\aim\\module\\Application\\src\\Application\\Controller\\sendmail.php\" /ST 00:01 /f";

//echo '/CREATE /SC WEEKLY /D "'. $daysList .'" /TN "Action Item Reminder" /TR "C:\wamp\www\aim\module\Application\src\Application\Controller\sendmail.php" /ST 00:01 /f"'; die();

if (isset ($activate))
{
$emailOptionTable->update('true', 'Activate Reminders');
$cmd = "c:\\windows\\system32\\schtasks.exe /Change /TN \"Action Item Reminder\" /Enable";

pclose(popen("start /B ". $cmd, "r"));
}
else
{
$emailOptionTable->update('false', 'Activate Reminders');
$cmd = "c:\\windows\\system32\\schtasks.exe /Change /TN \"Action Item Reminder\" /Disable";

pclose(popen("start /B ". $cmd, "r"));
}

编辑

问题本地化

Apache 错误日志显示此消息

ERROR: No mapping between account names and security IDs was done.

(46,4):UserId:ERROR: No mapping between account names and security IDs was done.

(46,4):UserId:

我需要做什么来解决这个问题?

最佳答案

  1. 您需要有一个用户。所以你应该添加/RU "用户名"
    我建议以系统运行任务。

  2. 您不需要完整地址。
    "c:\windows\system32\schtasks.exe">> schtasks.exe

  3. 您可以通过在行尾使用“>your file.txt”从 Windows 命令行获得反馈。
    exp: dir > "c:\Directories.txt"

您的新鳕鱼:

    $daysList = join(", ", $days);

$cmd = "schtasks.exe /CREATE /SC WEEKLY /D \"$daysList\" /TN \"Action Item Reminder\" /TR \"php.exe C:\\wamp\\www\\aim\\module\\Application\\src\\Application\\Controller\\sendmail.php\" /ST 00:01 /f /RU System";

pclose(popen("start /B ". $cmd, "r")); // OR exec($cmd);

//echo "schtasks.exe /CREATE /SC WEEKLY /D \"$daysList\" /TN \"Action Item Reminder\" /TR \"C:\\wamp\\bin\\php\\php5.5.12\\php.exe C:\\wamp\\www\\aim\\module\\Application\\src\\Application\\Controller\\sendmail.php\" /ST 00:01 /f /RU System";
//echo '/CREATE /SC WEEKLY /D "'. $daysList .'" /TN "Action Item Reminder" /TR "C:\wamp\www\aim\module\Application\src\Application\Controller\sendmail.php" /ST 00:01 /f /RU System"'; die();

$cmd ="schtasks.exe /Change /TN \"Action Item Reminder\" /RU System";
if (isset ($activate))
{
$emailOptionTable->update('true', 'Activate Reminders');
pclose(popen("start /B ". $cmd." /Enable", "r")); // OR exec($cmd);
}
else
{
$emailOptionTable->update('false', 'Activate Reminders');
pclose(popen("start /B ". $cmd." /Disable", "r")); // OR exec($cmd);
}

祝你好运。

关于PHP/Windows Task Scheduler - 如何从 PHP 创建新任务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32576146/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com