Sign in to follow this  
Followers 0
guinness

_AppMon() - Monitor all open instances of your application(s). This includes PID, hWnd and start time of the application.

6 posts in this topic

#1 ·  Posted (edited)

This UDF was created to keep a list of all instances of your application, this includes PID, GUI handle (if added) and the start time of the application. It could be argued that why not use ProcessList('myProg.exe') to acquire basically the same information. Well what if a user changes the executable name?*

So please check out the example below and carefully read the headers on how to use the UDF.

* - >_SelfRename() could be used to avoid this issue.

UDF:

#include-once

; #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7
; #INDEX# =======================================================================================================================
; Title .........: _AppMon
; AutoIt Version : v3.3.2.0 or higher
; Language ......: English
; Description ...: Monitor all open instances of your application(s). This includes PID, hWnd and start time of the application.
; Note ..........:
; Author(s) .....: guinness
; ===============================================================================================================================

; #INCLUDES# ====================================================================================================================
#include <Constants.au3>

; #GLOBAL VARIABLES# ============================================================================================================
; None

; #CURRENT# =====================================================================================================================
; _AppMon_GetArray: Return an array of currently open applications.
; _AppMon_Shutdown: Remove the current application from the AppMon list. This is to be called when the application exits.
; _AppMon_Start: Add the current application to the AppMon list.
; ===============================================================================================================================

; #FUNCTION# ====================================================================================================================
; Name ..........: _AppMon_GetArray
; Description ...: Return an array of currently open applications.
; Syntax ........: _AppMon_GetArray(Const Byref $aAPI[, $fTimeString = Default])
; Parameters ....: $aAPI                - [in/out and const] API created by _AppMon_Start.
;                  $fTimeString         - [optional] Convert the program start time to YYYY/MM/DD HH:MM:SS. Default is False, YYYYMMDDHHMMSS.
; Return values .: Success - An array containing a list of folders.
;                  Failure - Blank array & sets @error to non-zero.
; Author ........: guinness
; Remarks........: The array returned is two-dimensional and is made up as follows:
;                                $aArray[0][0] = Number of applications
;                                $aArray[1][0] = PID
;                                $aArray[1][1] = hWnd of GUI (if previously set in _AppMon_Start.)
;                                $aArray[1][2] = Application start time string.
;                                ...
;                                $aArray[n][0] = PID
;                                $aArray[n][1] = hWnd of GUI (if previously set in _AppMon_Start.)
;                                $aArray[n][2] = Application start time string.
; Example .......: Yes
; ===============================================================================================================================
Func _AppMon_GetArray(ByRef Const $aAPI, $fTimeString = Default)
    Local Enum $sAPIOccurenceName, $sAPIGUID
    #forceref $sAPIOccurenceName

    Local $hWnd = WinGetHandle($aAPI[$sAPIGUID])
    Local $hControl = ControlGetHandle($hWnd, '', 'Edit1')
    Local $sData = ControlGetText($hWnd, '', $hControl)

    Local $aSRE = StringRegExp($sData, 'PID:(\d+)\|hWnd:(0x[[:xdigit:]]+)\|Time:(\d{14})\r\n', 3)
    If @error Then
        Local $aError[1][3] = [[0]]
        Return SetError(1, 0, $aError)
    EndIf

    Local $iUBound = UBound($aSRE)
    Local $aReturn[($iUBound / 3) + 1][3] = [[0]]
    For $i = 0 To ($iUBound - 1) Step 3
        $aReturn[0][0] += 1
        $aReturn[$aReturn[0][0]][0] = Int($aSRE[$i])
        $aReturn[$aReturn[0][0]][1] = HWnd($aSRE[$i + 1])
        $aReturn[$aReturn[0][0]][2] = $aSRE[$i + 2]
        If $fTimeString Then
            $aReturn[$aReturn[0][0]][2] = StringRegExpReplace($aReturn[$aReturn[0][0]][2], '(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})', '\1/\2/\3 \4:\5:\6')
        EndIf
    Next
    Return $aReturn
EndFunc   ;==>_AppMon_GetArray

