Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 518 Vote(s) - 3.4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Powershell - Create Scheduled Task to run as local system / service

#1
Can anyone tell me how to create a scheduled task using powershell that runs as the local system or local service?

Everything works great except the call to ITaskFolder.RegisterTaskDefinition().

If I pass in $null, or "", than the call bombs saying invalid username or password.
Any thoughts"

$Rootfolder.RegisterTaskDefinition("Test", $Taskdef, 6, "LOCAL SERVICE", "", 3)
Reply

#2
I think you would need to use "nt authority\localservice" as the user name.

Kindness,

Dan
Reply

#3
This code snippet will use the [PowerShellPack][1]'s Task Scheduler module to schedule a task to run as SYSTEM immediately:

New-Task |
ForEach-Object {
$_.Principal.Id = "NTAuthority\SYSTEM"
$_.Principal.RunLevel = 1
$_
} |
Add-TaskAction -Script {
"SystemTask" > C:\myTest.txt
} |
Add-TaskTrigger -OnRegistration |
Register-ScheduledTask SystemTask


[1]:

[To see links please register here]

Reply

#4
For those who can use **PowerShell 3.0** on **Windows 8 or Windows Server 2012**, new cmdlets will let you do it in a simple way when registering your scheduled task with the cmdlet ````Register-ScheduledTask```` and as argument ````-User "System"````



Here is a scheduled task created entirely with PS, its purpose is to restart a service My Service, using the SYSTEM account, 3 minutes after the system has started:

$taskname = "Restart My Service"
$taskdescription = "Restart My Service after startup"
$action = New-ScheduledTaskAction -Execute 'Powershell.exe' `
-Argument '-NoProfile -WindowStyle Hidden -command "& Restart-Service -displayname \"My Service\""'
$trigger = New-ScheduledTaskTrigger -AtStartup -RandomDelay (New-TimeSpan -minutes 3)
$settings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit (New-TimeSpan -Minutes 2) -RestartCount 3 -RestartInterval (New-TimeSpan -Minutes 1)
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName $taskname -Description $taskdescription -Settings $settings -User "System"

NB: you will need to run powershell as an administrator for that script.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through