Jump to content

Autoit and power plans


Briandr
 Share

Recommended Posts

Hi,
 
I found this in the forums when googling Autoit and power plans and Windows 7. What I want to do is tweak so everything (On Battery, Plugged in) are set to Never. This script needs to adjust the power setting behavior temporarily so devices don't hibernate or turn off.
 

#include <Constants.au3>
$GetCurrent = "Powercfg -getactivescheme" ;CMD command
$SetHigh = "POWERCFG /SETACTIVE SCHEME_MIN" ;min= minimum aving
$SetLow = "POWERCFG /SETACTIVE SCHEME_MAX"
Global $DOS, $Message = '' ;; added "= ''" for show only.
$DOS = Run(@ComSpec & " /c " & $GetCurrent, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ;get your current power scheme
ProcessWaitClose($DOS)
$Message = StdoutRead($DOS)
Run(@ComSpec & " /c " & $SetHigh, "", @SW_HIDE) ;Set max performance settings
$OriginalSceme = StringTrimLeft ($Message,StringInStr ($Message,":")+1) ;working on string
$OriginalScemeFinal = StringLeft ($OriginalSceme,StringInStr ($OriginalSceme,"(")-3) ;working on string 
$ReturToOriginal = "POWERCFG /SETACTIVE " & $OriginalScemeFinal ;final string for previously used power scheme ID

RunWait ("Run what ever you want here")
Run(@ComSpec & " /c " & $ReturToOriginal , "", @SW_HIDE) ;Return to previously set power settings

Does this code look clean?
 
Thanks kindly.

Edited by Briandr
Added code tags
Link to comment
Share on other sites

  • Moderators

Briandr,

As a member for over 4 years, I am amazed you have not yet learned how to post code - see here how to do it. Then you get a scrolling box and syntax colouring as you can see above now I have added the tags and removed the dross. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I made some tweaks to try and simplify this. The only thing I am not sure is how to apply this to a specific power plan or apply it to all of them with another script that would that set back the changes I want later

#include <Constants.au3>

$MonitorTimeoutAC = "POWERCFG -change -monitor-timeout-ac 0"
$MonitorTimeoutDC = "POWERCFG -change -monitor-timeout-dc 0"
$DiskTimeoutAC =  "POWERCFG -change -disk-timeout-ac 0"
$DiskTimeoutDC =  "POWERCFG -change -disk-timeout-dc 0"
$StandbyTimeoutAC = "POWERCFG -change -standby-timeout-ac 0"
$StandbyTimeoutDC = "POWERCFG -change -standby-timeout-dc 0"
$HibernateTimeoutAC = "POWERCFG -change -hibernate-timeout-ac 0"
$HibernateTimeoutDC = "POWERCFG -change -hibernate-timeout-dc 0"

Run(@ComSpec & " /c " & $MonitorTimeoutDC, "", @SW_HIDE)
Run(@ComSpec & " /c " & $DiskTimeoutAC, "", @SW_HIDE)
Run(@ComSpec & " /c " & $DiskTimeoutDC, "", @SW_HIDE)
Run(@ComSpec & " /c " & $StandbyTimeoutDC, "", @SW_HIDE)
Run(@ComSpec & " /c " & $HibernateTimeoutAC, "", @SW_HIDE)
Run(@ComSpec & " /c " & $HibernateTimeoutDC, "", @SW_HIDE)
 
Edited by Briandr
Link to comment
Share on other sites

Hi,

Could I use something like this instead?

#RequireAdmin

$PowerScheme=IniRead("Setup.ini", "PowerScheme", "PowerLoc", "Not Found")

;Import power config settings
$PowerCMD = @SystemDir & '\Powercfg.exe -Import "' & $PowerScheme & '"'
$iRET = RunWait($PowerCMD, @SystemDir, @SW_MINIMIZE)

I don't need the setup.ini, but wouldn't I need a file install to include the power scheme file? 

Any help would be appreciated as I don't know AutoIT well.

Thanks.

Link to comment
Share on other sites

I would be willing to be that the power settings for the current user are in the registry and you could record all the values and then change them and then put them back.

Edit - Found them - [HKEY_CURRENT_USERControl PanelPowerCfg]

Give me a minute Ill write something you can use

Edit 2 - I cant recommend downloading the files here but there is useful data further down on the page here -> http://www.sevenforums.com/tutorials/21990-power-plan-create-shortcut-change-power-plan.html You can get a list of the power plan GUID's and just run the one you want and then change it back through the command prompt. Will this work for you?

Edited by computergroove

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

I just need the process to be automated. I been digging through the forums here at AutoIT and google. That's where I came up with the examples I posted. I was just hoping to tweak based off one of those. The one I posted at 12:45 yesterday seems to work, but I just need to make sure which power scheme it is applying to. It seems which ever is the selected power scheme is the one that it is applying to. I also want to make sure when plugged in or on battery are all set to Never.

Thanks for jumping and offering to help

Edited by Briandr
Link to comment
Share on other sites

You can automate commands with autoit using controlsend or run. You could read the registry value of the current power plan with regread. Open regedit and goto HKEY_CURRENT_USERControl PanelPowerCfg and look at the values. It is pretty self explanatory. Originally I wanted to use _WinAPI_SystemParametersInfo to refresh the power settings after you changed the power scheme but it looks like that is no longer supported by microsoft in Windows 7. You can change the power scheme from the command prompt and you can control the command prompt from within autoit.

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

In case anyone benefits I got something that worked for me. Export power scheme after setting my defaults and then importing back in. I know you guys tend to frown on wanting people to do other people's scripts. Took me a while to come up with this simple 4 or 5 line script, but I did. Not sure if someone can use it down the road. Proably not, but here is the snipet of code.

#include <Constants.au3>

FileInstall("PowerPlanNever.pow", @WindowsDir & "\", 1)
$ImportPowerPlan = "POWERCFG -import C:\Windows\PowerPlanNever.pow 3b5e563e-124a-46ac-a21e-c436de915f80"
$SetActivePowerPlan = "POWERCFG -setactive 3b5e563e-124a-46ac-a21e-c436de915f80"

Run(@ComSpec & " /c " & $ImportPowerPlan, "", @SW_HIDE)
Run(@ComSpec & " /c " & $SetActivePowerPlan, "", @SW_HIDE)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...