; #FUNCTION# ====================================================================================================================
; Name ..........: _AppMon_Shutdown
; Description ...: Remove the current application from the AppMon list. This is to be called when the application exits.
; Syntax ........: _AppMon_Shutdown(Const Byref $aAPI)
; Parameters ....: $aAPI                - [in/out and const] API created by _AppMon_Start.
; Return values .: Success - True
;                  Failure - False
; Author ........: guinness
; Example .......: Yes
; ===============================================================================================================================
Func _AppMon_Shutdown(ByRef Const $aAPI)
    Local Enum $sAPIOccurenceName, $sAPIGUID

    Local $hWnd = WinGetHandle($aAPI[$sAPIGUID])
    Local $hControl = ControlGetHandle($hWnd, '', 'Edit1')
    Local $sData = ControlGetText($hWnd, '', $hControl)

    Local $sReplacement = StringRegExpReplace($sData, 'PID:' & @AutoItPID & '\|hWnd:0x[[:xdigit:]]+\|Time:\d{14}\r\n', '')
    If @extended Then
        $sData = $sReplacement
        $sReplacement = ''
        If AutoItWinGetTitle() == $aAPI[$sAPIGUID] Then
            Local $aPID = StringRegExp($sData, 'PID:(\d+)\|hWnd:0x[[:xdigit:]]+\|Time:\d{14}\r\n', 3), $iPID = 0
            If @error = 0 Then
                $iPID = Int($aPID[0])
            EndIf
            Local $aWinList = WinList('[TITLE:' & $aAPI[$sAPIOccurenceName] & '; CLASS:AutoIt v3]')
            For $i = 1 To $aWinList[0][0]
                If $iPID = WinGetProcess($aWinList[$i][1]) Then
                    $hWnd = $aWinList[$i][1]
                    $hControl = ControlGetHandle($hWnd, '', 'Edit1')
                    WinSetTitle($hWnd, '', $aAPI[$sAPIGUID])
                    ExitLoop
                EndIf
            Next
        EndIf
        ControlSetText($hWnd, '', $hControl, $sData)
        Return True
    EndIf
    Return False
EndFunc   ;==>_AppMon_Shutdown

; #FUNCTION# ====================================================================================================================
; Name ..........: _AppMon_Start
; Description ...: Add the current application to the AppMon list.
; Syntax ........: _AppMon_Start([$sOccurenceName = Default[, $hGUI = Default]])
; Parameters ....: $sOccurenceName      - [optional] $sOccurenceName      - [optional] String to identify the occurrence of the script with the unique id. Default is {C1CE8F2E-CC97-11E2-AA40-55F011C84021}.
;                  $hGUI                - [optional] A valid GUI handle. Default is 0x0000000000000000 (no handle.)
; Return values .: API to be passed to relevant functions.
; Author ........: guinness
; Example .......: Yes
; ===============================================================================================================================
Func _AppMon_Start($sOccurenceName = Default, $hGUI = Default)
    Local Enum $sAPIOccurenceName, $sAPIGUID
    Local $aAPI[2]

    $aAPI[$sAPIOccurenceName] = $sOccurenceName
    $sOccurenceName = ''

    If $aAPI[$sAPIOccurenceName] = Default Then
        $aAPI[$sAPIOccurenceName] = '{C1CE8F2E-CC97-11E2-AA40-55F011C84021}'
    EndIf
    $aAPI[$sAPIOccurenceName] = StringStripWS($aAPI[$sAPIOccurenceName], $STR_STRIPALL)
    $aAPI[$sAPIGUID] = '__AppMon__' & $aAPI[$sAPIOccurenceName]
    Local $hWnd = WinGetHandle($aAPI[$sAPIGUID])
    If @error Then
        AutoItWinSetTitle($aAPI[$sAPIGUID])
        $hWnd = WinGetHandle($aAPI[$sAPIGUID])
    Else
        AutoItWinSetTitle($aAPI[$sAPIOccurenceName])
    EndIf

    Local $hControl = ControlGetHandle($hWnd, '', 'Edit1')
    Local $sData = ControlGetText($hWnd, '', $hControl)

    If IsHWnd($hGUI) = 0 Then
        $hGUI = '0x0000000000000000'
    EndIf
    $sData &= 'PID:' & @AutoItPID & '|hWnd:' & $hGUI & '|Time:' & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & @CRLF
    ControlSetText($hWnd, '', $hControl, $sData)
    Return $aAPI
