问题描述
我的客户正在某些工作站中用 OpenOffice 替换 MS Office.我的程序使用 .xml 扩展名(使用开放格式)将文件导出到 Excel 并使用当前关联的程序(使用 ShellExecute)打开它
My customer is replacing MS Office with OpenOffice in some workstations. My program export a file to Excel using the .xml extension (using open format) and opens it using the current associated program (using ShellExecute)
问题在于 OpenOffice 没有注册与之关联的 .xml 扩展名.
The problem is that OpenOffice does not register the .xml extension associated with it.
手动关联工作正常,但我想制作一个 .reg 或其他东西来轻松更改设置.
Manually association works fine, but I want to make a .reg or something to easily change the setting.
我正在 PC 中查看已进行更改的注册表,但是
I'm looking in the registry in a PC with the change already made, but the
"HKEY_CLASSES_ROOT.xml"
key 没有任何引用 OpenOffice.
key does not have anything referencing OpenOffice.
关联存储在哪里?我如何制作脚本来完成这项工作?
Where is the association stored? How can I make a script to do the work?
推荐答案
真正的关联存储在"HKEY_CLASSES_ROOT.xml"
指向的key中.
The real association is stored in the key that "HKEY_CLASSES_ROOT.xml"
points to.
在我的机器上,该键的默认值是 "xmlfile"
,很可能与您的相同.
On my machine, the default value of that key says "xmlfile"
, most likely that is the same for yours.
那么让我们转到"HKEY_CLASSES_ROOTxmlfile"
.在那里您可以看到(并更改)将使用什么命令来启动该类型的文件:
So let's go to "HKEY_CLASSES_ROOTxmlfile"
. There you can see (and change) what command is going to be used to launch that type of file:
HKEY_CLASSES_ROOTxmlfileshellopencommand
Windows 使用这种重定向将多个文件扩展名映射到同一文件类型,从而映射到同一应用程序.
Windows uses this kind of redirection to map multiple file extensions to the same file type, and thus to the same application.
在 "HKEY_CLASSES_ROOTxmlfileshell"
下有多个子键,类似于您可以对文件执行的操作的动词".同样,如果您双击文件,"shell"
键的默认值决定了使用这些动词中的哪一个.就我而言,这是 "open"
.
Under "HKEY_CLASSES_ROOTxmlfileshell"
there are multiple sub-keys that resemble the "verbs" of what you can do to the file. Again, the default value of the "shell"
key decides which of these verbs is used if you double click the file. In my case this is "open"
.
结论:
有了这些知识,使关联可脚本化的最简单方法是使用 regedit 导出包含该更改的 .reg 文件,然后双击或将其应用到目标计算机:
With that knowledge, the easiest way to make an association scriptable is to use regedit to export a .reg file containing that change, and apply it to the target computer with a double click or:
regedit /s new_xml_association.reg
或(如果您使用 XP 或更高版本并且知道自己在做什么)用以下内容覆盖当前值:
or (if you are on XP or higher and know what you do) overwrite the current value with:
reg add "HKEY_CLASSES_ROOTxmlfileshellopencommand" /ve /d "path oprogram %1"
无论如何,建议更深入地了解 reg add/?
命令.第一种方案更安全.
At any rate, a deeper look into reg add/?
command is advised. The first solution is safer.
这篇关于将扩展关联到程序的脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!