Jump to content
tbwalker

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

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

-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

Share this post


Link to post
Share on other sites

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

Jos

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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

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

  • Similar Content

    • By matwachich
      AutoIt3 Lua Wrapper
      This is an AutoIt3 wrapper for the Lua scripting language. Consider it beta software, but since I will be using it in commercial product, expect it to evolve.
      It has been developped with Lua 5.3.5. Updates will come for new Lua version.
      Everything works just fine, except one (big) limitation: Anything that throws a Lua error (using C setjmp/longjmp functionality) will crash your AutoIt program. That means that it is impossible to use throw errors from an AutoIt function called by Lua (luaL_check*, lua_error...).
      It is hosted in Github: https://github.com/matwachich/au3lua
      Simple example
      #include <lua.au3> #include <lua_dlls.au3> ; Initialize library _lua_Startup(_lua_ExtractDll()) OnAutoItExitRegister(_lua_Shutdown) ; create new execution state $pState = _luaL_newState() _luaopen_base($pState) ; needed for the lua's print function $iRet = _luaL_doString($pState, 'print("Hello, world!")') If $iRet <> $LUA_OK Then ; read the error description on top of the stack ConsoleWrite("!> Error: " & _lua_toString($pState, -1) & @CRLF) Exit EndIf ; close the state to free memory (you MUST call this function, this is not AutoIt's automatic memory management, it's a C library) _lua_close($pState)
    • By gahhon
      I am not very sure if I am all right to post here tho. Due to other forums have no respond at all.
      So I have my custom make google chrome extension, and it will load unpack into Portable Google Chrome, but it keep pop up the alert box

      Is there any way to disable it? Because my Portable Google Chrome will load as Kiosk mode, so that user can't be uninstall/disable the extension.
      Many thanks in advance.
    • By TheSaint
      Files Checklist
      Just a simple little (complex enough) program I whipped up, for a purpose ... but only too happy to share.
      It can of course be modified to do more, but at the moment just compares file names with or without path ... Location versus Checklist.
      There are of course other compare programs out there, most doing a lot more than mine (i.e. WinMerge or FileComparer). But I wanted something quick and simple with drag & drop, that uses up a smallish amount of screen real estate.
      NOTE - The SAVE button is also a LOAD one, and displays 'Load' when the list is empty. So you can save and load specific lists. While in SAVE mode, the button can also be used with CTRL held down, to ADD another list to existing (displayed one) ... combining as they say ... though not saved until you SAVE. CLEAR button removes a selected entry, or if used with CTRL held down, queries about removing all listed entries.
              
      Files Checklist v1.2.zip
      Files Checklist v1.3.zip
      Files Checklist v1.4.zip  (Includes a BUGFIX.)
        (source included)
      WARNING - While this program does not act on files or folders ADDED or CHECKED, you might act on the results, so I advise caution, and I also recommend using the new 'Relative' option in v1.3 or newer ... but you still need to understand what you are doing and what the results actually mean. Some basic examples in the next post.
      Enjoy!
      RELATED
      Users might also be interested in another somewhat related program of mine.
      DeleteIf Same
      Cheers!
    • By nacerbaaziz
      Hello
      I have an inquiry from you
      I have a file path  with commands line
      Is there a way to separate the path from the commands line?
      I want the result in an array
      for example
      $path = '"c:\NVDA\NVDA slav Portable 1\NVDA.exe" -r -m -path="d:\NVDA Path\Portable"'
      there are any method to separate this text?
      i want the result to be as that
      $array[1] = "c:\NVDA\NVDA slav Portable 1\NVDA.exe"
      $array[2] = '-r -m -path="d:\NVDA Path\Portable"'
      Thanks in advance
      am Waiting for your answers
    • By Seminko
      In my recent project I'm downloading a bunch of data, so I decided to store it in a SQLite database. NOTE: I'm using sqlite3_x64.dll
      Everything is working just fine but I'm struggling with getting the Median value. SQLite has an Average function but not a Median one.
      I googled but all of the provided solutions are way above my pay-grade. After some more searching I found 'extension-functions.c' on the SQLite site where Median is included. After almost an hour of struggling I was able to successfully compile it into a DLL.
      So I downloaded @jchd's SQLiteExtLoad.au3 as seen here:
      But I'm getting these errors:
      "Path\SQLiteExtLoad.au3"(21,40) : warning: $g_hDll_SQLite: possibly used before declaration. Local $RetVal = DllCall($g_hDll_SQLite, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ "Path\SQLiteExtLoad.au3"(21,40) : error: $g_hDll_SQLite: undeclared global variable. Local $RetVal = DllCall($g_hDll_SQLite, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ So I tried, copying the function to my file and changing the DLL variable ($g_hDll_SQLite) directly to the DLL location (C:\...\.. .dll), but now this error fires
      If __SQLite_hChk($hConn, 1) Then Return SetError(@error, 0, $SQLITE_MISUSE) To be honest, I don't know what to use as the $hConn - handle of connection.
      I would appreciate any help, be it getting the median using SQLite queries or getting the DLL extension loaded using AutoIt.
      Thanks, S.
       
      EDIT: well, I suspect the $hConn variable refers to the return value of the _SQLite_Open function. Well, at least now _SQLite_EnableExtensions doesn't give errors. Now I run into problems with _SQLite_LoadExtension, which gives error -1, and extended 1. Apparently the 1 constant is a generic error where other error do not apply.
      BTW, anybody knows whether I need to compile the extension DLL "into" x64 when I use a x64 SQLite? That might be the problem...
       
      EDIT2: I recompiled the dll and tried it using the SQLite3.exe and it works, so I'm confident the extension DLL has been created correctly

×
×
  • Create New...