EndFunc   ;==>_AppMon_Start
Example 1:

#include <Array.au3>
#include <GUIConstantsEx.au3>

#include '_AppMon.au3'

Example()

Func Example()
    Local $hGUI = GUICreate('', 400, 300, Random(0, @DesktopWidth - 400, 1), Random(0, @DesktopHeight - 350, 1))

    Local $iLabel = GUICtrlCreateLabel('', 5, 5, 390, 20)
    Local $iCloseAll = GUICtrlCreateCheckbox('Close all instances.', 5, 272.5)
    GUICtrlSetState($iCloseAll, $GUI_CHECKED)

    Local $iAppMon = GUICtrlCreateButton('AppMon', 130, 270, 85, 25)
    Local $iRun = GUICtrlCreateButton('Run', 220, 270, 85, 25)
    Local $iClose = GUICtrlCreateButton('Close', 310, 270, 85, 25)
    GUISetState(@SW_SHOW, $hGUI)

    ; Add the current application to the AppMon list.
    Local $hAppMon = _AppMon_Start('SingletonExample', $hGUI)

    ; Get an array of the currently open applications.
    Local $aAppMon = _AppMon_GetArray($hAppMon, True)
    For $i = 1 To $aAppMon[0][0]
        ; If the AutoIt PID of the current applications matches the same as the array item, then set the GUI title and label.
        If @AutoItPID == $aAppMon[$i][0] Then
            WinSetTitle($hGUI, '', '[' & $i & ' of ' & $aAppMon[0][0] & '] - PID: ' & @AutoItPID)
            GUICtrlSetData($iLabel, 'Application started: ' & $aAppMon[$i][2]) ; Time string.
            ExitLoop
        EndIf
    Next

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $iClose
                ExitLoop

            Case $iAppMon
                $aAppMon = _AppMon_GetArray($hAppMon)
                _ArrayDisplay($aAppMon)

            Case $iRun
                If @Compiled Then
                    Run(@ScriptFullPath, @WorkingDir)
                Else
                    Run(@AutoItExe & ' "' & @ScriptFullPath & '"', @WorkingDir)
                EndIf

        EndSwitch
    WEnd

    ; Close all open applications if the checkbox is selected to do so.
    If BitAND(GUICtrlRead($iCloseAll), $GUI_CHECKED) = $GUI_CHECKED Then
        $aAppMon = _AppMon_GetArray($hAppMon)
        For $i = 1 To $aAppMon[0][0]
            ; So as not to inadvertently close the current application before tidying up.
            If @AutoItPID == $aAppMon[$i][0] Then
                ContinueLoop
            EndIf
            ; Close the GUI handles.
            If WinExists($aAppMon[$i][1]) Then
                WinClose($aAppMon[$i][1])
            EndIf
        Next
    EndIf

    ; Delete the GUI.
    GUIDelete($hGUI)

    ; Remove from the AppMon list.
    _AppMon_Shutdown($hAppMon)
EndFunc   ;==>Example
Example 2:

#include <Constants.au3>
#include <GUIConstantsEx.au3>

#include '_AppMon.au3'

Example()

