22

I have a problem regarding how to make a scheduled task to run whether the user is logged on or not. It must be done in PowerShell. What I have done is:

$WINDIR/system32/schtasks.exe /create /tn TaskName /sc daily /st 15:05:00 /tr "C:\cygwin\opt\IBM\tpchc\bin\tools\TheFileToRun.bat"

But can I provide an extra argument making this task run no matter if the user is logged on or off?

If it cant be done in PowerShell is it then possible to do it in another script language?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Diemauerdk
  • 5,238
  • 9
  • 40
  • 56
  • For one, that's not powershell, that's the command line way to do it -- (see the `Register-ScheduledTask` cmdlet), for two, this is a duplicate of: https://stackoverflow.com/questions/13965997/set-a-scheduled-task-to-run-when-user-isnt-logged-in – BrainSlugs83 Mar 09 '18 at 01:44

4 Answers4

25

You'll need to specify a user (like /RU system), but it should be the default whether to run logged in or not. You can look at this link for a list of all schtasks.exe parameters.

SpellingD
  • 2,533
  • 1
  • 17
  • 13
23

if you add

/RU <username> /RP <password>

to the call to schtasks.exe you will get "Run whether user is logged on or not" selected.

You can also use the /NP instead, which will also give you "Run whether user is logged on or not", but also "Do not store password..." which will limit the accessible resources.

NetVicious
  • 3,848
  • 1
  • 33
  • 47
ClarD
  • 231
  • 2
  • 2
0

I got a Working solution, just add this:

/RU "NT AUTHORITY\SYSTEM" /RP *

Will run as System and ignore password, Tested on XP

Jhollman
  • 2,093
  • 24
  • 19
0

If you're using common account:

/RU {accountName} /RP {password}

If you're using gMSA account:

/RU {accountName}$ /RP 
John Jang
  • 2,567
  • 24
  • 28