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_MACHINESoftwareMicrosoftWindowsCurrentVersionApp Paths
On Windows x64 there is additionally:
HKEY_LOCAL_MACHINESoftwareWow6432NodeMicrosoftWindowsCurrentVersionApp 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.
MicrosoftWindowsCurrentVersionApp 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 HKLMSoftwareMicrosoftWindowsCurrentVersionApp Paths
works for x86 and x64 applications.
But the registry key MicrosoftWindowsCurrentVersionApp 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 HKLMSoftwareMicrosoftWindowsCurrentVersionApp Paths
reads in real HKLMSoftwareWow6432NodeMicrosoftWindowsCurrentVersionApp Paths
containing only x86 applications while x64 applications read really HKLMSoftwareMicrosoftWindowsCurrentVersionApp 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 HKLMSoftwareMicrosoftWindowsCurrentVersionApp Paths
. If the executable name from OpenWithList
can't be found there, a second read attempt should be made on HKLMSoftwareWow6432NodeMicrosoftWindowsCurrentVersionApp 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_USERSoftwareMicrosoftWindowsCurrentVersionApp Paths
and on Windows x64 prior Windows 7 and Windows Server 2008 R2 perhaps only under
HKEY_CURRENT_USERSoftwareWow6432NodeMicrosoftWindowsCurrentVersionApp 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.