What is the command line to schedule a task to be executed once and soon?
The schtasks command can run a defined task immediately.
From How to use Schtasks.exe to Schedule Tasks in Windows Server 2003
Schtasks /Run
Starts a scheduled task immediately. The run operation ignores the schedule, but uses the program file location, user account, and password that are saved in the task to run the task immediately.
Syntax:
schtasks /run /tn TaskName [/s computer [/u [domain\]user /p password]] /?
So just define the task, then run it immediately at any time you need to.
Working on top of Keith's answer to suit your needs:
timeout /t X ; psexec -i -s Y
Where
-
timeout
replaces sleep in Windows 7. -
X
is the seconds to wait defined by/t
, add/nobreak
if you want to disallow the user to continue. -
psexec
from Microsoft SysInternals allows you to run interactive (-i
) as the local system (-s
), please note that you have to start psexec once to accept the first time EULA, or add-accepteula
. -
Y
is your command.
runas
doesn't allow you to start as local system, that's why to use PsTools for process-related tasks.
Starting a Scheduled Task or Service seems like too much of a workaround for me...
For example, Patrick's answer can simply be rewritten as:
timeout /t 120 ; psexec -i -s calc.exe