Jump to content

2 monitors, 1 movie at night, solved

Recommended Posts


I took some time to make something that will cover both monitors as to watch a movie on one and not have the other monitor shining. You may have a similar setup and like it.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPISys.au3>
#include <WinAPI.au3>

Opt("MustDeclareVars", 1)
Opt("GUICloseOnESC", 0)
Opt("WinTitleMatchMode", 3)

If _WinAPI_GetVersion() < '6.0' Then
    MsgBox(0, 'Error', 'Require Windows Vista or later.')

If WinExists("CoverScreen2") Then Exit ; this should never happen anyways
Global $sTitle = "CoverScreen1"
Global $iLeft = -1
If WinExists($sTitle) Then
    $iLeft = @DesktopWidth + 1000 ; my 2nd monitor is there
    $sTitle = "CoverScreen2"

; AppBar States
Global Const $ABS_NORMAL = 0x0
Global Const $ABS_AUTOHIDE = 0x1
Global Const $ABS_ALWAYSONTOP = 0x2

Global $IsTaskbarHidden = _IsTaskbarHidden()
Global $_iDisplayState = -1
Global $Form2, $bgColor, $exit, $onTop, $minimize, $winMenu, $nMsg, $bttn_Taskbar

$Form2 = GUICreate($sTitle, 557, 367, $iLeft, -1, BitOR($WS_SYSMENU, $WS_POPUP))
$bgColor = 0x404040
If @HOUR > 6 And @HOUR < 19 Then $bgColor = 0xB0B0B0 ; ..can't see the buttons during the day
$exit = GUICtrlCreateLabel("X", 512, 11, 28, 25, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetFont(-1, 12, 400, 0, "Courier New")
GUICtrlSetColor(-1, $bgColor)
$onTop = GUICtrlCreateLabel("o", 480, 12, 28, 25, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetFont(-1, 12, 800, 0, "Courier New")
GUICtrlSetColor(-1, $bgColor)
$minimize = GUICtrlCreateLabel("_", 451, 7, 28, 25, $SS_CENTER)
GUICtrlSetFont(-1, 12, 400, 0, "Courier New")
GUICtrlSetColor(-1, $bgColor)
$winMenu = GUICtrlCreateLabel("M", 14, 290, 28, 25, $SS_CENTER)
GUICtrlSetFont(-1, 12, 400, 0, "Courier New")
GUICtrlSetColor(-1, $bgColor)
$bttn_Taskbar = GUICtrlCreateLabel("T", 422, 11, 28, 25, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetFont(-1, 12, 400, 0, "Courier New")
GUICtrlSetColor(-1, $bgColor)

Local $iRestoreTaskbar = 0
Local $iRestoreTaskbarFirstState = $IsTaskbarHidden
If $IsTaskbarHidden Then
    GUICtrlSetData($bttn_Taskbar, "t")

WinSetOnTop($Form2, "", 0)

If $sTitle = "CoverScreen1" Then
    ShellExecute(@ScriptFullPath) ; <--- i have 2 monitors, this is to cover the 2nd screen,
    ; could have made just 1 big GUI ( WinGetPos("Program Manager") ) but, this is the way I did it.
    _DisplayState($Form2) ; this will tell the GUI to exit if the monitor is off,
    ; so when I wake the monitors this cover foreground won't be there.

GUICtrlSetTip($exit, "close these windows")
GUICtrlSetTip($onTop, "set these as topmost, or not")
GUICtrlSetTip($minimize, "minimize this")
GUICtrlSetTip($winMenu, "click the ""Start"" button")
GUICtrlSetTip($bttn_Taskbar, "set taskbar to auto hide or normal")

While 1

    If $sTitle = "CoverScreen1" Then
        If MouseGetPos(1) > @DesktopHeight - 2 Then
            If MouseGetPos(0) > 10 Then
                WinActivate("[CLASS:Shell_TrayWnd;]", "")

    $nMsg = GUIGetMsg()
    If $_iDisplayState = 0 Then
        $nMsg = $GUI_EVENT_CLOSE
        $iRestoreTaskbar = 1 ; because, that's the way it was and the user did not choose to close it now

    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $exit
            GUICtrlSetColor($exit, $bgColor - 0x202020)
            If $sTitle = "CoverScreen1" Then
                ControlClick("[CLASS:AutoIt v3 GUI; Title:CoverScreen2;]", "", "[CLASS:Static; INSTANCE:1]")
                ControlClick("[CLASS:AutoIt v3 GUI; Title:CoverScreen1;]", "", "[CLASS:Static; INSTANCE:1]")
            If $iRestoreTaskbar Then
                If $iRestoreTaskbarFirstState Then

        Case $minimize
            GUICtrlSetColor($minimize, $bgColor + 0x202020)
            GUICtrlSetColor($minimize, $bgColor)

        Case $onTop
            GUICtrlSetColor($onTop, $bgColor + 0x202020)
            If GUICtrlRead($onTop) == "O" Then
                WinSetOnTop($Form2, "", 0)
                GUICtrlSetData($onTop, 'o')
                WinSetOnTop($Form2, "", 1)
                GUICtrlSetData($onTop, 'O')
            GUICtrlSetColor($onTop, $bgColor)

        Case $winMenu
            GUICtrlSetColor($winMenu, $bgColor - 0x202020)
            GUICtrlSetColor($winMenu, $bgColor)

        Case $bttn_Taskbar
            GUICtrlSetColor($bttn_Taskbar, $bgColor - 0x202020)
            $IsTaskbarHidden = _IsTaskbarHidden()
            If $IsTaskbarHidden Then
                GUICtrlSetData($bttn_Taskbar, "T")
                GUICtrlSetData($bttn_Taskbar, "t")
            GUICtrlSetColor($bttn_Taskbar, $bgColor)
            If $sTitle = "CoverScreen1" Then
                ControlSetText("[CLASS:AutoIt v3 GUI; Title:CoverScreen2;]", "", "[CLASS:Static; INSTANCE:5]", GUICtrlRead($bttn_Taskbar))
                ControlSetText("[CLASS:AutoIt v3 GUI; Title:CoverScreen1;]", "", "[CLASS:Static; INSTANCE:5]", GUICtrlRead($bttn_Taskbar))


; #FUNCTION# ====================================================================================================================
; Name ..........: _DisplayState
; Description ...: Checks if a display is on or off.
; Syntax ........: _DisplayState()
; Parameters ....: GUI handle, or not, see remarks
; Return values..: Success - 1 = screen is on
;                             0 = screen is off
;                  Failure - -1 and sets the @error flag to non-zero.
; Author ........: syk3s
; Modified ......: argumentum on 2015.05.26
; Remarks .......: when a GUI handle is passed, the function will return "-2" and will remain resident. The state is held by Global $_iDisplayState
; Related .......: PG13, works on Win Vista and newer
; Link ..........: @@MsdnLink@@ RegisterPowerSettingNotification
; Example .......: No
; Original post..: https://www.autoitscript.com/forum/topic/152393-getdisplaystate-udf/#comment-1093495
; ===============================================================================================================================
Func _DisplayState($hWndGUI = 0, $MsgID = 0, $WParam = 0, $LParam = 0)
    ;   ConsoleWrite('+ Func _DisplayState(' & $hWndGUI & ', ' & $MsgID & ', ' & $WParam & ', ' & $LParam & ' )' & @CRLF)
    Local Const $_GUID_MONITOR_POWER_ON = '{02731015-4510-4526-99E6-E5A17EBD1AEA}'
    Local Const $_tagGUID = "ulong Data1;ushort Data2;ushort Data3;byte Data4[8]"
    If IsDeclared($_iDisplayState) = 0 Then Global $_iDisplayState = -1
    If $WParam = 0 And $LParam = 0 And $MsgID = 0 Then
        Global $_iDisplayState = -1
        Local Const $_WM_POWERBROADCAST = 0x0218
        Local $hTemp, $tGUID, $Ret
        If $hWndGUI Then
            $hTemp = $hWndGUI ; your Gui and stay resident. $_iDisplayState holds the value
            $hTemp = GUICreate("Display state temporary GUI")
        If IsHWnd($hTemp) = 0 Then
            Return SetError(1, 0, -1)
        If GUIRegisterMsg($_WM_POWERBROADCAST, "_DisplayState") = 0 Then
            Return SetError(2, 0, -1)
        ;register for a display state broadcast
        $tGUID = DllStructCreate($_tagGUID)
        If @error Then
            Return SetError(3, 0, -1)
        $Ret = DllCall('ole32.dll', 'uint', 'CLSIDFromString', 'wstr', $_GUID_MONITOR_POWER_ON, 'ptr', DllStructGetPtr($tGUID))
        If (@error) Or ($Ret[0]) Then
            Return SetError(4, 0, -1)
        $Ret = DllCall('user32.dll', 'ptr', 'RegisterPowerSettingNotification', 'hwnd', $hTemp, 'ptr', DllStructGetPtr($tGUID), 'dword', 0) ;register for the event
        If (@error) Or (Not $Ret[0]) Then
            Return SetError(5, 0, -1)
        If $hWndGUI = 0 Then
            DllCall('user32.dll', 'int', 'UnregisterPowerSettingNotification', 'ptr', $Ret[0]) ;unregister
            Return SetError(0, 0, -2)
        If $_iDisplayState <> 0 And $_iDisplayState <> 1 Then
            Return SetError(6, 0, -1)
            Return $_iDisplayState
        Local $stPOWERBROADCAST_SETTING = DllStructCreate($_tagGUID & ";DWORD;byte[1]", $LParam)
        Local $aResult = DllCall("ole32.dll", "int", "StringFromGUID2", "struct*", DllStructGetPtr($stPOWERBROADCAST_SETTING), "wstr", "", "int", 40) ;get string GUID back
        If $aResult[2] = $_GUID_MONITOR_POWER_ON Then
            $_iDisplayState = DllStructGetData($stPOWERBROADCAST_SETTING, 6, 1)
EndFunc   ;==>_DisplayState

; Detect whether the taskbar is hidden or not.
Func _IsTaskbarHidden() ; https://www.autoitscript.com/wiki/Snippets_%28_Windows_Information_%29
    ;   Local Const $ABS_AUTOHIDE = 0x01,
    Local Const $ABM_GETSTATE = 0x00000004
    Local $aReturn = DllCall('shell32.dll', 'uint', 'SHAppBarMessage', 'dword', $ABM_GETSTATE, 'ptr*', 0)
    If @error Then
        Return SetError(1, 0, 0)
    Return BitAND($aReturn[0], $ABS_AUTOHIDE) = $ABS_AUTOHIDE
EndFunc   ;==>_IsTaskbarHidden

Func _TaskBarSet($iState) ; https://www.autoitscript.com/forum/topic/164237-multi-monitor-and-auto-hide-taskbar-interferes-with-script/
    Local Const $ABM_SETSTATE = 0xA ; Windows XP and later: Sets the state of the appbar's autohide and always-on-top attributes.
    Local $tStruct = DllStructCreate("dword;int;uint;uint;int;int;int;int;int")
    DllStructSetData($tStruct, 1, DllStructGetSize($tStruct))
    DllStructSetData($tStruct, 2, ControlGetHandle("Start", "", "Shell_TrayWnd"))
    DllStructSetData($tStruct, 9, $iState)
    Local $aRet = DllCall("shell32.dll", "int", "SHAppBarMessage", "int", $ABM_SETSTATE, "ptr", DllStructGetPtr($tStruct))
    If Not @error And $aRet[0] Then
        Return $aRet[0]
    Return SetError(1, 0, 0)
EndFunc   ;==>_TaskBarSet

if you have a better idea, post it.

PS: to hide the mouse, move it all the way to the right. All the way to the bottom will popup the taskbar.

Edited by argumentum
tweaked the code

Share this post

Link to post
Share on other sites

I posted this originally to showcase the function _DisplayState() but since I'm at it, might as well make the script more functional.

updated the code:

added to restore the Taskbar as it was when the script it's closed by it self on monitor power down.
changed the buttons color for daytime, as I could not see them.

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

  • Similar Content

    • stoyan
      By stoyan
      Multi-monitor aware window centring function. Can handle various work area setups as outlined below:

      Those are the variants I've tested.
      #include <Math.au3> #include <WinAPI.au3> #include <WinAPIConstants.au3> #include <WinAPIGdi.au3> #include <WinAPISys.au3> #include <WindowsConstants.au3> Func activeWindowCenter() Const $window = WinGetHandle('[ACTIVE]') Const $monitorInfo = _WinAPI_GetMonitorInfo(_WinAPI_MonitorFromWindow($window)) Const $area[] = [DllStructGetData($monitorInfo[1], 1), DllStructGetData($monitorInfo[1], 3), DllStructGetData($monitorInfo[1], 2), DllStructGetData($monitorInfo[1], 4)] Const $size = WinGetPos($window) If @error Then Return EndIf If BitAND(_WinAPI_GetWindowLong($window, $GWL_STYLE), $WS_MAXIMIZE) Then Return EndIf Const $areaWidth = _Max($area[0], $area[1]) - _Min($area[0], $area[1]) Const $windowOffsetX = ($areaWidth - $size[2]) / 2 Const $x = _Min($area[0], $area[1]) + $windowOffsetX Const $areaHeight = _Max($area[2], $area[3]) - _Min($area[2], $area[3]) Const $windowOffsetY = ($areaHeight - $size[3]) / 2 Const $y = _Min($area[2], $area[3]) + $windowOffsetY WinMove($window, '', $x, $y, $size[2], $size[3], 2) EndFunc Here's simple usage:
      ; include the definition HotKeySet('#o', 'activeWindowCenter') While 1 Sleep(1000) WEnd  
    • mmoalem
      By mmoalem
      Hi there - quite a beginner to codding so please bare with me...
      i am writing an autoit code that will be running 24/7 executing various tasks every 10-20 minutes. it suppose to run on unattended server but i would like to occasionally remote log in and do stuff on the server without disturbing the autoit script (while the autoit script is in Sleep count). to achieve this I will need to know at what point in the commands run it is  and how long roughly until the next command (I use Sleep in between commands)...
       so, is there a way to create a monitor that shows me the last command executed and how long of the Sleep is left (like in a small window or in the windows task bar)?
      failing that any idea how can I utilize the FileWriteLog function to keep updating an always open text file ?
      thanks in advance
    • draien
      By draien
      I was searching for a while now and didn't find anything regarding this:
      Is there a function that returns the "number" of the monitor where the mouse is currently on screen? The same number that appears when you open windows-resolution and click on "identify" (or something). I want to trigger an event when the number changes. I wrote something that recognizes leaving the main monitor. But I couldn't get any further than that (maybe with _WinAPI_EnumDisplayMonitors/Devices/Settings ?) and I wouldn't catch an event, if someone has 3 monitors (aligned 1--2--3 with 1 being main monitor) and changes from 2 to 3. 
      Here is my code:
      The GUI was just for testing. Maybe you can give me some hints :)?
    • nitekram
      By nitekram
      I have found the code to do this, but I am wondering how you would change to a second monitor.
      Found the code here, but it might be located on different posts...

      ;=============================================================================== ; ; Function Name: _ChangeScreenRes() ; Description: Changes the current screen geometry, colour and refresh rate. ; Version: ; Parameter(s): $i_Width - Width of the desktop screen in pixels. (horizontal resolution) ; $i_Height - Height of the desktop screen in pixels. (vertical resolution) ; $i_BitsPP - Depth of the desktop screen in bits per pixel. ; $i_RefreshRate - Refresh rate of the desktop screen in hertz. ; Requirement(s): AutoIt Beta > 3.1 ; Return Value(s): On Success - Screen is adjusted, @ERROR = 0 ; On Failure - sets @ERROR = 1 ; Forum(s): <a href='http://www.autoitscript.com/forum/index.php?showtopic=20121' class='bbc_url' title=''>http://www.autoitscript.com/forum/index.php?showtopic=20121</a> ; Author(s): Original code - psandu.ro ; Modifications - PartyPooper ; ;=============================================================================== Func _ChangeScreenRes($i_Width = @DesktopWidth, $i_Height = @DesktopHeight, $i_BitsPP = @DesktopDepth, $i_RefreshRate = @DesktopRefresh) Local Const $DM_PELSWIDTH = 0x00080000 Local Const $DM_PELSHEIGHT = 0x00100000 Local Const $DM_BITSPERPEL = 0x00040000 Local Const $DM_DISPLAYFREQUENCY = 0x00400000 Local Const $CDS_TEST = 0x00000002 Local Const $CDS_UPDATEREGISTRY = 0x00000001 Local Const $DISP_CHANGE_RESTART = 1 Local Const $DISP_CHANGE_SUCCESSFUL = 0 Local Const $HWND_BROADCAST = 0xffff Local Const $WM_DISPLAYCHANGE = 0x007E If $i_Width = "" Or $i_Width = -1 Then $i_Width = @DesktopWidth ; default to current setting If $i_Height = "" Or $i_Height = -1 Then $i_Height = @DesktopHeight ; default to current setting If $i_BitsPP = "" Or $i_BitsPP = -1 Then $i_BitsPP = @DesktopDepth ; default to current setting If $i_RefreshRate = "" Or $i_RefreshRate = -1 Then $i_RefreshRate = @DesktopRefresh ; default to current setting Local $DEVMODE = DllStructCreate("byte[32];int[10];byte[32];int[6]") Local $B = DllCall("user32.dll", "int", "EnumDisplaySettings", "ptr", 0, "long", 0, "ptr", DllStructGetPtr($DEVMODE)) If @error Then $B = 0 SetError(1) Return $B Else $B = $B[0] EndIf If $B <> 0 Then DllStructSetData($DEVMODE, 2, BitOR($DM_PELSWIDTH, $DM_PELSHEIGHT, $DM_BITSPERPEL, $DM_DISPLAYFREQUENCY), 5) DllStructSetData($DEVMODE, 4, $i_Width, 2) DllStructSetData($DEVMODE, 4, $i_Height, 3) DllStructSetData($DEVMODE, 4, $i_BitsPP, 1) DllStructSetData($DEVMODE, 4, $i_RefreshRate, 5) $B = DllCall("user32.dll", "int", "ChangeDisplaySettings", "ptr", DllStructGetPtr($DEVMODE), "int", $CDS_TEST) If @error Then $B = -1 Else $B = $B[0] EndIf Select Case $B = $DISP_CHANGE_RESTART $DEVMODE = "" Return 2 Case $B = $DISP_CHANGE_SUCCESSFUL DllCall("user32.dll", "int", "ChangeDisplaySettings", "ptr", DllStructGetPtr($DEVMODE), "int", $CDS_UPDATEREGISTRY) DllCall("user32.dll", "int", "SendMessage", "hwnd", $HWND_BROADCAST, "int", $WM_DISPLAYCHANGE, _ "int", $i_BitsPP, "int", $i_Height * 2 ^ 16 + $i_Width) $DEVMODE = "" Return 1 Case Else $DEVMODE = "" SetError(1) Return $B EndSelect EndIf EndFunc ;==>_ChangeScreenRes My issue is that I share this desktop with other people...everyone likes to have their own resolutions. I like 1280*1024, where is my coworker likes 1600*1200. I have a script that both of us run all day long, and was trying to change screen on the fly, once the script starts. The trouble: I want all monitors to be the same resolution. As it sits right now, I call this function with my resolution, and would hope it would change all, but only changes one monitor. How do I add to this function to change all or a single monitor to the size I want. Oh, why I say this, all our monitors are not the same, so potentially it could be one changed one way and another change another way.
      Hope I am clear as mud...trying to automatically change display settings, based on user that is on the computer.
      EDIT - i might have found it in the link i posted as that link is not the same code
    • Ascend4nt
      By Ascend4nt
      Process CPU Usage Trackers

      As yet another alternative to the Performance Counters UDF, I've created this UDF to allow easy tracking of one or more processes's CPU usage.  While this has obviously been done before, I haven't seen it done the way I've created it.
      Basically, just as the Performance Counters had Process Counter objects, so this too has Process Usage trackers.  They are relatively simple to use, and require very little interaction other than invoking the functions.
      To create a new tracker object, call one of these:
      _ProcessUsageTracker_Create()   ; Single process tracker _ProcessesUsageTracker_Create() ; Multiple processes tracker The multiple-process tracker requires addition of processes, which can be done one of 2 ways:
      _ProcessesUsageTracker_Add()  ; add a single  process _ProcessesUsageTracker_AddMultiple()  ; multiple processes in a ProcessList-style array After the usage tracker object has been created, stats can be collected via one of two calls:
      _ProcessUsageTracker_GetUsage()  ; single process - returns a percentage _ProcessesUsageTracker_GetUsage()  ; multiple Processes - returns an array of %'s Basically the main loop of the program can be filled with 'GetUsage' calls without juggling anything around.  If a process dies out, an @error code will be returned in the single-process version.  The multiple-process tracker version however lets you retain dead processes in the list although their process handles will be closed.  These can be alternatively cleared up on each call to 'GetUsage' (setting $bRemoveDead to True), or you can opt to clean them up with the following call:
      _ProcessesUsageTracker_RemoveDead() ; Removes any dead processes from the tracker object Finally, to destroy the trackers and close handles, just call the appropriate function:
      _ProcessUsageTracker_Destroy() _ProcessesUsageTracker_Destroy() That's about it.  More info is in the headers.
      Here's an example of a single process cpu usage tracker:
      ; ======================================================================================================== ; <Process_CPUUsageExample.au3> ; ; Example usage of <Process_CPUUsage.au3> ; ; Author: Ascend4nt ; ======================================================================================================== #include "Process_CPUUsage.au3" ;   --------------------    HOTKEY FUNCTION & VARIABLE -------------------- Global $bHotKeyPressed=False Func _EscPressed()     $bHotKeyPressed=True EndFunc ;   --------------------    MAIN PROGRAM CODE   -------------------- HotKeySet("{Esc}", "_EscPressed") Local $hSplash, $sSplashText Local $sProcess, $aProcUsage, $fUsage ; Regular Process: ;~ $sProcess = "firefox.exe" ;~ $sProcess = "sp2004.exe"    ; Stress Prime 2004 ; Protected Process (opens a different way): ;~ $sProcess = "audiodg.exe" ; Processes Requiring elevated privilege (will fail even with limited access rights): ;~ $sProcess = "CTAudSvc.exe" $sProcess = InputBox("Enter Process Name", "Process Name:", "", "", 320, 140) If @error Or $sProcess = "" Then Exit $aProcUsage = _ProcessUsageTracker_Create($sProcess) If @error Then Exit ConsoleWrite("Error calling _ProcessUsageTracker_Create(): " & @error & ", @extended = " & @extended & @CRLF) Sleep(250) $hSplash=SplashTextOn("Process CPU Usage Information", "", 360, 20 + 60, Default, Default, 16, Default, 12) ; Start loop Do     $sSplashText=""     $fUsage = _ProcessUsageTracker_GetUsage($aProcUsage)     If @error Then         ConsoleWrite("Error from _ProcessUsageTracker_GetUsage(): " & @error & ", @extended = " &@extended & @CRLF)         ExitLoop     EndIf     $sSplashText &= "'"&$sProcess&"' CPU usage: " & $fUsage & " %" & @CRLF     $sSplashText &= @CRLF & "[Esc] exits"     ControlSetText($hSplash, "", "[CLASS:Static; INSTANCE:1]", $sSplashText)     Sleep(500) Until $bHotKeyPressed _ProcessUsageTracker_Destroy($aProcUsage) _
      Multiple processes example, which is best used with something like 'chrome' which spawns a number of processes with the same name:
      ; ======================================================================================================== ; <Processes_CPUUsageExample.au3> ; ; Example usage of <Processes_CPUUsage.au3> ; ; Author: Ascend4nt ; ======================================================================================================== #include "Processes_CPUUsage.au3" ;   --------------------    HOTKEY FUNCTION & VARIABLE -------------------- Global $bHotKeyPressed=False Func _EscPressed()     $bHotKeyPressed=True EndFunc ;   --------------------    MAIN PROGRAM CODE   -------------------- HotKeySet("{Esc}", "_EscPressed") Local $hSplash, $sSplashText Local $sProcess, $aProcList, $aProcUsage, $aPercents, $nPercents ; Regular Process: ;~ $sProcess = "firefox.exe" ;~ $sProcess = "sp2004.exe"    ; Stress Prime 2004 ; Protected Process (opens a different way): ;~ $sProcess = "audiodg.exe" ; Processes Requiring elevated privilege (will fail even with limited access rights): ;~ $sProcess = "CTAudSvc.exe" $sProcess = InputBox("Enter Process Name", "Process Name:", "", "", 320, 140) If @error Or $sProcess = "" Then Exit $aProcUsage = _ProcessesUsageTracker_Create() _ProcessesUsageTracker_Add($aProcUsage, "sp2004.exe") _ProcessesUsageTracker_Add($aProcUsage, "CPUStabTest.exe") $aProcList = ProcessList("chrome.exe") _ProcessesUsageTracker_AddMultiple($aProcUsage, $aProcList) _ProcessesUsageTracker_Add($aProcUsage, $sProcess) _ProcessesUsageTracker_Add($aProcUsage, "audiodg.exe") Sleep(250) $hSplash=SplashTextOn("Process CPU Usage Information", "", 380, 24 + 15*2 + $aProcUsage[0][0]*15, Default, Default, 16+4, "Lucida Console", 11) ; Start loop Do     ; DEBUG: Interrupt to allow multiple process termination     ;MsgBox(0, "Next usage", "Next usage time..")     $sSplashText=""     $aPercents = _ProcessesUsageTracker_GetUsage($aProcUsage, True)    ; True = Remove dead     $nPercents = @extended     If @error Then         ConsoleWrite("Error from _ProcessesUsageTracker_GetUsage(): " & @error & ", @extended = " &@extended & @CRLF)         ExitLoop     EndIf     For $i = 0 To $nPercents - 1         $sSplashText &= "'"&$aProcUsage[$i+1][0]&"' [PID #"&$aProcUsage[$i+1][1]&"] CPU usage: " & $aPercents[$i] & " %" & @CRLF     Next     $sSplashText &= @CRLF & "[Esc] exits"     ControlSetText($hSplash, "", "[CLASS:Static; INSTANCE:1]", $sSplashText)     Sleep(500) Until $bHotKeyPressed _ProcessesUsageTracker_Destroy($aProcUsage) ProcessCPUUsage.zip

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.