Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows create task schedule from command prompt with modified power condition

update: I was able to do the highest privilege job with /RL option. (but still wondering why this is not mentioned in official microsoft documentation?)

As the title tells, I want to create a scheduled task with modified power condition(untick 'run only when plugged into ac') as we can untick the option in GUI mode, in windows 8.1 with the help of a batch file/command prompt.

I used:

schtasks /create /sc minute /tn test1 /tr "C:\Users\SOURAV\Desktop\beautiful_text.bat" /mo 1 /ru ""

It created the scheduled task but not with highest privilege. Moreover there were restrictions like 'only run the task when plugged into AC power' etc.

My question is how can I achieve the same things via command prompt as we can do via GUI?

Another answer in stackoverflow said that it is not possible to achieve all taskes via command prompt as in GUI. But I saw that Opera browser/Google drive automatically created scheduled task in task scheduler and their tasks run with highest privilege. [see image link below] http://i.stack.imgur.com/UAu7I.png

Can anyone explain all this things? Thank you. :)

like image 341
Sourav Ghosh Avatar asked Feb 11 '23 22:02

Sourav Ghosh


1 Answers

Export as an XML file or create one on the fly with echo.

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2012-08-19T16:49:14.6182</Date>
    <Author>Serenity\David Candy</Author>
  </RegistrationInfo>
  <Triggers>
    <CalendarTrigger>
      <StartBoundary>2012-08-19T04:30:00</StartBoundary>
      <Enabled>true</Enabled>
      <ScheduleByWeek>
        <DaysOfWeek>
          <Monday />
          <Tuesday />
          <Wednesday />
          <Thursday />
          <Friday />
        </DaysOfWeek>
        <WeeksInterval>1</WeeksInterval>
      </ScheduleByWeek>
    </CalendarTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>SERENITY\David Candy</UserId>
      <LogonType>InteractiveToken</LogonType>
      <RunLevel>LeastPrivilege</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <IdleSettings>
      <Duration>PT10M</Duration>
      <WaitTimeout>PT1H</WaitTimeout>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>true</WakeToRun>
    <ExecutionTimeLimit>P3D</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>"C:\Program Files\Windows Media Player\wmplayer.exe"</Command>
      <Arguments>"C:\Users\David Candy\Documents\Music\Soundtrack\Natural Born Killers [Original Soundtrack]\13 Sex Is Violent.wma"</Arguments>
    </Exec>
    <SendEmail>
      <Server>pop.gmail.com</Server>
      <Subject>Hi</Subject>
      <To>Fred</To>
      <From>DCandy</From>
      <Body>Hello</Body>
      <HeaderFields />
    </SendEmail>
  </Actions>
</Task>

From Help for schtasks /create /?

/XML  xmlfile      Creates a task from the task XML specified in a file.
                   Can be combined with /RU and /RP switches, or with /RP
                   alone, when task XML already contains the principal.
like image 150
Noodles Avatar answered Feb 16 '23 04:02

Noodles