Launching Wordpad on Windows

Patrick L. Nolan pln at razzle.Stanford.EDU
Mon Jan 19 19:50:01 EST 2004


I'm trying to find a clean way to launch a Wordpad editor
on Windows.  By "clean", I mean that it should work on as
many versions of Windows as possible, and it shouldn't
require installing any extra software.  I assume everyone
has win32api and its friends.

The problem is to find the path to wordpad.exe.  At first
I just copied the path from my XP machine:
c:\Program Files\Windows NT\Accessories\WORDPAD.EXE

I verified that the same path works on W2K, but I don't
know about older versions.  With some labor I was able
to come up with a longer, more obfuscated bit of code:

item = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\WORDPAD.EXE"
key = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, item, 0, 
			  win32con.KEY_QUERY_VALUE)
info = win32api.RegQueryValueEx(key, None)
win32api.RegCloseKey(key)
editor = win32api.ExpandEnvironmentStrings(info[0])

I would like to solicit learned opinions about this.  Which
version will work in more versions of Windows?  Is there a
better approach?

-- 
*   Patrick L. Nolan                                          *
*   W. W. Hansen Experimental Physics Laboratory (HEPL)       * 
*   Stanford University                                       *



More information about the Python-list mailing list