2014-01-21 72 views
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 

回答

0

我已經得到了它與下面的命令工作:

Set-PSSessionConfiguration -Name Microsoft.PowerShell -showSecurityDescriptorUI 

有我加入Apache服務的用戶享有充分權利。

比我需要運行:

Set-ExecutionPolicy Unrestricted 

在x86的PowerShell。系統運行在64位系統上,服務在32位模式下運行powershell,我只在64位模式下更改執行策略。

相關問題