Jump to content

Search the Community

Showing results for tags 'monitor'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office


  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start



Member Title




Found 8 results

  1. PDH Performance Counters Measure Process, CPU, Network, Process, Disk (etc) Usage (note that the above dialog appears differently on Vista+) New ObjectBase interface!! *x64 and Localization Issues have been resolved!* *Download and License agreement are at the bottom of this post! About The Project: Performance Counters gather all kind of performance data about the PC and the Network using the standard PDH.DLL module (standard since Windows 2000). Among the performance data you can collect and monitor are: Processor Stats (including total usage)Process (programs) Stats (including CPU usage)Disk Stats (speed/access)TCP, UDP, IP Connection Counts, Speed/Error StatsNetwork Stats..and so onNote that one example is a WIP. 'TaskManager' mockup UDF, I'm looking at you. You can jump right in, download the two AutoIT files (below) and run one of the following to see what the PDH Performance Counters project can get you: TestPDH_PerformanceCounters - this is where you should start! It allows you to visually experiment with most all of the Counters available on your PC and Network. NOTES: - Currently the 'Refresh' rate is set to 1/2 second - this can be changed by altering the Adlib() function frequency - New Counters that come into existence during monitoring will *not* be added to the list (this would be a function I've yet to add) - Counters that become invalid are simply given a prefix of '[Dead Counter Handle]:' TestPDH_ProcessLoop - this basically repeatedly shows an extended Process-information list for all processes. NOTE: You must hit 'ESC' to exit the loop TestPDH_TaskManager - this gathers and displays most everything you'd see in the Process and Performance sections of Task Manager. NOTES: - The screen does NOT update, and the UDF is a MESS. This is due to a number of reasons - the biggest one being laziness on my behalf. Plus I need to figure out how best to manage ListView changes. - TWO fields need Windows XP+ to display correctly (or a version of psapi.dll that supports 'GetPerformanceInfo'): Commit Charge (Peak) and System Cache TestPDH_ProcessGetRelatives - this shows how the PDH Performance Counters can be used to get 'parent' and 'children' process information. There are more practical means of getting this info of course (a few you'll see in my 'Process Functions' module, but hey - its just yet another example of what can be done.TestPDH_ObjectTests - this is more for reading/understanding the code than anything. It is there to show how the new 'ObjectBase' Interface works to make coding Performance Counters *much* easier.Multipile extra 'TestPDH*' examplesAt its most basic, interacting with Performance Counters is as such: The brand new ObjectBase Interface removes some of the difficulty in interacting with Performance Counters, and works like this: Examples of the new ObjectBase interface: % CPU Usage of a Process % CPU Usage of Multiple Instances of a Process (+monitoring and adjustment based on new/dead Instances) Other Examples: Waiting for Hard Disk activity to Idle for 'x' ms % System CPU Usage (by Processor) Network Usage (bytes sent/received) I've put a LOT of work into this project, and all I ask is that you follow my License Agreement when using the code (very easy, see below). Any feedback is welcome. I apologize for the unpolished GUI interfaces (especially the unfinished one), but I will get to that TaskManager GUI one day, hah. Enough chatter -now go on and experience the awesome power of Performance Counters Download the ZIP Here NOTE: Bundled in the ZIP (and included in the License agreement) are other UDF's I wrote that are necessary to run some of the 'Test' programs:_WinAPI_GetSystemInfo.au3, _WinAPI_GetPerformanceInfo.au3, _WinTimeFunctions.au3, and the unnecessary, but provided for those who are interested in the _WinTimeFunctions 'filetime' usage, program: TestWinTimeFunctions.au3. Ascend4nt's AutoIT Code License agreement: While I provide this source code freely, if you do use the code in your projects, all I ask is that: If you provide source, keep the header as I have put it, OR, if you expand it, then at least acknowledge me as the original author, and any other authors I creditIf the program is released, acknowledge me in your credits (it doesn't have to state which functions came from me, though again if the source is provided - see #1)The source on it's own (as opposed to part of a project) can not be posted unless a link to the page(s) where the code were retrieved from is provided and a message stating that the latest updates will be available on the page(s) linked to.Pieces of the code can however be discussed on the threads where Ascend4nt has posted the code without worrying about further linking.Enjoy!Ascend4nt UPDATES:
  2. 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
  3. 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 michel
  4. Hi 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 :)?
  5. 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. #NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile_type=a3x #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.') Exit EndIf 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" EndIf ; AppBar States Global Const $ABS_NORMAL = 0x0 Global Const $ABS_AUTOHIDE = 0x1 Global Const $ABS_ALWAYSONTOP = 0x2 Global Const $ABS_AUTOHIDEANDONTOP = 0x3 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)) GUISetBkColor(0x000000) $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) GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT) $onTop = GUICtrlCreateLabel("o", 480, 12, 28, 25, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetFont(-1, 12, 800, 0, "Courier New") GUICtrlSetColor(-1, $bgColor) GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT) $minimize = GUICtrlCreateLabel("_", 451, 7, 28, 25, $SS_CENTER) GUICtrlSetFont(-1, 12, 400, 0, "Courier New") GUICtrlSetColor(-1, $bgColor) GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT) $winMenu = GUICtrlCreateLabel("M", 14, 290, 28, 25, $SS_CENTER) GUICtrlSetFont(-1, 12, 400, 0, "Courier New") GUICtrlSetColor(-1, $bgColor) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT) $bttn_Taskbar = GUICtrlCreateLabel("T", 422, 11, 28, 25, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetFont(-1, 12, 400, 0, "Courier New") GUICtrlSetColor(-1, $bgColor) GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT) Local $iRestoreTaskbar = 0 Local $iRestoreTaskbarFirstState = $IsTaskbarHidden If $IsTaskbarHidden Then GUICtrlSetData($bttn_Taskbar, "t") EndIf GUISetState(@SW_MAXIMIZE) WinSetOnTop($Form2, "", 0) GUISetState(@SW_SHOWMINNOACTIVE) 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. EndIf 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;]", "") EndIf EndIf EndIf $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 EndIf 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]") Else ControlClick("[CLASS:AutoIt v3 GUI; Title:CoverScreen1;]", "", "[CLASS:Static; INSTANCE:1]") EndIf GUIDelete($Form2) If $iRestoreTaskbar Then If $iRestoreTaskbarFirstState Then _TaskBarSet($ABS_AUTOHIDEANDONTOP) Else _TaskBarSet($ABS_ALWAYSONTOP) EndIf EndIf ExitLoop Case $minimize GUICtrlSetColor($minimize, $bgColor + 0x202020) GUISetState(@SW_MINIMIZE) Sleep(200) GUICtrlSetColor($minimize, $bgColor) Case $onTop GUICtrlSetColor($onTop, $bgColor + 0x202020) If GUICtrlRead($onTop) == "O" Then WinSetOnTop($Form2, "", 0) GUICtrlSetData($onTop, 'o') Else WinSetOnTop($Form2, "", 1) GUICtrlSetData($onTop, 'O') EndIf Sleep(200) GUICtrlSetColor($onTop, $bgColor) Case $winMenu GUICtrlSetColor($winMenu, $bgColor - 0x202020) Send("^{ESC}") Sleep(200) GUICtrlSetColor($winMenu, $bgColor) Case $bttn_Taskbar GUICtrlSetColor($bttn_Taskbar, $bgColor - 0x202020) $IsTaskbarHidden = _IsTaskbarHidden() If $IsTaskbarHidden Then _TaskBarSet($ABS_ALWAYSONTOP) GUICtrlSetData($bttn_Taskbar, "T") Else _TaskBarSet($ABS_AUTOHIDEANDONTOP) GUICtrlSetData($bttn_Taskbar, "t") EndIf GUICtrlSetColor($bttn_Taskbar, $bgColor) If $sTitle = "CoverScreen1" Then ControlSetText("[CLASS:AutoIt v3 GUI; Title:CoverScreen2;]", "", "[CLASS:Static; INSTANCE:5]", GUICtrlRead($bttn_Taskbar)) Else ControlSetText("[CLASS:AutoIt v3 GUI; Title:CoverScreen1;]", "", "[CLASS:Static; INSTANCE:5]", GUICtrlRead($bttn_Taskbar)) EndIf EndSwitch WEnd ; #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 Else $hTemp = GUICreate("Display state temporary GUI") EndIf If IsHWnd($hTemp) = 0 Then Return SetError(1, 0, -1) EndIf If GUIRegisterMsg($_WM_POWERBROADCAST, "_DisplayState") = 0 Then Return SetError(2, 0, -1) EndIf ;register for a display state broadcast $tGUID = DllStructCreate($_tagGUID) If @error Then Return SetError(3, 0, -1) EndIf $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) EndIf $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) EndIf If $hWndGUI = 0 Then DllCall('user32.dll', 'int', 'UnregisterPowerSettingNotification', 'ptr', $Ret[0]) ;unregister GUIDelete($hTemp) Else Return SetError(0, 0, -2) EndIf If $_iDisplayState <> 0 And $_iDisplayState <> 1 Then Return SetError(6, 0, -1) Else Return $_iDisplayState EndIf Else 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) EndIf EndIf 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) EndIf 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] EndIf Return SetError(1, 0, 0) EndFunc ;==>_TaskBarSet if you have a better idea, post it. Thanks PS: to hide the mouse, move it all the way to the right. All the way to the bottom will popup the taskbar.
  6. 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
  7. 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
  8. Hi all, I'm in the middle of writing a print queue monitor. I would like to be able to run this on our print server to be able to track who's printing large amounts and reduce the effect on the environment. I've done a fair chunck of it, but I'm finding that it's causing a bit of a load on the CPU. On average the 'spoolsv.exe' process sits at about 15-20% constantly when nothing is happening. I'm wondering if there is a way I can reduce this. I'm using the following code to access the print queue. ; Connect to Print Queue $objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2") While 1 $AllPrintJobs = $objWMIService.ExecQuery ("SELECT * FROM Win32_PrintJob") ; Run through Print Jobs For $PrintJob In $AllPrintJobs ; Process any new jobs here Next Sleep (50) WEnd I've found that I have to catch the job several times in the queue. If I don't I can miss the total number of pages as the jobs spools. Is there another way of me getting the same information? Does the information go to another location after the print queue?
  • Create New...