如何枚举所有可以以纯文本形式打开XML文件的程序? [英] How to enumerate all programs that can open XML file as plain text?

查看:213
本文介绍了如何枚举所有可以以纯文本形式打开XML文件的程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有时我想把它导入到Excel中 >使用 .xmlImportxml 方法,其他时候我只想在文本编辑器中打开它。



在一个框内设置一个复选框的2个选项按钮。该复选框确定是否要导入或仅查看XML文件。 2个选项是使用文本编辑器或使用 ShellExecute API使用系统默认值。我不太喜欢这个选项,因为它通常是Internet Explorer 。它看起来不错,但是您无法编辑文件。



我想要做的是枚举可用于查看平面文本文件的所有程序系统。我想将它们全部添加到框架内的组合框中。我以前只是用记事本使用shell进行硬编码来启动它,但是现在我正在使用 Notepad ++ ,而且我想选择使用它,而不需要任何硬编码。一些用户使用 TextPad ,某些使用 UltraEdit ,某些使用写字板等。我可以编写所有可以想到的内容,但是我我们已经通过注册表进行了检查,但是并没有什么一致的。我可以使用:

  HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\。 txt\OpenWithList 

找到列表,但我还没有找到一个很好的方式来获取路径从此。



如何获取 OpenWithList .txt 文件?



或者有更好的方法来找出哪些应用程序(文本编辑器)安装用于查看和编辑文本文件,因为XML文件也是

解决方案

确实很难找出哪些已安装的应用程序适合编辑XML文件,也就是文本编辑器。



自动评估 .txt OpenWithList Windows资源管理器管理 FileExts 列表是一个好主意。但是这个列表只包含无路径的可执行文件的名称。



具有完整路径的可执行文件可以从以下位置读取:

  HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App路径

在Windows x64上还有:

  HK $ _ $ 

这些注册表项包含已安装应用程序的列表。每个可执行文件都有一个密钥,位于 App Paths 之下。每个应用程序密钥的默认字符串是具有完整路径的可执行文件的文件名。通常也存在路径 string是可选的,因此并不总是存在。



定期安装的所有应用程序都列在 App Paths 除了记事本。但是,记事本始终存在于目录%windir%%SystemRoot%中。因此,通过获取环境变量 windir SystemRoot 的值,可以通过代码轻松确定完整的文件名称​​记事本



仅在 App Paths 下列出的仅有的应用程序是刚刚复制到硬盘或从档案文件中提取而不运行安装程序的应用程序。但是文本编辑器通常安装有一个安装程序,而不是通过将文本编辑器的所有程序文件复制或提取到目录中。



Microsoft\根据Microsoft文章共享 /en-us/library/windows/desktop/aa384253.aspxrel =nofollow noreferrer>受WOW64影响的注册表项。这意味着两个注册表路径具有相同的数据库。因此,在两个 App Paths 中的任何一个中进行的每个修改都将自动立即在其他路径上显示。并从 HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths 中读取可用于x86和x64应用程序。



但是x64版本的Windows Server 2008上的注册表项 Microsoft\Windows\CurrentVersion\App Paths 只是重定向 ,Windows Vista,Windows Server 2003和Windows XP。这意味着x86应用程序读取 HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths 读取实际 HKLM\Software\\ \\ Wow6432Node\Microsoft\Windows\CurrentVersion\App路径只包含x86应用程序,而x64应用程序读取真正 HKLM\Software\Microsoft\Windows\CurrentVersion \App路径包含x64应用程序。



因此,在x64 Windows上查找应用程序路径的策略是不容易选择的。我建议首先在 HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths 中搜索一个可执行文件。如果在 OpenWithList 中的可执行文件名称无法找到,则应在 HKLM\Software\Wow6432Node\Microsoft上进行第二次读取尝试\Windows\CurrentVersion\App路径。如果机器正在运行Windows x86,那么在查询/读取访问中,只能发现



Microsoft文章申请注册解释申请注册。由于可以读取,当用户没有管理员权限时,用户只能为当前用户安装应用程序。在这种情况下,应用程序注册在

  HKEY_CURRENT_USER\Software\Microsoft\Windows\\ \\ CurrentVersion\App路径

和Windows x64以前的Windows 7和Windows Server 2008 R2可能只有在

  HKEY_CURRENT_USER\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\App路径

还应从中搜索可执行文件的名称, OpenWithList



顺便说一句:Windows命令行解释器的命令开始也使用应用程序路径注册表项以查找要启动的应用程序,请参阅START在哪里搜索可执行文件?






我还建议一个复选框选项记住我的选择,使用户只能选择一次首选的查看器/编辑器应用程序的XML文件。如果一旦选定的应用程序仍然存在于记忆目录中,则应用程序应该在下一次打开该对话框时选择适当的应用程序。



另一个复选框选项可以是始终使用选定的应用程序,当选中此选项将导致在一次选定的应用程序中自动打开XML文件,而不显示对话框以选择一个应用程序来查看/编辑XML文件应用程序仍然存在于记忆目录中。


I'm working on some code that will import some XML in from an SQL database.

Sometimes I want to import it into Excel using the .xmlImportxml method and other times I just want to open it in a text editor.

I'm setting up 2 option buttons inside a frame with a check box. The check box determines if I want to import or just look on the XML file. The 2 options are to use a text editor or use the system default using ShellExecute API. I don't like that option much because it's usually Internet Explorer. It looks nice but you can't edit the file.

What I'd like to do is enumerate all of the programs that can be used to view flat text files on the system. I want to add all of them to a combo box inside the frame. I used to just have Notepad hard coded using shell to launch it, but now I'm using Notepad++ and I want to have the option to use it without hard coding anything. Some users use TextPad, some use UltraEdit, some use WordPad, etc. I could just code all of the ones I can think of but I'd much rather enumerate them dynamically.

I've checked through the registry but there isn't anything consistent there. I can use:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.txt\OpenWithList

to find the list, but I haven't found a good way to get the path from that.

How to get path of all executables found in OpenWithList for .txt files?

Or is there a better method to find out which applications (text editors) are installed for viewing and editing text files as XML files are, too?

解决方案

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.

这篇关于如何枚举所有可以以纯文本形式打开XML文件的程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