Windows creates a task schedule from the command line with a modified power level

update: I was able to execute the highest priority job with the / RL option. ( but still wondering why this isn't mentioned in the official Microsoft documentation. )

As the title says, I want to create a scheduled task with a modified power state (not run only when connected to ac) as we can disable this option in GUI mode in Windows 8.1 using a batch file / command line.

I used:

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

He created a scheduled task, but not with the highest privileges. In addition, there are restrictions such as "only start the task when connected to AC power" and so on.

My question is how can I achieve the same result using the command line, how can this be done using the GUI?

Another answer on stackoverflow said that it is not possible to complete all tasks using the command line like in a GUI. But I saw that Opera / Google Drive browser created a scheduled task automatically in the task scheduler and their tasks are executed with the highest privileges. [cm. link to image below] http://i.stack.imgur.com/UAu7I.png

Can anyone explain all of this? Thank.:)

+3


source to share


2 answers


Export as XML file or create 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.

      

+3


source


This is how to put the xml file in the bat file. Note Skip = 6 means the xml file must start on line 7.



FOR /F "usebackq skip=6 delims=" %%i IN (%0) DO @echo %%i >>"%temp%\tmp010.xml"
notepad "%temp%\tmp010.xml"
del "%temp%\tmp010.xml"


goto :eof
<?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>

      

+3


source







All Articles