I want to create a Task via Powershell, but i get this Error:
Register-ScheduledTask : Access Denied In C:\Users\4TL4S\Documents\Coding\Bot_Dev\juri_exc\ui\setup_bot_task.ps1:8 Zeichen:1
I think it has todo with that "Administrator" hasnt got enough rights...How could i fix this? Is it possible to create Task as System32?
This is the Script:
$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
This is the Code which calls the Script:
subprocess.Popen([r'C:\\WINDOWS\\system32\WindowsPowerShell\\v1.0\\powershell.exe',
'-ExecutionPolicy',
'Unrestricted',
'./setup_bot_task.ps1'], cwd=os.getcwd())
You need to run this is an elevated session using the "Run as adminstrator" option.
You can use Start-Process
with the parameter -Verb
and argument runas
. See this test
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
User contributions licensed under CC BY-SA 3.0