Briandr Posted December 1, 2014 Share Posted December 1, 2014 (edited) 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 December 2, 2014 by Briandr Added code tags Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 1, 2014 Moderators Share Posted December 1, 2014 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Briandr Posted December 1, 2014 Author Share Posted December 1, 2014 Sorry, the code was actually messier and I tried cleaning it up. But no excuse you are right. I was just in a hurry Link to comment Share on other sites More sharing options...
Briandr Posted December 2, 2014 Author Share Posted December 2, 2014 (edited) 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 December 2, 2014 by Briandr Link to comment Share on other sites More sharing options...
Briandr Posted December 3, 2014 Author Share Posted December 3, 2014 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 More sharing options...
computergroove Posted December 3, 2014 Share Posted December 3, 2014 (edited) 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 December 3, 2014 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 More sharing options...
Briandr Posted December 3, 2014 Author Share Posted December 3, 2014 (edited) 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 December 3, 2014 by Briandr Link to comment Share on other sites More sharing options...
computergroove Posted December 3, 2014 Share Posted December 3, 2014 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 More sharing options...
Briandr Posted December 3, 2014 Author Share Posted December 3, 2014 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now