Jump to content

Window Tracer


Monamo
 Share

Recommended Posts

Current Build: v1.2 (27 FEB 2009)

I've had to go through hoops too many times trying to track down the originating process when a random notification/dialog pops up on my system. I wrote the following as a quick way to trace them.

Running the script provides you with a small GUI that contains a combobox of visible windows. Selecting a window from the list will provide a messagebox with process information (process executable, file location, PID) and will open the containing folder in Windows Explorer.

If it's of use to you, have at it. Otherwise, thanks for taking a look. Comments welcome.

Version History:

v1.0 (26 FEB 2009) :Note:Codebase is for AutoIt 3.2.10.0 (still at this build by work mandate), so those running the later builds will have to account for the replacement of the GUIConstants.au3 reference with GUIConstantsEx.au3 and possible others.

v1.2 (27 FEB 2009) : Codebase updated to function with AutoIt v3.3.0.0 (Yay for VMWare)

Window_Tracer_v1_2.au3

Edit: code update

Edited by Monamo

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Link to comment
Share on other sites

I'm a new to autoit, When run this script I get this error. Tell me how to fix it plz :P

WARNING: $CBS_DROPDOWNLIST: possibly used before declaration.
$comboWindows = GUICtrlCreateCombo("", 10, 10, $GUIWidth - 20, 20,$CBS_DROPDOWNLIST)

ERROR: $CBS_DROPDOWNLIST: undeclared global variable.
$comboWindows = GUICtrlCreateCombo("", 10, 10, $GUIWidth - 20, 20,$CBS_DROPDOWNLIST)
Link to comment
Share on other sites

I'm a new to autoit, When run this script I get this error. Tell me how to fix it plz :P

WARNING: $CBS_DROPDOWNLIST: possibly used before declaration.
$comboWindows = GUICtrlCreateCombo("", 10, 10, $GUIWidth - 20, 20,$CBS_DROPDOWNLIST)

ERROR: $CBS_DROPDOWNLIST: undeclared global variable.
$comboWindows = GUICtrlCreateCombo("", 10, 10, $GUIWidth - 20, 20,$CBS_DROPDOWNLIST)
you need to add #include <comboconstants.au3> to the beginning of your script
[u]You can download my projects at:[/u] Pulsar Software
Link to comment
Share on other sites

I'm a new to autoit, When run this script I get this error. Tell me how to fix it plz :P

WARNING: $CBS_DROPDOWNLIST: possibly used before declaration.
$comboWindows = GUICtrlCreateCombo("", 10, 10, $GUIWidth - 20, 20,$CBS_DROPDOWNLIST)

ERROR: $CBS_DROPDOWNLIST: undeclared global variable.
$comboWindows = GUICtrlCreateCombo("", 10, 10, $GUIWidth - 20, 20,$CBS_DROPDOWNLIST)
The issue was because the script was written based upon AutoIt v3.2.10.0 (as noted in the original post). There were code changes made in subsequent releases that caused other #include entries to be required. The code in the original post has been updated to support AutoIt v3.3.0.0.

Enjoy!

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Link to comment
Share on other sites

  • 1 year later...

Thank you Monamo

; @AZJIO 22.03.2010
#NoTrayIcon
Global $aVisibleWindows[1] = ["0"], $sTmp, $sTitle

GUICreate("SaveFolders", 500, 200)

GUICtrlCreateLabel("Session", 15, 15, 41, 18)
$Session = GUICtrlCreateCombo("current", 15, 32, 470, 25, 0x3) ; $CBS_DROPDOWNLIST=0x3

GUICtrlCreateLabel("folders", 15, 71, 74, 18)
$Folderlist = GUICtrlCreateCombo("", 15, 88, 470, 25, 0x3)

$Open = GUICtrlCreateButton("Open", 390, 12, 73, 20)
GUICtrlSetTip(-1, "Open session")

$Save = GUICtrlCreateButton("Save", 390, 68, 73, 20)
GUICtrlSetTip(-1, "Save session")

$Openfolder = GUICtrlCreateButton("Open all folders", 80, 130, 130, 33)

$close = GUICtrlCreateButton("Close all folders", 290, 130, 130, 33)

_GetWindows()
_search()

