Jump to content
Sign in to follow this  
Ward Gerlach

RunAsSet Acting Oddly When Setting Power Schemes

Recommended Posts

Ward Gerlach

CODE
; ----------------------------------------------------------------------------

;

; AutoIt Version: 3.2.4.9

;

; Script Function: Configure power schemes in WinXP/W2K -

; Set everything to always on.

;

; Expand all types of variables inside strings

Opt("ExpandEnvStrings",1)

Opt("ExpandvarStrings",1)

; Require all variables to be declared

Opt("MustDeclareVars",1)

; ----------------------------------------------------------------------------

;

; Include files

;

#include <File.au3>

;

;Declare Variables

;

Dim $CurrPwrScheme

Dim $AvailPwrScheme

Dim $CurrDateTime

Dim $CurrMon

Dim $CurrDay

Dim $CurrYear

Dim $CurrHour

Dim $CurrMin

Dim $CurrUser

;

; Set var $CurrDateTime

;

$CurrYear=@YEAR

$CurrMon=@MON

$CurrDay=@MDAY

$CurrHour=@HOUR

$CurrMin=@MIN

$CurrDateTime=$CurrYear & $CurrMon & $CurrDay & " " & $CurrHour & ":" & $CurrMin

;

; MsgBox (64, "Date/Time for log", $CurrDateTime)

;

;

; Get current user

;

$CurrUser= @UserName

;

; Set admin rights

;

RunAsSet ("Administrator", @ComputerName, "PACKERS")

;

; Get the current power scheme. If the current power scheme is

; "Presentation" then we can quit.

;

RunWait (@ComSpec & " /c c:\windows\system32\powercfg.exe /query > c:\currpwr.txt")

_FileReadToArray("C:\currpwr.txt", $CurrPwrScheme)

;MsgBox (64, "Current Power Scheme", $CurrPwrScheme[4])

If StringRight($CurrPwrScheme[4],12) = "Presentation" Then

;MsgBox (64, "Current Power Scheme", StringRight($CurrPwrScheme[4],12))

Exit

EndIf

RunWait (@ComSpec & " /c c:\windows\system32\powercfg.exe /setactive Presentation")

$File=FileOpen ("C:\Logs\PowerCfgLog.txt",2)

FileWrite ($File, $CurrDateTime & $CurrUser & "Power scheme 'Presentation' set OK." & @CRLF)

FileClose ($File)

RunAsSet ()

Built a little script to change the Power Scheme on Win2K/XP workstations from what ever is currently set to "Presentation" - which is exactly what it does as long as the user has admin privileges and RunAsSet isn't used.

When RunAsSet is used, the script appears to run OK - but the Power Scheme is not changed.

I've used RunAsSet before without this problem. Anybody got any idea of what's wrong?

Share this post


Link to post
Share on other sites
wkain1

The power settings are per user settings (HKCU registry). Since doing a RunAsSet with no options it is applying to the administrator account and not the logged on user. If you logged in as administrator the power scheme would be set as presentation. Try this:

RunAsSet ("Administrator", @ComputerName, "PACKERS", 0)

Which will not load the user profile and should use the currently logged in user's HKCU.

Share this post


Link to post
Share on other sites
Ward Gerlach

The power settings are per user settings (HKCU registry). Since doing a RunAsSet with no options it is applying to the administrator account and not the logged on user. If you logged in as administrator the power scheme would be set as presentation. Try this:

RunAsSet ("Administrator", @ComputerName, "PACKERS", 0)

Which will not load the user profile and should use the currently logged in user's HKCU.

Ahhhh.... that flash you saw on the horizon was {LightBulb ON}!

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.