Jump to content

Check if the monitor is turned off/standby mode


Tankman
 Share

Recommended Posts

Hi Guys

I need a script for one of my programs that checks the current monitor status.

In specific if my system turned my monitor off.

On MSDN I found the following System Power Event

GUID_MONITOR_POWER_ON

http://msdn.microsoft.com/en-us/library/aa373195%28v=VS.85%29.aspx

Unfortunately I am too much of a beginner at scripting that I just don't know how to get the status of that event.

I hope somebody here can help me.

Greetings, Tankman

Link to comment
Share on other sites

Here is also something to start with

;MsgBox(0, "Started", @ScriptName & " has started.... F11 = Monitor off, F10 = Monitor on, Esc = Exit Program.")
;~ #NoTrayIcon
Opt("TrayMenuMode",1)
Opt ("WinTitleMatchMode", 4)
HotKeySet("{F11}", "MonOff")
HotKeySet("{F10}", "MonOn")
HotKeySet("{Esc}", "Close")

While 1
    Sleep(0x7fffffff)
WEnd

Func Close()
    $hwnd = WinGetHandle('classname=Progman')
    DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', $hwnd, 'int', 274, 'int', 61808, 'int', -1)
    MsgBox(0, "Closing...", "Closing program.....")
    Exit
EndFunc;==>Close

Func MonOn()
    $hwnd = WinGetHandle('classname=Progman')
    DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', $hwnd, 'int', 274, 'int', 61808, 'int', -1)
EndFunc;==>MonOn
Func MonOff()
    $hwnd = WinGetHandle('classname=Progman')
    Sleep(500)
    DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', $hwnd, 'int', 274, 'int', 61808, 'int', 2)
EndFunc;==>MonOff

; Generated by AutoIt Scriptomatic

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

Sleep(5000)

$Output=""
$Output = $Output & "Computer: " & $strComputer  & @CRLF
$Output = $Output & "==========================================" & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_DesktopMonitor", "WQL", _
                                        $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   For $objItem In $colItems
    $Output = $Output & "Availability: " & $objItem.Availability & @CRLF
    $Output = $Output & "Bandwidth: " & $objItem.Bandwidth & @CRLF
    $Output = $Output & "Caption: " & $objItem.Caption & @CRLF
    $Output = $Output & "ConfigManagerErrorCode: " & $objItem.ConfigManagerErrorCode & @CRLF
    $Output = $Output & "ConfigManagerUserConfig: " & $objItem.ConfigManagerUserConfig & @CRLF
    $Output = $Output & "CreationClassName: " & $objItem.CreationClassName & @CRLF
    $Output = $Output & "Description: " & $objItem.Description & @CRLF
    $Output = $Output & "DeviceID: " & $objItem.DeviceID & @CRLF
    $Output = $Output & "DisplayType: " & $objItem.DisplayType & @CRLF
    $Output = $Output & "ErrorCleared: " & $objItem.ErrorCleared & @CRLF
    $Output = $Output & "ErrorDescription: " & $objItem.ErrorDescription & @CRLF
    $Output = $Output & "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF
    $Output = $Output & "IsLocked: " & $objItem.IsLocked & @CRLF
    $Output = $Output & "LastErrorCode: " & $objItem.LastErrorCode & @CRLF
    $Output = $Output & "MonitorManufacturer: " & $objItem.MonitorManufacturer & @CRLF
    $Output = $Output & "MonitorType: " & $objItem.MonitorType & @CRLF
    $Output = $Output & "Name: " & $objItem.Name & @CRLF
    $Output = $Output & "PixelsPerXLogicalInch: " & $objItem.PixelsPerXLogicalInch & @CRLF
    $Output = $Output & "PixelsPerYLogicalInch: " & $objItem.PixelsPerYLogicalInch & @CRLF
    $Output = $Output & "PNPDeviceID: " & $objItem.PNPDeviceID & @CRLF
    $strPowerManagementCapabilities = $objItem.PowerManagementCapabilities(0)
    $Output = $Output & "PowerManagementCapabilities: " & $strPowerManagementCapabilities & @CRLF
    $Output = $Output & "PowerManagementSupported: " & $objItem.PowerManagementSupported & @CRLF
    $Output = $Output & "ScreenHeight: " & $objItem.ScreenHeight & @CRLF
    $Output = $Output & "ScreenWidth: " & $objItem.ScreenWidth & @CRLF
    $Output = $Output & "Status: " & $objItem.Status & @CRLF
    $Output = $Output & "StatusInfo: " & $objItem.StatusInfo & @CRLF
    $Output = $Output & "SystemCreationClassName: " & $objItem.SystemCreationClassName & @CRLF
    $Output = $Output & "SystemName: " & $objItem.SystemName & @CRLF
    if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop
    $Output=""
   Next
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_DesktopMonitor" )
Endif


Func WMIDateStringToDate($dtmDate)

    Return (StringMid($dtmDate, 5, 2) & "/" & _
    StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
    & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc
Edited by Xenobiologist

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Cheer Xenobiologist, AutoIt Scriptomatic somehow slipped under my radar. Wish there was something similar for WinAPI Creation :) But I have WinAPIEx to keep me occupied!

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Thank you Xenobiologist for the quick answer.

I have seen both scripts b4 as I was trying to search for a solution to my problem.

The first script shows a way to turn the monitor off or on but I need a script to check if the monitor is currently off or on.

I was already testing the second script before my original posting.

The field "Availability" of the monitor properties seemed to be just what I was looking for.

Unfortunately the status never changed when the monitor got into standby and back again.

But still thanks for your help.

Link to comment
Share on other sites

I modified the First Script a little...Sorry.

HotKeySet("{F11}", "_MonitorOff")
HotKeySet("{F10}", "_MonitorOn")
HotKeySet("{Esc}", "_Exit")

While 1
    Sleep(1000)
WEnd

Func _Exit()
    _MonitorOn()
    ConsoleWrite("Shutting Down Monitor On & Off" & @CRLF)
    Exit
EndFunc   ;==>_Exit

Func _MonitorOn()
    Local $mo_Opt = Opt("WinTitleMatchMode", 4)
    Local $mo_Handle = WinGetHandle("classname=Progman")
    DllCall("user32.dll", "int", "SendMessage", "hwnd", $mo_Handle, "int", 274, "int", 61808, "int", -1)
    Return Opt("WinTitleMatchMode", $mo_Opt)
EndFunc   ;==>_MonitorOn

Func _MonitorOff()
    Local $mo_Opt = Opt("WinTitleMatchMode", 4)
    Local $mo_Handle = WinGetHandle("classname=Progman")
    Sleep(500)
    DllCall("user32.dll", "int", "SendMessage", "hwnd", $mo_Handle, "int", 274, "int", 61808, "int", 2)
    Return Opt("WinTitleMatchMode", $mo_Opt)
EndFunc   ;==>_MonitorOff

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

  • 3 weeks later...

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...