Search code examples
pythonwindowspywin32

Access Most Recently Used (MRU) entries via Python on Windows?


Using Python, is it possible to get access to the Most Recently Used (MRU) list in windows. This is where Windows keeps a list of the most recently opened documents and programs.

Thanks!


Solution

  • Possible: yes, easy yes. the challenge though is choosing which MRU to choose from... windows and programs stores dozens of em - windows alone probably stores 6 of them. presuming you want the Windows run dialogue you can get it like so (Python 2x syntax, tested on python 2.7):

    def get_run_mru():
        import _winreg
        regKey = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER,
            r'Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU')
        recent = _winreg.QueryValueEx(regKey,'MRUList')[0]
        recent_list = []
        for subkey in recent:
            recent_list.append(_winreg.QueryValueEx(regKey,subkey)[0])
        return recent_list
    

    Of course then you'll have to do whatever you want to do with that but that should get you started.

    Pacific