winapi - Get Application Name from .exe file in python -
i getting both active window title , exe filepath code below
hwnd = win32gui.getforegroundwindow() _, pid = win32process.getwindowthreadprocessid(hwnd) if hwnd != 0 or pid != 0: try: hndl = win32api.openprocess(win32con.process_query_information | win32con.process_vm_read, 0, pid) self.newexe = win32process.getmodulefilenameex(hndl, 0) self.newwindowtitle = win32gui.getwindowtext(hwnd) except: self.newexe = '' self.newwindowtitle = ''
the issue although is, window title not application name (the name users understand main part of application) , need. example calc.exe calculator withiout relying on window title.
the purpose create script log in xml comparative use of software on computer
is possible?
most windows applications store information such inside resource tables. there api calls can used extract this.
the following extracts file description given application:
import win32api def getfiledescription(windows_exe): try: language, codepage = win32api.getfileversioninfo(windows_exe, '\\varfileinfo\\translation')[0] stringfileinfo = u'\\stringfileinfo\\%04x%04x\\%s' % (language, codepage, "filedescription") description = win32api.getfileversioninfo(windows_exe, stringfileinfo) except: description = "unknown" return description print getfiledescription(r"c:\program files\internet explorer\iexplore.exe")
the output is:
internet explorer
you therefore pass result of call win32process.getmodulefilenameex()
function.
Comments
Post a Comment