Power Settings - be able set our own defaults

Do you know of a feature that UVK should have? Post it here!
Post Reply
Xander
Posts: 438
Joined: Sun May 24, 2015 11:55 pm
Contact:

Power Settings - be able set our own defaults

Post by Xander »

On laptops, I set the Power button and Lid-Close settings to Hibernate. I had two client laptops in the last year where they closed the lid, it went to Sleep and then they stuffed it into a bag causing the CPU to overheat. After that, I started making that my default setting.
Image

I'd like a way to be able to set the power settings, either in a script or within the System Repair section to our preferences.
wmmiller
Posts: 1098
Joined: Fri Dec 07, 2012 6:02 am
Location: Minnesota, USA

Re: Power Settings - be able set our own defaults

Post by wmmiller »

Hi Xander,

From the welcome screen check the “IT/Geek tools” section. Then under “Enable/Disable (select)”. There is a setting there. See if that will work for you. :)

Bill
Play stupid games….win stupid prizes
Fred
Site Admin
Posts: 2360
Joined: Sat Jul 30, 2011 12:05 pm
Location: Red coast, France
Contact:

Re: Power Settings - be able set our own defaults

Post by Fred »

Xander,

I don't think we could ever find a default schema that would please everyone, so I guess setting up a System repair fix for that effect would not be possible.

However, I can build a script based on this one for the effect. I'll give it a shot tomorrow.
One thing we humans have in common is that we are all different. So, if you think you're weird because you're different from everyone else, then we are all weird.

Fred
Xander
Posts: 438
Joined: Sun May 24, 2015 11:55 pm
Contact:

Re: Power Settings - be able set our own defaults

Post by Xander »

Code's a little beyond me but I'm open. It's currently something that I have in the SR as just "powercfg.cpl" which opens automatically to remind me to set it. Being able to set it automatically would be obviously better.

What about something a little like the <ImunizeSettings> (misspelled, btw) where there's a scripting command "<___>" with parameters?

___________

The Immunization part got me thinking: is there a way to enter a <scriptcommand> in the SR section? So that one could enter, say, <ImunizeSystem>0|2|15|20 as the command line and have it perform that action?
I know a lot of of script functions are duplicated in SR but not all so wondering if there's a built-in way to use them in the SR stuff.
Charger440
Posts: 1529
Joined: Sun May 25, 2014 7:44 am
Location: Missouri

Re: Power Settings - be able set our own defaults

Post by Charger440 »

How about just add a setting and let people pick the action they want for power settings? The tech settings, as far as I'm concerned are fine. But, not everyone wants the default windows power settings to be restored which is essentially what UVK is doing now.
Jim

It is not "Can it be done?" but rather, "How can we do it?"
wmmiller
Posts: 1098
Joined: Fri Dec 07, 2012 6:02 am
Location: Minnesota, USA

Re: Power Settings - be able set our own defaults

Post by wmmiller »

Sorry, I misread that first post. I normally set them to never sleep or hibernate but to shut down. I don’t care for those options. On or off, that way it’s accessible or it isn’t.
Play stupid games….win stupid prizes
Xander
Posts: 438
Joined: Sun May 24, 2015 11:55 pm
Contact:

Re: Power Settings - be able set our own defaults

Post by Xander »

Charger440 wrote:How about just add a setting and let people pick the action they want for power settings? The tech settings, as far as I'm concerned are fine.
The settings during our work are fine. I'm asking for the ability to set them to my liking automatically.
Charger440 wrote:But, not everyone wants the default windows power settings to be restored which is essentially what UVK is doing now.
Right and, if I read Fred's reply correctly, he's looking in to the ability to set them to our preferences.

Win win.
Charger440
Posts: 1529
Joined: Sun May 25, 2014 7:44 am
Location: Missouri

Re: Power Settings - be able set our own defaults

Post by Charger440 »

Xander wrote:
Charger440 wrote:How about just add a setting and let people pick the action they want for power settings? The tech settings, as far as I'm concerned are fine.
The settings during our work are fine. I'm asking for the ability to set them to my liking automatically.
Charger440 wrote:But, not everyone wants the default windows power settings to be restored which is essentially what UVK is doing now.
Right and, if I read Fred's reply correctly, he's looking in to the ability to set them to our preferences.

