Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

get monitor power off time ?

Posted on 2005-05-16
7
Medium Priority
?
121 Views
Last Modified: 2010-05-01
is there an api or way to get the current set profile time for a monitor power off setting in the display properties ?
0
Comment
Question by:aot2002
  • 4
  • 3
7 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 14013433
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
 
LVL 28

Expert Comment

by:vinnyd79
ID: 14013513
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
 
LVL 1

Author Comment

by:aot2002
ID: 14014700
where can i set this too?

Ive increased points
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 28

Accepted Solution

by:
vinnyd79 earned 2000 total points
ID: 14018074
I'll try to write a SetMonitorTimeOut Function but I might not be able to get to it until later today.
0
 
LVL 1

Author Comment

by:aot2002
ID: 14019687
thats cool thanks
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 14027357
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
 
LVL 1

Author Comment

by:aot2002
ID: 14032364
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question