Jump to content
Sign in to follow this  
FitzChivalry

Find the executable of the active window?

Recommended Posts

FitzChivalry

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
Valuater

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

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

Maybe...

; Get the execuatble path of a window
; Author gafrost

$path = _WinGetPath()
MsgBox(0,WinGetTitle(""),$path)

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
      Next
   EndIf
EndFunc

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites
FitzChivalry

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  

×

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.