Jump to content
Sign in to follow this  

Find the executable of the active window?

Recommended Posts

Question for all... I'm working on a time management program similar to rescuetime (www.rescuetime.com). It's been pretty easy to do with autoit so far, but I'm having a problem with finding the actual process that is running the active window. The window title is easy, as is the actual process ID just using the built in WinGetText and WinGetProcess. Is there a way to get the name of the executable from either the title or the PID? I've searched through the forum here and cant find anything that seems to help, so any and all suggestions appreciated!

Share this post

Link to post
Share on other sites

I found this in Autoit Wrappers .. great additions to your script.

There are many, many other useful scriptlets there to help you!


; Get the execuatble path of a window
; Author gafrost

$path = _WinGetPath()

Func _WinGetPath($Title="", $strComputer='localhost')
    $win = WinGetTitle($Title)
    $pid = WinGetProcess($win)
   $wbemFlagReturnImmediately = 0x10
   $wbemFlagForwardOnly = 0x20
   $colItems = ""
   $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
   $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Process WHERE ProcessId = " & $pid, "WQL", _
         $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
   If IsObj($colItems) Then
      For $objItem In $colItems
         If $objItem.ExecutablePath Then Return $objItem.ExecutablePath


Edited by Valuater


Share this post

Link to post
Share on other sites

Coolness. After looking around some more, I also found a udf that will work as well. The full command is _ProcessGetName(WinGetProcess(WinGetTitle("")))). Thanks all!

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...