通过 Powershell 作为 System32 创建任务
Creating Task via Powershell as System32
我想通过 Powershell 创建一个任务,但我得到了这个错误:
注册计划任务:拒绝访问
在 C:\UsersTL4S\Documents\Coding\Bot_Dev\juri_exc\ui\setup_bot_task.ps1:8 Zeichen:1
- 注册-ScheduledTask“Bot_Activation”-InputObject $Task
-
- 类别信息:权限被拒绝:(PS_ScheduledTask:Root/Microsoft/...S_ScheduledTask)
[注册计划任务],CimException
- FullyQualifiedErrorId : HRESULT 0x80070005,Register-ScheduledTask
我认为这与“管理员”没有足够的权限有关...我该如何解决这个问题?是否可以将任务创建为 System32?
这是脚本:
$Action = New-ScheduledTaskAction -Execute "cmd.exe"
$Trigger = New-ScheduledTaskTrigger -At "0am" -DaysOfWeek 1 -Weekly
$Principle = New-ScheduledTaskPrincipal "Administrator" -RunLevel Highest
$Settings = New-ScheduledTaskSettingsSet
$Task = New-ScheduledTask -Action $Action -Principal $Principle -Trigger $Trigger -Settings $Settings
Register-ScheduledTask "Bot_Activation" -InputObject $Task
这是调用脚本的代码:
subprocess.Popen([r'C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe',
'-ExecutionPolicy',
'Unrestricted',
'./setup_bot_task.ps1'], cwd=os.getcwd())
您需要运行这是一个使用“运行作为管理员”选项的提升会话。
您可以将 Start-Process
与参数 -Verb
和自变量 runas
一起使用。看这个测试
Start-Process powershell -ArgumentList @'
$Action = New-ScheduledTaskAction -Execute "cmd.exe"
$Trigger = New-ScheduledTaskTrigger -At "0am" -DaysOfWeek 1 -Weekly
$Principle = New-ScheduledTaskPrincipal "Administrator" -RunLevel Highest
$Settings = New-ScheduledTaskSettingsSet
$Task = New-ScheduledTask -Action $Action -Principal $Principle -Trigger $Trigger -Settings $Settings
Register-ScheduledTask "Bot_Activation" -InputObject $Task
'@ -Verb runas
我想通过 Powershell 创建一个任务,但我得到了这个错误:
注册计划任务:拒绝访问 在 C:\UsersTL4S\Documents\Coding\Bot_Dev\juri_exc\ui\setup_bot_task.ps1:8 Zeichen:1
- 注册-ScheduledTask“Bot_Activation”-InputObject $Task
-
- 类别信息:权限被拒绝:(PS_ScheduledTask:Root/Microsoft/...S_ScheduledTask) [注册计划任务],CimException
- FullyQualifiedErrorId : HRESULT 0x80070005,Register-ScheduledTask
我认为这与“管理员”没有足够的权限有关...我该如何解决这个问题?是否可以将任务创建为 System32?
这是脚本:
$Action = New-ScheduledTaskAction -Execute "cmd.exe"
$Trigger = New-ScheduledTaskTrigger -At "0am" -DaysOfWeek 1 -Weekly
$Principle = New-ScheduledTaskPrincipal "Administrator" -RunLevel Highest
$Settings = New-ScheduledTaskSettingsSet
$Task = New-ScheduledTask -Action $Action -Principal $Principle -Trigger $Trigger -Settings $Settings
Register-ScheduledTask "Bot_Activation" -InputObject $Task
这是调用脚本的代码:
subprocess.Popen([r'C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe',
'-ExecutionPolicy',
'Unrestricted',
'./setup_bot_task.ps1'], cwd=os.getcwd())
您需要运行这是一个使用“运行作为管理员”选项的提升会话。
您可以将 Start-Process
与参数 -Verb
和自变量 runas
一起使用。看这个测试
Start-Process powershell -ArgumentList @'
$Action = New-ScheduledTaskAction -Execute "cmd.exe"
$Trigger = New-ScheduledTaskTrigger -At "0am" -DaysOfWeek 1 -Weekly
$Principle = New-ScheduledTaskPrincipal "Administrator" -RunLevel Highest
$Settings = New-ScheduledTaskSettingsSet
$Task = New-ScheduledTask -Action $Action -Principal $Principle -Trigger $Trigger -Settings $Settings
Register-ScheduledTask "Bot_Activation" -InputObject $Task
'@ -Verb runas