Win win.
What I got out of Fred's post was that he would make a script that instead of asking "Yes" or "No" would allow us to select the option for the item. What I thought would be a better solution is to leave the power settings like they are but ADD the default action to the user options and just have the current power settings menu item use the default action we setup. Essentially what you said but, I wanted to be more clear in what I was talking about.
Jim

It is not "Can it be done?" but rather, "How can we do it?"
Fred
Site Admin
Posts: 2360
Joined: Sat Jul 30, 2011 12:05 pm
Location: Red coast, France
Contact:

Re: Power Settings - be able set our own defaults

Post by Fred »

If I make a script or add a feature that allows us to set the power options we want, it will not be any different from the custom app Xander made that runs powercfg.cpl. I was going to make a script that sets close lid actions to Hibernate, in all power schemes, and for both "On battery" and "Plugged-in" states.
One thing we humans have in common is that we are all different. So, if you think you're weird because you're different from everyone else, then we are all weird.

Fred
Fred
Site Admin
Posts: 2360
Joined: Sat Jul 30, 2011 12:05 pm
Location: Red coast, France
Contact:

Re: Power Settings - be able set our own defaults

Post by Fred »

Xander, here's the script I promised. It will set the "Close lid" action to "Hibernate" for all power schemes, and for both "On battery" and "Plugged-in" states.

Code: Select all

 <AutoItScript>
;#RequireAdmin
Global Const $tagGUID = 'ULONG Data1;USHORT Data2;USHORT Data3;BYTE Data4[8]'
Global Const $GUID_SYSTEM_BUTTON_SUBGROUP = '4f971e89-eebd-4455-a8de-9e59040e7347'
Global Const $GUID_LIDCLOSE_ACTION = '5ca83367-6e45-459f-a27b-476b1d01c936'

Global Const $GUID_MAX_POWER_SAVINGS = 'A1841308-3541-4FAB-BC81-F71556F20B4A'
Global Const $GUID_MIN_POWER_SAVINGS = '8C5E7FDA-E8BF-4A96-9A85-A6E23A8C635C'
Global Const $GUID_TYPICAL_POWER_SAVINGS = '381b4222-f694-41f0-9685-ff5bb260df2e'

Global Const $LID_CLOSE_INDEX_DONOTHING	= 0
Global Const $LID_CLOSE_INDEX_SLEEP		= 1
Global Const $LID_CLOSE_INDEX_HIBERNATE	= 2
Global Const $LID_CLOSE_INDEX_SHUTDOWN	= 3

_SetLidCloseToHibernate()


Func _SetLidCloseToHibernate()

	Local $ret = 0, $PowerID  = _PowerGetActiveScheme()

   ;Lid Close
   Local Const $GroupId = _UuidFromString($GUID_SYSTEM_BUTTON_SUBGROUP)
   Local Const $SubGroupId = _UuidFromString($GUID_LIDCLOSE_ACTION)
   Local Const $value = $LID_CLOSE_INDEX_HIBERNATE

   $ret += _PowerWriteACValueIndex($PowerID, $GroupId, $SubGroupId, $value)

   $ret += _PowerWriteDCValueIndex($PowerID, $GroupId, $SubGroupId, $value)

   $ret += _PowerWriteACValueIndex( _
   _UuidFromString($GUID_MAX_POWER_SAVINGS), $GroupId, $SubGroupId, $value)

   $ret += _PowerWriteDCValueIndex( _
   _UuidFromString($GUID_MAX_POWER_SAVINGS), $GroupId, $SubGroupId, $value)

   $ret += _PowerWriteACValueIndex( _
   _UuidFromString($GUID_MIN_POWER_SAVINGS), $GroupId, $SubGroupId, $value)

   $ret += _PowerWriteDCValueIndex( _
   _UuidFromString($GUID_MIN_POWER_SAVINGS), $GroupId, $SubGroupId, $value)

   $ret += _PowerWriteACValueIndex( _
   _UuidFromString($GUID_TYPICAL_POWER_SAVINGS), $GroupId, $SubGroupId, $value)

   $ret += _PowerWriteDCValueIndex( _
   _UuidFromString($GUID_TYPICAL_POWER_SAVINGS), $GroupId, $SubGroupId, $value)

   ;Apply changes
   Local $msg = _PowerSetActiveScheme($PowerID) And $ret ? _
   'The Close lid action was successfully set to "Hibernate".' : _
   'The Close lid action could not be set to "Hibernate".'

   ;Free the pointer
   _LocalFree($PowerID )

   MsgBox(0,'Technician Settings',$msg&@CRLF&@CRLF&$ret&' power policies applied.')
