0
嘿傢伙我寫了一個小powershell腳本輸出有關所有計劃任務的信息Json格式。這些信息我用於一個小型網站。這是我的PowerShell腳本:運行powershell日程安排任務信息請求沒有管理員權限
$servername = "localhost"
$schedule = new-object -com("Schedule.Service")
$schedule.connect($servername)
$tasks = $schedule.getfolder("\").gettasks(0)
$tasks |select name, lasttaskresult, lastruntime, enabled, nextruntime | ConvertTo-Json > C:\xampp\htdocs\batch_files\test.txt
我從PHP運行ps1
文件這一行:
$output = shell_exec('powershell.exe -command C:\\xampp\\htdocs\\batch_files\\stask_query.ps1');
但是,這是行不通的。當我從powershell控制檯運行腳本我得到一個訪問被拒絕的錯誤。當我在一個開始於Run as admin
的控制檯中運行它時,它正在工作。我怎樣才能做到這一點?
我試圖Apache服務的用戶與該行的全部權利添加到PowerShell的:
Set-PSSessionConfiguration -Name Microsoft.PowerShell -showSecurityDescriptorUI
但它並不能幫助。
編輯:我注意到我不需要$servername
更新腳本:
$schedule = new-object -com("Schedule.Service")
$schedule.connect()
$tasks = $schedule.getfolder("\").gettasks(0)
$tasks |select name, lasttaskresult, lastruntime, enabled, nextruntime | ConvertTo-Json > C:\xampp\htdocs\batch_files\test.txt