Jump to content

Setting power scheme.


stampy
 Share

Recommended Posts

I'm trying to create a setup script for many different computers. One thing it will need to do is to set the power settings to not turn off the monitor or hard drives.

I've succeeded in setting the name of the scheme but nothing seems to actually change the monitor/hdd settings.

I've found a few examples using powercfg.exe. However some of the systems are Windows XP and some are Windows 2k. Powercfg.exe does not work on 2k.

I found this link:

http://www.autoitscript.com/forum/index.php?showtopic=10218&st=0&p=71350&hl=setting%20power%20schemes&fromsearch=1&#entry71350

I tried this and it still doesn't change the settings on 2k (I haven't tried on xp yet). When I change to the needed settings. Then export the reg file. Then change them to something else. Then import the reg file... it doesn't change the settings either. Am I looking in the wrong area? How can I accomplish this simple task in Windows 2k?

Any advice is greatly appreciated.

SetUserPowercfg()


Func SetUserPowercfg()
    RegWrite("HKEY_CURRENT_USER\Control Panel\PowerCfg", "CurrentPowerPolicy", "REG_SZ", "2")
    If @error Then
        Return 0
    Else
        Return 1
    EndIf
    RegWrite('HKEY_CURRENT_USER\Control Panel\PowerCfg\PowerPolicies\2', 'Policies', 'REG_BINARY', _
            '0100000000000000010000000000000000000000000000000000' & _
            '000000000000000000003232000001000000010000006c000000' & _
            '43003a00000000002c01000000000000580200000000646464646500')
    If @error Then
        Return 0
    Else
        Return 1
    EndIf
EndFunc   ;==>SetUserPowercfg
Link to comment
Share on other sites

I don't know if you just don't have access to the registry key or not, but if you do, here is a page to check out.

That would be nice. Powercfg.exe does everything I would need it to... except work with windows 2k :) >>> http://support.microsoft.com/kb/888742

Edit: And yes, full control, local computers with administrator priv.

Edited by stampy
Link to comment
Share on other sites

Oops. Sorry. Didn't see that part about win2k.

Hi,

After your first regwrite you make a return. So your 2nd Regwrite isn't executed forever.

$var = SetUserPowercfg()

Func SetUserPowercfg()
$return = 0    
RegWrite("HKEY_CURRENT_USER\Control Panel\PowerCfg", "CurrentPowerPolicy", "REG_SZ", "0")
    If @error Then
        $return = 0
    Else
        $return = 2
    EndIf
    RegWrite('HKEY_CURRENT_USER\Control Panel\PowerCfg\PowerPolicies\2', 'Policies', 'REG_BINARY', _
            '0100000000000000010000000000000000000000000000000000' & _
            '000000000000000000003232000001000000010000006c000000' & _
            '43003a00000000002c01000000000000580200000000646464646500')
    If @error Then
        $return = $return + 4
    Else
        $return = $return + 8
    EndIf
    Return $return ; 10 -> no error, 4 -> Error 1st and 2nd regwrite, 8 -> error 1st .....
EndFunc   ;==>SetUserPowercfg

;-))

Stefan

Edited by 99ojo
Link to comment
Share on other sites

Your right the error catch wouldn't allow the second one. I also saw that the current policy was being set wrong. However, turns out I pasted the wrong code. I changed it with no error catching to make sure I tested it right and the following didn't work either.

Func SetUserPowercfg2()
RegWrite("HKEY_CURRENT_USER\Control Panel\PowerCfg", "CurrentPowerPolicy", "REG_SZ", "2")
   
    RegWrite('HKEY_CURRENT_USER\Control Panel\PowerCfg\PowerPolicies\2', 'Policies', 'REG_BINARY', _
            '0100000000000000010000000000000000000000000000000000' & _
            '000000000000000000003232000001000000010000006c000000' & _
            '43003a00000000002c01000000000000580200000000646464646500')
    
    MsgBox(0,'','done')
EndFunc
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...