get monitor power off time ?

is there an api or way to get the current set profile time for a monitor power off setting in the display properties ?
LVL 1
aot2002Asked:
Who is Participating?
 
vinnyd79Connect With a Mentor Commented:
I'll try to write a SetMonitorTimeOut Function but I might not be able to get to it until later today.
0
 
vinnyd79Commented:
Give this a try:


Const HKEY_CURRENT_USER = &H80000001

Private Sub Command1_Click()
Dim strPath As String, regSZ As String
Dim objRegistry As Object
Dim regBinary As Variant
Dim i As Long, Ret As Long, lSecs As Long

Set objRegistry = GetObject("Winmgmts:root\default:StdRegProv")

strPath = "Control Panel\PowerCfg"

Ret = objRegistry.GetStringValue(HKEY_CURRENT_USER, strPath, "CurrentPowerPolicy", regSZ)

If Ret = 0 Then
    strPath = "Control Panel\PowerCfg\PowerPolicies\" & regSZ
    Ret = objRegistry.GetBinaryValue(HKEY_CURRENT_USER, strPath, "Policies", regBinary)
End If

If Ret = 0 Then

    Select Case Hex(regBinary(56))
        Case "3C"
            MsgBox "1 Min"
        Case "78"
            MsgBox "2 Min"
        Case "B4"
            MsgBox "3 Min"
        Case "2C"
            MsgBox "5 Min"
        Case "58"
            MsgBox "10 Min"
        Case "84"
            MsgBox "15 Min"
        Case "B0"
            MsgBox "20 Min"
        Case "DC"
            MsgBox "25 Min"
        Case "08"
            MsgBox "30 Min"
        Case "8C"
            MsgBox "45 Min"
        Case "10"
            MsgBox "1 Hr"
        Case "20"
            MsgBox "2 Hr"
        Case "30"
            MsgBox "3 Hr"
        Case "40"
            MsgBox "4 Hr"
        Case "50"
            MsgBox "5 Hr"
        Case "00"
            MsgBox "Never"
    End Select
   
End If

Set objRegistry = Nothing

End Sub
0
 
vinnyd79Commented:
Try this example instead:

Private Sub Command1_Click()
MsgBox GetMonitorTimeOut
End Sub


Private Function GetMonitorTimeOut() As String
Dim strPath As String, regSZ As String
Dim objRegistry As Object
Dim regBinary As Variant

Set objRegistry = GetObject("Winmgmts:root\default:StdRegProv")

strPath = "Control Panel\PowerCfg"

Ret = objRegistry.GetStringValue(&H80000001, strPath, "CurrentPowerPolicy", regSZ)

If Ret = 0 Then
    strPath = "Control Panel\PowerCfg\PowerPolicies\" & regSZ
    Ret = objRegistry.GetBinaryValue(&H80000001, strPath, "Policies", regBinary)
End If

If Ret = 0 Then

    Select Case Hex(regBinary(56))
        Case "3C"
            GetMonitorTimeOut = "After 1 Min"
        Case "78"
            GetMonitorTimeOut = "After 2 Min"
        Case "B4"
            GetMonitorTimeOut = "After 3 Min"
        Case "2C"
            GetMonitorTimeOut = "After 5 Min"
        Case "58"
            GetMonitorTimeOut = "After 10 Min"
        Case "84"
            GetMonitorTimeOut = "After 15 Min"
        Case "B0"
            GetMonitorTimeOut = "After 20 Min"
        Case "DC"
            GetMonitorTimeOut = "After 25 Min"
        Case "08"
            GetMonitorTimeOut = "After 30 Min"
        Case "8C"
            GetMonitorTimeOut = "After 45 Min"
        Case "10"
            GetMonitorTimeOut = "After 1 Hour"
        Case "20"
            GetMonitorTimeOut = "After 2 Hours"
        Case "30"
            GetMonitorTimeOut = "After 3 Hours"
        Case "40"
            GetMonitorTimeOut = "After 4 Hours"
        Case "50"
            GetMonitorTimeOut = "After 5 Hours"
        Case "0"
            GetMonitorTimeOut = "Never"
    End Select
   
End If

Set objRegistry = Nothing

End Function
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
aot2002Author Commented:
where can i set this too?

Ive increased points
0
 
aot2002Author Commented:
thats cool thanks
0
 
vinnyd79Commented:
For some reason I cannot get this to work.I've tried the SetBinaryValue method and it appears to return successful but it does not make the change. I've also tried API which returns sucessful but again,the changes do not take.
I'll mess around with it some more and see what I can come up with.
0
 
aot2002Author Commented:
yea thats seems to be the problem ive been having !
i've managed to narrow down how to get it to set 20 minutes but not anything else?

heres the code to set 20 minutes interval




'use this for power timeout changes
Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long


If DetectIfRunning("winamp.exe") = True Then
status.Caption = "Winamp is Running"
  Call SystemParametersInfo(82, 0, 0, &H1) 'turn on power profile to 20 minutes
Else
status.Caption = "Winamp is * NOT * Running"
  Call SystemParametersInfo(82, 1200, 0, &H1) 'turn off power profile
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.