Command Line Task Scheduler Power Options


  1. Posts : 1
    Windows 7 Pro x86
       #1

    Command Line Task Scheduler Power Options


    Hi everyone,

    I was trying to create a scheduled task via command line (schtask.exe) and I want it to run regardless of whether the user is on battery power or on AC power. I created an event and it runs fine on AC power but when I try it on the battery power, it doesn't work. I checked the task in the task scheduler and saw in the condition for my event the following options checked:
    - Start the task only if the computer is on AC power
    - Stop if the computer switches to battery power

    After I create the task via command line, I can't modify the settings. Either way, I MUST only use the command line to create/modify the tasks. Is there any way to modify this variable? Or am I stuck on only having the task run on AC power?

    Any help would be appreciated. Thanks!
      My Computer


  2. Posts : 22,814
    W 7 64-bit Ultimate
       #2

    Hello demonzrulaz, welcome to Seven Forums!


    Perhaps I'm missing something, why can't you just use the Windows Task Scheduler for this?

    Why MUST you use the command-line?
      My Computer


  3. Posts : 66
    XP Professional, 7 Professional
       #3

    Why do you have to create the scheduled task in the command line? I can think of a couple reasons you might need to run it from the shell, but I'm interested to know why you can't create it from the wizard.

    Also, have you checked out this site? http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

    I don't see the function you are looking for off hand, but it's a good general guide to the schtasks.exe functions.
      My Computer


  4. Posts : 1
    Windows 7 Pro 64-bit
       #4

    Okay, I appreciate that you guys want to make sure that demonzrulaz can't just use the GUI to set the power options, but here's a scenario for you: I'm trying to deploy software to 16 laptops with a script. The software needs to run as an administrative user in non-interactive mode on startup, but it needs to run regardless of whether or not the laptops are on AC. Now, is there a flag that hasn't been documented on Microsoft's site for power management? Or do I need to use some XML file? If so, what format does it need to be in (as there doesn't seem to be much documentation on that either)?
      My Computer


  5. Posts : 3
    OS
       #5

    In the case of randoogle, you can create your task in the GUI configuring your "on battery" settings. Then export that task to XML. On the command line, use the XML switch for your script.

    I created a task with default power settings and then exported that task to XML. I then edited the power settings for that task and re-exported to XML. Comparing the files will show you the specific XML code that you can use:

    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>

    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>

    <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>

    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 17:34.
Find Us