GUISetState ()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $Save
            $file_save = FileSaveDialog( "Save session", @ScriptDir & "", "Session (*.inc)", 24, "Session.inc")
            If @error Then ContinueLoop
            $file = FileOpen($file_save, 2)
            If $file = -1 Then
               MsgBox(0, "Error", "Unable to open file.")
               ContinueLoop
            EndIf
            FileWrite($file, $sTmp)
            FileClose($file)
            
        Case $msg = $Open
            $file_open = FileOpenDialog("Open session", @ScriptDir & "", "Session (*.inc)", 1 + 4 , "Session.inc")
            If @error Then ContinueLoop
            $file = FileOpen($file_open, 0)
            If $file = -1 Then
               MsgBox(0, "Error", "Unable to open file.")
               ContinueLoop
            EndIf
            $sTmp = FileRead($file)
            GUICtrlSetData($Session, $file_open) 
            GUICtrlSetData($Folderlist, $sTmp) 
            FileClose($file)
            
        Case $msg = $Openfolder
            $aPath = StringSplit($sTmp, "|")
            For $i=1 To $aPath [0]
                If FileExists($aPath[$i]) Then Run('Explorer.exe '&$aPath[$i])
            Next
            _GetWindows()
            Sleep(300)
            WinActivate ( "SaveFolders") 
            
        Case $msg = $close
            $aTitle = StringSplit($sTitle, "|")
            For $i=1 To $aTitle [0]
                If WinExists ($aTitle[$i]) And $aTitle[$i] <> "Program Manager" Then WinClose ($aTitle[$i])
            Next
            _GetWindows()
            
        Case $msg = $Session
            $file_open=GUICtrlRead ($Session)
            If $file_open ='current' Then
            _GetWindows()
            Else
            $file = FileOpen($file_open, 0)
            If $file = -1 Then
               MsgBox(0, "Error", "Unable to open file.")
               ContinueLoop
            EndIf
            $sTmp = FileRead($file)
            FileClose($file)
            GUICtrlSetData($Session, $file_open) 
            If $sTmp <> '' Then
            GUICtrlSendMsg($Folderlist, 0x14B, 0, 0)
            GUICtrlSetData($Folderlist, $sTmp)
            EndIf
            EndIf
            
        Case $msg = $Folderlist
                $myFolder = GUICtrlRead($Folderlist)
                If FileExists($myFolder) Then
                    Run('Explorer.exe '&$myFolder)
                EndIf
            ;EndIf
        Case $msg = -3
            Exit
    EndSelect
WEnd

Func _GetWindows()
    GUICtrlSendMsg($Folderlist, 0x14B, 0, 0)
    $AllWindows = WinList()
    $sTmp = ""
    For $i = 1 To $AllWindows[0][0]
        If _IsVisible($AllWindows[$i][1]) Then
    $iPID = WinGetProcess($AllWindows[$i][0])
    $sProcessPath = _ProcessPath($iPID)
            If $AllWindows[$i][0] <> "" And $AllWindows[$i][0] <> "Program Manager" And StringRight($sProcessPath, 12)='explorer.exe' Then
                $iIndex = $aVisibleWindows[0] + 1
                ReDim $aVisibleWindows[$iIndex + 1]
                $aVisibleWindows[0] = $iIndex
                $aVisibleWindows[$iIndex] = $AllWindows[$i][0]
                If $sTmp = "" Then
                    $sTmp &= ControlGetText ( $aVisibleWindows[$iIndex], '', "[CLASS:Edit; INSTANCE:1]")
                    $sTitle &= $aVisibleWindows[$iIndex]
                Else
                    $sTmp &= "|" & ControlGetText ( $aVisibleWindows[$iIndex], '', "[CLASS:Edit; INSTANCE:1]")
                    $sTitle &= "|" & $aVisibleWindows[$iIndex]
                EndIf
            EndIf
        EndIf
    Next
    If $sTmp <> "" Then
        GUICtrlSetData($Folderlist, $sTmp)
    Else
        GUICtrlSetData($Folderlist, "<No Data>")
    EndIf
EndFunc

Func _IsVisible($handle)
    If BitAND(WinGetState($handle), 4) Then
        If BitAND(WinGetState($handle), 2) Then
            Return 1
        Else
            Return 0
        EndIf
    EndIf
EndFunc

Func _search()
$sestmp=''
$search = FileFindFirstFile(@ScriptDir & "\*.inc")
If $search <> -1 Then
While 1
    $file = FileFindNextFile($search) 
    If @error Then ExitLoop
    $sestmp&=@ScriptDir & "\"&$file&'|'
WEnd
EndIf
FileClose($search)
GUICtrlSetData($Session, $sestmp)
EndFunc

Func _ProcessPath($iCheckPID)
    $strComputer = "."
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Process", "WQL", 0x30)

    If IsObj($colItems) Then
        For $objItem In $colItems
            $sProcessPID = $objItem.ProcessId
            If $sProcessPID = $iCheckPID Then
                $sProcessPath = $objItem.ExecutablePath
                ExitLoop
            EndIf
        Next
    EndIf
    If $sProcessPath <> "" Then Return $sProcessPath
EndFunc
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...