Func Example()
    Local $hGUI = GUICreate('', 400, 300, Random(0, @DesktopWidth - 400, 1), Random(0, @DesktopHeight - 350, 1))

    Local $iCloseAll = GUICtrlCreateCheckbox('Close all instances.', 5, 272.5)
    GUICtrlSetState($iCloseAll, $GUI_CHECKED)

    Local $iRun = GUICtrlCreateButton('Run', 220, 270, 85, 25)
    Local $iClose = GUICtrlCreateButton('Close', 310, 270, 85, 25)
    GUISetState(@SW_SHOW, $hGUI)

    ; Array of the currently open applications.
    Local $aAppMon = 0

    ; Add the current application to the AppMon list.
    Local $hAppMon = _AppMon_Start('SingletonExample', $hGUI)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $iClose
                ExitLoop

            Case $iRun
                $aAppMon = _AppMon_GetArray($hAppMon)

                ; Allow only 2 instances of an application to be executed.
                If $aAppMon[0][0] = 2 Then
                    MsgBox($MB_SYSTEMMODAL, '', 'Total number of concurrent running applications has been reached.', 0, $hGUI)
                Else
                    If @Compiled Then
                        Run(@ScriptFullPath, @WorkingDir)
                    Else
                        Run(@AutoItExe & ' "' & @ScriptFullPath & '"', @WorkingDir)
                    EndIf
                EndIf
        EndSwitch
    WEnd

    ; Close all open applications if the checkbox is selected to do so.
    If BitAND(GUICtrlRead($iCloseAll), $GUI_CHECKED) = $GUI_CHECKED Then
        $aAppMon = _AppMon_GetArray($hAppMon)
        For $i = 1 To $aAppMon[0][0]
            ; So as not to inadvertently close the current application before tidying up.
            If @AutoItPID == $aAppMon[$i][0] Then
                ContinueLoop
            EndIf
            ; Close the GUI handles.
            If WinExists($aAppMon[$i][1]) Then
                WinClose($aAppMon[$i][1])
            EndIf
        Next
    EndIf

    ; Delete the GUI.
    GUIDelete($hGUI)

    ; Remove from the AppMon list.
    _AppMon_Shutdown($hAppMon)
EndFunc   ;==>Example
All of the above has been included in a ZIP file. AppMon.zip

Previous download 75+.

Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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: 04/09/2015

Share this post


Link to post
Share on other sites



Added an additional second example to show how to limit your application to only 2 instances.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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: 04/09/2015

Share this post


Link to post
Share on other sites

Hello, good job man! Not of any use for me, at the moment, but may be for someone. This is a post to congratulate for the great job, and for you to stop saying you have topics were you don't even got a (one) reply. :)


Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

 

Share this post


Link to post
Share on other sites

Hello, good job man! Not of any use for me, at the moment, but may be for someone. This is a post to congratulate for the great job, and for you to stop saying you have topics were you don't even got a (one) reply. :)

Thanks. I was making a point that last time, I don't care if no one replies. That's a good sign.

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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: 04/09/2015

Share this post


Link to post
Share on other sites

I updated the examples and UDF by replacing 'magic numbers' with the available variable constant values. See first post for download and examples.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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: 04/09/2015

Share this post


Link to post
Share on other sites

