26

When I use the GUI Task Scheduler, I can easily check the "Run with highest privileges" checkbox.

I found no such option in the SchTasks command line too, however.

Is there a way to do that from the command line?

fixer1234
  • 27,064
  • 61
  • 75
  • 116
WinWin
  • 960
  • 3
  • 11
  • 20

3 Answers3

35

That's what the /RL option does.

Example: SCHTASKS /Create /TN "New Task" /SC HOURLY /TR blah.exe /RU username /RP password /RL HIGHEST

Kiquenet
  • 269
  • 1
  • 4
  • 14
Skatterbrainz
  • 925
  • 1
  • 8
  • 9
  • can we use that for each version of Windows (from XP to 7 or 8, including Windows Server 2008) ? – fbiville Oct 09 '12 at 15:23
  • Not for Windows XP, according to Microsoft (http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/schtasks.mspx?mfr=true), also note the "this option is not available" comments for (XP and WinServer 2003) on http://msdn.microsoft.com/en-us/library/windows/desktop/bb736357(v=vs.85).aspx – Skatterbrainz May 04 '13 at 02:54
  • @Rolf check out my answer for a small script, that will work on both XP/2003 and Vista/2008 (or higher) – abstrask Jul 29 '14 at 12:19
7

/RL level Sets the Run Level for the job. Valid values are LIMITED and HIGHEST. The default is LIMITED.

Simon Sheehan
  • 9,114
  • 12
  • 52
  • 71
Andrey
  • 71
  • 1
  • 1
3

To add to @Skatterbrainz's answer: If you run the same command/script on XP/2003, specifying /RL, SchTasks.exe will fail to create the task.

You can make a script that will work on XP, 2003, Vista, 2008, 7, 2008R2 etc., by pulling the OS version from the registry. A batch script could look like this:

setlocal
set runlevel=

REM Get OS version from registry
for /f "tokens=2*" %%i in ('reg.exe query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "CurrentVersion"') do set os_ver=%%j

REM Set run level (for Vista or later - version 6)
if /i "%os_ver:~,1%" GEQ "6" set runlevel=/rl HIGHEST

REM Execute SchTasks.exe
schtasks.exe /create /tn "Task Name" /sc ONSTART /TR "C:\Scripts\somescript.cmd" /ru SYSTEM %runlevel%
abstrask
  • 4,849
  • 5
  • 26
  • 34