Jump to content

How do i get the .EXE name of the active window


tbwalker
 Share

Recommended Posts

I'm trying to build a script that will eventually create a log with time stamps of the active windows used on a workstation throughout the day, but I'm having a problem figuring out how to actually get this information.  For example, if someone has Microsoft Word open, I'd like to be able to pop-up/log "word.exe" along with the full path to that file if at all possible (sort of like seeing the application DETAILS name in Windows Task Manager and being able to right-click on the name and choose "Open FIle Location" to get the full path to the file).

Is what I'm asking even possible within the realm of AutoIt?  I have the below script as a test that gets me the current active window handle and title in a message box every 6 seconds, but for the life of me, I don't know what code I need to use to get the actual .EXE name/path of the active window. 

#include <MsgBoxConstants.au3>

Local $i = 0
Do
   Global $handle = WinGetHandle("[ACTIVE]")
   Global $title = WinGetTitle("[ACTIVE]")
   MsgBox(0,"Active Handle & Title",$handle & " - " & $title, 3)
    $i = $i + 1
    Sleep(3000)
Until $i = 100

Any help or suggestions would be greatly appreciated.   I don't mind figuring out the code myself, if someone could just point me in the right direction.

 

Thanks,

TBWalker

Link to comment
Share on other sites

Basically, use WinGetProcess --> PID and match that in ProcessList to get the process name :)

Edited by seadoggie01

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

  • Developers

-or-

; Retrieve the handle of the Notepad window using the classname of Notepad.
Local $hWnd = WinGetHandle("[ACTIVE]")

; Retrieve the identifier of the thread and pass a variable to the $iPID parameter to store the PID.
Local $iPID = 0
Local $iThread = _WinAPI_GetWindowThreadProcessId($hWnd, $iPID)

; Display the process thread, PIDof, processname and processfilename 
ConsoleWrite(' Process thread:'  & $iThread & '  Process ID (PID): ' & $iPID & "  Processname:" & _WinAPI_GetProcessName($iPID) & "  filename:" & _WinAPI_GetProcessFileName($iPID) & @CRLF)

Jos :) 

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

So how exactly will you be using this as it has a bit of a "big brother is watching you" ring to it? :) 

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I work for a global manufacturing company that is trying to come up with cost savings.   We use a lot of Microsoft O365, Adobe and AutoDesk AutoCAD Products, purchasing a large number of licenses for each on an annual subscription. We want to make sure that we aren't issuing licenses for applications, such as Adobe Acrobat DC, When users rarely, if ever, actually launch and use the applications.

 

Since this is a cost savings initiative, the company doesn’t actually want to spend a whole lot of money on methods of auditing, so I thought I would come up with a cheap method that would log to a text file whenever a specific application was used.  I would program it to look specifically for the Adobe, Microsoft, and AutoCAD applications we are paying mega bucks on licensing,  then after 30 days we would collect the log files from all of the computers globally  (probably have each computer automatically write the log files to a location on the domain controller when they connect to our network), And simply do a plain English windows search including content of the text log files to see which files contain activity for specific licenses.

Text files with license activity would be put in a separate folder, and those text files with no license activity would be put in the folder for us to contact the users and verify directly that they are not using the application, therefore allowing us to recover license so we do not over purchase.

I don’t know if this is going to work out, but it sort of the basic plan.

 

Thanks again for your assistance 

Edited by tbwalker
Link to comment
Share on other sites

  • Developers

Understood, but there is a thin line between monitoring for efficiency and invading employees privacy, so I guess/hope this is made known to them and won't be running hidden. 

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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

×
×
  • Create New...