EndFunc ;==> _SetLidCloseToHibernate

Func _PowerGetActiveScheme()
   Local $aCall = DllCall('PowrProf.dll', 'DWORD','PowerGetActiveScheme', 'ptr',0, 'ptr*',0)
   If @error Or $aCall[0] Then Return SetError(1,0,0)
   Return $aCall[2]
EndFunc ;==> _PowerGetActiveScheme

Func _LocalFree($hmem)
   Local $aCall = DllCall('Kernel32.dll', 'ptr','LocalFree', 'ptr',$hmem)
   If Not @error Then Return Number($aCall[0] = 0)
EndFunc ;==> _LocalFree

Func _PowerWriteACValueIndex($SchemeGuid, $SubGroupGuid, $SettingGuid, $AcValueIndex)
   Local $pSchemeGuid = IsDllStruct($SchemeGuid) ? DllStructGetPtr($SchemeGuid) : $SchemeGuid
   Local $pSubGroupGuid = IsDllStruct($SubGroupGuid) ? DllStructGetPtr($SubGroupGuid) : $SubGroupGuid
   Local $pSettingGuid = IsDllStruct($SettingGuid) ? DllStructGetPtr($SettingGuid) : $SettingGuid
   Local $aCall = DllCall('PowrProf.dll', 'DWORD','PowerWriteACValueIndex', _
   'ptr',0, 'ptr',$pSchemeGuid, 'ptr',$pSubGroupGuid , 'ptr',$pSettingGuid, 'DWORD',$AcValueIndex)
   If Not @error Then Return Number($aCall[0] = 0)
EndFunc ;==> _PowerWriteACValueIndex

Func _PowerWriteDCValueIndex($SchemeGuid, $SubGroupGuid, $SettingGuid, $AcValueIndex)
   Local $pSchemeGuid = IsDllStruct($SchemeGuid) ? DllStructGetPtr($SchemeGuid) : $SchemeGuid
   Local $pSubGroupGuid = IsDllStruct($SubGroupGuid) ? DllStructGetPtr($SubGroupGuid) : $SubGroupGuid
   Local $pSettingGuid = IsDllStruct($SettingGuid) ? DllStructGetPtr($SettingGuid) : $SettingGuid
   Local $aCall = DllCall('PowrProf.dll', 'DWORD','PowerWriteDCValueIndex', _
   'ptr',0, 'ptr',$pSchemeGuid, 'ptr',$pSubGroupGuid , 'ptr',$pSettingGuid, 'DWORD',$AcValueIndex)
   If Not @error Then Return Number($aCall[0] = 0)
EndFunc ;==> _PowerWriteACValueIndex

Func _PowerSetActiveScheme($SchemeGuid)
   Local $pSchemeGuid = IsDllStruct($SchemeGuid) ? DllStructGetPtr($SchemeGuid) : $SchemeGuid
   Local $aCall = DllCall('PowrProf.dll', 'DWORD', 'PowerSetActiveScheme', 'ptr',0, 'ptr',$pSchemeGuid)
   If Not @error Then Return Number($aCall[0] = 0)
EndFunc ;==> _PowerSetActiveScheme

Func _UuidFromString($guidStr)
   Local $sret = DllStructCreate($tagGUID)
   Local $aCall = DllCall('Rpcrt4.dll', 'DWORD','UuidFromStringW', 'wstr',$guidStr, 'struct*',$sret)
   If @error Or $aCall[0] Then Return SetError(1,0,$sret)
   Return $sret
EndFunc ;==> _UuidFromString
CloseLidAction.uvk
(4.54 KiB) Downloaded 182 times
Enjoy!
One thing we humans have in common is that we are all different. So, if you think you're weird because you're different from everyone else, then we are all weird.

Fred
Post Reply