Php 如何使用powershell更改任务计划程序中的安全选项
我从PHP页面调用了PowerShell脚本,如下所示: file.phpPhp 如何使用powershell更改任务计划程序中的安全选项,php,powershell,security,windows-task-scheduler,Php,Powershell,Security,Windows Task Scheduler,我从PHP页面调用了PowerShell脚本,如下所示: file.php try{ echo shell_exec('powershell.exe -executionpolicy bypass -NoProfile -File "C:\wamp64\www\xpress_upgrade\Schedule_CRON.ps1"'); }catch (Exception $e){ echo "Oops: Something went wrong.&
try{
echo shell_exec('powershell.exe -executionpolicy bypass -NoProfile -File "C:\wamp64\www\xpress_upgrade\Schedule_CRON.ps1"');
}catch (Exception $e){
echo "Oops: Something went wrong.<br />".$e->getMessage();
}
如果我直接运行PowerShell,任务将正常创建和运行。但若我通过PHP文件运行,那个么这个任务可以创建,但由于以下安全问题,它并没有运行。需要设置用户帐户名并设置运行用户是否登录。-如何才能做到这一点
任务计划程序中的警告:
任务计划程序未启动任务“\WMS计划的工作流01”
因为用户“**”在启动条件满足时未登录
遇见。用户操作:确保用户已登录或更改任务
允许在用户注销时启动的定义
如果需要第二个选项,则需要使用
-User
和-Password
参数运行Register ScheduledTask
。这意味着您需要通过交互式提示提供凭据,将凭据存储在当前会话中并检索它们,或者将凭据存储在其他位置并在调用命令时检索它们。无论如何,请不要提及用户和密码。@AdminOfThings。我不知道如何从寄存器ScheduledTask中使用命令
$lines = Get-Content C:\wamp64\www\xpress_upgrade\Scheduled_data.txt | Where {$_ -notmatch '^\s+$'}
foreach ($line in $lines) {
$fields = $line -split '\s+'
$id = $fields[0]
$time = $fields[1]
$description = "scheduled workflow " + $id
#creating tasks in task scheduler on Workflow scheduled time
$argument = 'C:\wamp64\www\xpress_upgrade\workflow_execution_progress_sch.php ' + $id
Write-Host $argument
$action = New-ScheduledTaskAction -Execute 'C:\wamp64\bin\php\php7.4.9\php.exe' -Argument $argument
$trigger = New-ScheduledTaskTrigger -Once -At $time
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName $description -Description $description
}