The UDF is now deprecated. Please see >AppMonEx for an up to date and manageable UDF.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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: 04/09/2015

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0

  • Similar Content

    • guinness
      By guinness
      This UDF was created because I found a simple approach to the currently available >_AppMon UDF.

      So please check out the example below and carefully read the headers on how to use the UDF.

      UDF:

      #include-once ; #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7 ; #INDEX# ======================================================================================================================= ; Title .........: _AppMon ; AutoIt Version : v3.3.10.0 or higher ; Language ......: English ; Description ...: Monitor all open instances of your application(s). This includes PID, hWnd and start time of the application. ; Note ..........: ; Author(s) .....: guinness ; =============================================================================================================================== ; #INCLUDES# ==================================================================================================================== #include <StringConstants.au3> ; #GLOBAL VARIABLES# ============================================================================================================ Global Const $APPMON_GUID = 'F9A296EE-F58F-11E3-B354-006D0707A45E' Global Enum $APPMON_AUTOIT_TITLE, $APPMON_ID, $APPMON_TITLE, $APPMON_MAX ; #CURRENT# ===================================================================================================================== ; _AppMon_GetArray: Return an array of currently open applications, excluding the application calling this function. ; _AppMon_GetArrayAll: Return an array of currently open applications, including the application calling this function. ; _AppMon_Shutdown: Remove the current application from the AppMon list. This is to be called when the application exits. ; _AppMon_Start: Add the current application to the AppMon list. ; =============================================================================================================================== ; #INTERNAL_USE_ONLY#============================================================================================================ ; See below ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name ..........: _AppMon_GetArray ; Description ...: Return an array of currently open applications, excluding the application calling this function. ; Syntax ........: _AppMon_GetArray(ByRef $aAppMon[, $fTimeString = Default]) ; Parameters ....: $aAppMon - [in/out] Handle created by _AppMon_Start(). ; $fTimeString - [optional] Convert the program start time to YYYY/MM/DD HH:MM:SS. Default is False (YYYYMMDDHHMMSS). ; Return values .: Success - An array containing a details about the running applications. ; Failure - Null & sets @error to non-zero. ; Author ........: guinness ; Remarks........: The array returned is two-dimensional and is made up as follows: ; $aArray[0][0] = PID ; $aArray[0][1] = hWnd of GUI (if previously set in _AppMon_Start().) ; $aArray[0][2] = Application start time string. ; ... ; $aArray[n][0] = PID ; $aArray[n][1] = hWnd of GUI (if previously set in _AppMon_Start().) ; $aArray[n][2] = Application start time string. ; Use UBound() to obtain the length of the array. ; Example .......: Yes ; =============================================================================================================================== Func _AppMon_GetArray(ByRef $aAppMon, $fTimeString = Default) Return __AppMon_Array($aAppMon, False, $fTimeString) EndFunc ;==>_AppMon_GetArray ; #FUNCTION# ==================================================================================================================== ; Name ..........: _AppMon_GetArrayAll ; Description ...: Return an array of currently open applications, including the application calling this function. ; Syntax ........: _AppMon_GetArrayAll(ByRef $aAppMon[, $fTimeString = Default]) ; Parameters ....: $aAppMon - [in/out] Handle created by _AppMon_Start(). ; $fTimeString - [optional] Convert the program start time to YYYY/MM/DD HH:MM:SS. Default is False (YYYYMMDDHHMMSS). ; Return values .: Success - An array containing a details about the running applications. ; Failure - Null & sets @error to non-zero. ; Author ........: guinness ; Remarks........: The array returned is two-dimensional and is made up as follows: ; $aArray[0][0] = PID ; $aArray[0][1] = hWnd of GUI (if previously set in _AppMon_Start()) ; $aArray[0][2] = Application start time string. ; ... ; $aArray[n][0] = PID ; $aArray[n][1] = hWnd of GUI (if previously set in _AppMon_Start()) ; $aArray[n][2] = Application start time string. ; Use UBound() to obtain the length of the array. ; Example .......: Yes ; =============================================================================================================================== Func _AppMon_GetArrayAll(ByRef $aAppMon, $fTimeString = Default) Return __AppMon_Array($aAppMon, True, $fTimeString) EndFunc ;==>_AppMon_GetArrayAll ; #FUNCTION# ==================================================================================================================== ; Name ..........: _AppMon_Shutdown ; Description ...: Remove the current application from the AppMon list. This is to be called when the application exits. ; Syntax ........: _AppMon_Shutdown(ByRef $aAppMon) ; Parameters ....: $aAppMon - [in/out and const] Handle created by _AppMon_Start(). ; Return values .: Success - True ; Failure - False ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func _AppMon_Shutdown(ByRef $aAppMon) If UBound($aAppMon) = $APPMON_MAX And $aAppMon[$APPMON_ID] = $APPMON_GUID Then AutoItWinSetTitle($aAppMon[$APPMON_TITLE] & @AutoItPID) Local Const $hAutoItWnd = WinGetHandle($aAppMon[$APPMON_TITLE] & @AutoItPID) AutoItWinSetTitle($aAppMon[$APPMON_AUTOIT_TITLE]) Local Const $hControl = ControlGetHandle($hAutoItWnd, '', 'Edit1') ControlSetText($hAutoItWnd, '', $hControl, _ StringRegExpReplace(ControlGetText($hAutoItWnd, '', $hControl), _ '(?<=\n)\|APPMON_(?:HWND|PID|TIME):\V+\R', _ '')) For $i = 0 To $APPMON_MAX - 1 $aAppMon[$i] = Null Next EndIf Return True EndFunc ;==>_AppMon_Shutdown ; #FUNCTION# ==================================================================================================================== ; Name ..........: _AppMon_Start ; Description ...: Add the current application to the AppMon list. ; Syntax ........: _AppMon_Start([$sOccurenceName = Default[, $hGUI = Default]]) ; Parameters ....: $sOccurenceName - [optional] A string to identify the occurrence of the script with the unique id. Default is $APPMON_GUID. ; $hWnd - [optional] A valid GUI handle. Default is 0x0000000000000000 (no handle). ; Return values .: Handle to be passed to relevant functions. ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func _AppMon_Start($sOccurenceName = Default, $hWnd = Default) Local $aAppMon[$APPMON_MAX] $aAppMon[$APPMON_ID] = $APPMON_GUID $aAppMon[$APPMON_TITLE] = $sOccurenceName If $aAppMon[$APPMON_TITLE] = Default Then $aAppMon[$APPMON_TITLE] = $APPMON_GUID Else $aAppMon[$APPMON_TITLE] = StringStripWS($aAppMon[$APPMON_TITLE], $STR_STRIPALL) EndIf $aAppMon[$APPMON_AUTOIT_TITLE] = AutoItWinGetTitle() AutoItWinSetTitle($aAppMon[$APPMON_TITLE] & @AutoItPID) Local Const $hAutoItWnd = WinGetHandle($aAppMon[$APPMON_TITLE] & @AutoItPID) AutoItWinSetTitle($aAppMon[$APPMON_TITLE]) Local Const $hControl = ControlGetHandle($hAutoItWnd, '', 'Edit1') ControlSetText($hAutoItWnd, '', $hControl, ControlGetText($hAutoItWnd, '', $hControl) & @CRLF & _ '|APPMON_PID:' & @AutoItPID & '|APPMON_HWND:' & (IsHWnd($hWnd) ? $hWnd : '0x0000000000000000') & '|APPMON_TIME:' & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & @CRLF) Return $aAppMon EndFunc ;==>_AppMon_Start ; #INTERNAL_USE_ONLY#============================================================================================================ Func __AppMon_Array(ByRef $aAppMon, $fIsIncludeCurrent, $fTimeString) Local $iError = 1, _ $vReturn = Null If UBound($aAppMon) = $APPMON_MAX And $aAppMon[$APPMON_ID] = $APPMON_GUID Then Local $aWinList = WinList('[TITLE:' & $aAppMon[$APPMON_TITLE] & ']') ; Don't include the current this process. If ($fIsIncludeCurrent And $aWinList[0][0] > 0) Or $aWinList[0][0] > 1 Then $iError = 0 Local Enum $eAPPMON_PID, $eAPPMON_WND, $eAPPMON_STARTTIME, $eAPPMON_MAX Local $aArray[$aWinList[0][0]][$eAPPMON_MAX], $aSRE = 0, _ $iIndex = 0 For $i = 1 To $aWinList[0][0] $aSRE = StringRegExp(ControlGetText($aWinList[$i][$eAPPMON_WND], '', ControlGetHandle($aWinList[$i][$eAPPMON_WND], '', 'Edit1')), _ '\|APPMON_PID:(\d+)\|APPMON_HWND:(0[xX][[:xdigit:]]+)\|APPMON_TIME:(\d{14})\R', $STR_REGEXPARRAYGLOBALMATCH) If UBound($aSRE) = $eAPPMON_MAX Then If Not $fIsIncludeCurrent And Number($aSRE[$eAPPMON_PID]) = @AutoItPID Then ContinueLoop $aArray[$iIndex][$eAPPMON_PID] = Int($aSRE[$eAPPMON_PID]) $aArray[$iIndex][$eAPPMON_WND] = HWnd($aSRE[$eAPPMON_WND]) $aArray[$iIndex][$eAPPMON_STARTTIME] = $aSRE[$eAPPMON_STARTTIME] If $fTimeString Then $aArray[$iIndex][$eAPPMON_STARTTIME] = StringRegExpReplace($aArray[$iIndex][$eAPPMON_STARTTIME], '(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})', '\1/\2/\3 \4:\5:\6') EndIf $iIndex += 1 EndIf Next ReDim $aArray[$iIndex][$eAPPMON_MAX] $vReturn = $aArray $aArray = 0 EndIf EndIf Return SetError($iError, 0, $vReturn) EndFunc ;==>__AppMon_Array Example 1:
      #include <Array.au3> #include <GUIConstantsEx.au3> #include '_AppMon.au3' Example() Func Example() Local $hGUI = GUICreate('', 400, 300, Random(0, @DesktopWidth - 400, 1), Random(0, @DesktopHeight - 350, 1)) Local $iCloseAll = GUICtrlCreateCheckbox('Close all instances.', 5, 272.5) GUICtrlSetState($iCloseAll, $GUI_CHECKED) Local $iAppMon = GUICtrlCreateButton('AppMon', 130, 270, 85, 25) Local $iRun = GUICtrlCreateButton('Run', 220, 270, 85, 25) Local $iClose = GUICtrlCreateButton('Close', 310, 270, 85, 25) GUISetState(@SW_SHOW, $hGUI) ; Add the current application to the AppMon list. Local $hAppMon = _AppMon_Start('SingletonExample', $hGUI) ; Get an array of the currently open applications not including this instance. Local $aAppMon = _AppMon_GetArray($hAppMon, True) WinSetTitle($hGUI, '', '[' & (UBound($aAppMon) + 1) & '] - PID: ' & @AutoItPID) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $iClose ExitLoop Case $iAppMon ; Get an array of the currently open applications including this instance. $aAppMon = _AppMon_GetArrayAll($hAppMon) _ArrayDisplay($aAppMon) Case $iRun If @Compiled Then Run(@ScriptFullPath, @WorkingDir) Else Run(@AutoItExe & ' "' & @ScriptFullPath & '"', @WorkingDir) EndIf EndSwitch WEnd ; Close all open applications if the checkbox is selected. If BitAND(GUICtrlRead($iCloseAll), $GUI_CHECKED) Then ; Get an array of the currently open applications not including this instance. $aAppMon = _AppMon_GetArray($hAppMon) For $i = 0 To UBound($aAppMon) - 1 ; Close the GUI handle. If WinExists($aAppMon[$i][1]) Then WinClose($aAppMon[$i][1]) Next EndIf ; Delete the GUI. GUIDelete($hGUI) ; Remove from the AppMon list. _AppMon_Shutdown($hAppMon) Return True EndFunc ;==>Example Example 2:
      #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include '_AppMon.au3' Example() Func Example() Local $hGUI = GUICreate('', 400, 300, Random(0, @DesktopWidth - 400, 1), Random(0, @DesktopHeight - 350, 1)) Local $iCloseAll = GUICtrlCreateCheckbox('Close all instances.', 5, 272.5) GUICtrlSetState($iCloseAll, $GUI_CHECKED) Local $iRun = GUICtrlCreateButton('Run', 220, 270, 85, 25) Local $iClose = GUICtrlCreateButton('Close', 310, 270, 85, 25) GUISetState(@SW_SHOW, $hGUI) ; Array of the currently open applications. Local $aAppMon = 0 ; Add the current application to the AppMon list. Local $hAppMon = _AppMon_Start('SingletonExample', $hGUI) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $iClose ExitLoop Case $iRun ; Get an array of the currently open applications not including this instance. $aAppMon = _AppMon_GetArrayAll($hAppMon) ; Allow only 2 concurrent instances of an application to be executed. If UBound($aAppMon) = 2 Then MsgBox($MB_SYSTEMMODAL, '', 'Total number of concurrent running applications has been reached.', 0, $hGUI) Else If @Compiled Then Run(@ScriptFullPath, @WorkingDir) Else Run(@AutoItExe & ' "' & @ScriptFullPath & '"', @WorkingDir) EndIf EndIf EndSwitch WEnd ; Close all open applications if the checkbox is selected. If BitAND(GUICtrlRead($iCloseAll), $GUI_CHECKED) Then ; Get an array of the currently open applications not including this instance. $aAppMon = _AppMon_GetArray($hAppMon) For $i = 0 To UBound($aAppMon) - 1 ; Close the GUI handle. If WinExists($aAppMon[$i][1]) Then WinClose($aAppMon[$i][1]) Next EndIf ; Delete the GUI. GUIDelete($hGUI) ; Remove from the AppMon list. _AppMon_Shutdown($hAppMon) Return True EndFunc ;==>Example All of the above has been included in a ZIP file. AppMonEx.zipPrevious download 260+.