It is indeed difficult to find out which of the installed applications is suitable for editing XML files, i.e. are text editors.
Evaluating the OpenWithList
of .txt
in automatically by Windows Explorer managed FileExts
list is a good idea. But this list contains just the file name of the executable without path.
The executable with full path can be read from:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App Paths
On Windows x64 there is additionally:
HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\App Paths
Those registry keys contain the list of installed applications. Each executable has a key below App Paths
. The default string of each application key is the file name of the executable with full path. The often also existing Path
string is optional and therefore does not always exist.
All applications regularly installed are listed under App Paths
with exception of Notepad. But Notepad always exists on Windows in directory %windir%
respectively %SystemRoot%
. So with getting value of environment variable windir or SystemRoot, the full file name of Notepad can be determined easily by code.
The only applications not listed under App Paths
are those just copied to hard disk or extracted from an archive file without running an installer. But text editors are usually installed with an installer and not by copying or extracting all program files of the text editor to a directory.
Microsoft\Windows\CurrentVersion\App Paths
is shared since Windows 7 and Windows Server 2008 R2 according to Microsoft article Registry Keys Affected by WOW64. This means the two registry paths have same database. Therefore each modification made in any of the two App Paths
is automatically immediately also visible on the other path. And reading from HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths
works for x86 and x64 applications.
But the registry key Microsoft\Windows\CurrentVersion\App Paths
is just redirected on x64 version of Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP. This means an x86 application reading HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths
reads in real HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\App Paths
containing only x86 applications while x64 applications read really HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths
containing x64 applications.
Which strategy to use for finding the application path on x64 Windows is therefore not easy to choose. I suggest to search for an executable first in HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths
. If the executable name from OpenWithList
can't be found there, a second read attempt should be made on HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\App Paths
. On a query/read access nothing more than a not found can happen if the machine is running Windows x86.
The Microsoft article Application Registration explains registration of applications. As it can be read there an application can be installed also by a user just for current user when the user does not have administrator privileges. In this case the application is registered under
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths
and on Windows x64 prior Windows 7 and Windows Server 2008 R2 perhaps only under
HKEY_CURRENT_USER\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\App Paths
Those 2 registry paths should be also searched for name of the executable from OpenWithList
.
By the way: The command start of Windows command line interpreter uses also App Paths
registry key to find an application to start, see Where is “START” searching for executables?
I suggest additionally a check box option Remember my choice to make it possible for the user to select only once the preferred viewer/editor application for XML files. Your application should preselect the appropriate application on next opening of the dialog when this check box was used before if the once selected application still exists in remembered directory.
Another check box option could be Always use selected application with when checked once results in opening the XML file next time automatically in the once selected application without displaying the dialog to select an application for viewing/editing the XML file if the once selected application still exists in remembered directory.