如何正确添加文件关联到Windows注册表?

Jak*_*les 5 registry windows-installer file-association

我应该在Windows注册表中添加哪些数据以及正确创建文件关联?

我问这个问题主要是因为我多年前写过的一些旧应用程序,它们使用Visual Studio .NET的Windows Installer打包程序来创建文件关联.我安装的扩展名是.whr.encxml.

现在,在安装这些应用程序的计算机上,有时会出现一个奇怪的问题- 当在Google Chrome或Internet Explorer(特别是exe,msi或zip文件)中下载文件时,浏览器会将文件扩展名更改为1我的安装程序安装的扩展程序.我不知道它是否会影响其他浏览器 - 这两个浏览器有什么共同之处吗?所以...如果你下载,例如http://example.com/downloads/application.exe,该文件将被下载为http://example.com.downloads/application.encxml(或.whr,无论哪个因为没有任何明显的理由,他们当下选择了一个.

我要指出的是,按键的HKCR\.whrHCKR\.encxml密钥引用(帐户管理器加密的XML文件和工作时间记录)中包含空格,当我在Visual Studio中创建关联时,我没有添加".".到前面.也许不允许使用空格,和/或你应该用"."作为前缀?注册表代码似乎没问题,但我注意到通过我的注册表查看每个其他应用程序不使用关联类中的空间,也不会在我知道的任何机器上安装的任何应用程序的任何其他文件扩展名中发生此问题 - 仅由我的应用程序的VS安装程序创建的.我已经粘贴了相应的注册表项和与文件扩展名相关的值的注册表转储 - 因为MSI是专有的我不知道这是否全部,但从我从其他应用程序知道这应该是一切.一世' 多年来一直对这个问题感到疑惑,但却永远无法理解.我很快用新产品替换其中一个旧应用程序,所以这次我想确保没有像这样的奇怪错误......

这是数据(注意我已经指出了一些二进制字符串的文本值,其中//注释低于该值):

[HKEY_CLASSES_ROOT\.encxml]
"Content Type"="application/octet-stream"
@="Account Manager Encrypted XML File"

[HKEY_CLASSES_ROOT\.encxml\Account Manager Encrypted XML File]

[HKEY_CLASSES_ROOT\.encxml\Account Manager Encrypted XML File\ShellNew]
Run Code Online (Sandbox Code Playgroud)
[HKEY_CLASSES_ROOT\Account Manager Encrypted XML File]
@="Account Manager Encrypted XML File"

[HKEY_CLASSES_ROOT\Account Manager Encrypted XML File\DefaultIcon]
@=hex(2):25,00,41,00,50,00,50,00,44,00,41,00,54,00,41,00,25,00,5c,00,4d,00,69,\
  00,63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,5c,00,49,00,6e,00,73,00,74,00,\
  61,00,6c,00,6c,00,65,00,72,00,5c,00,7b,00,42,00,36,00,34,00,31,00,37,00,36,\
  00,30,00,42,00,2d,00,37,00,44,00,42,00,37,00,2d,00,34,00,46,00,31,00,42,00,\
  2d,00,41,00,44,00,36,00,45,00,2d,00,30,00,41,00,33,00,34,00,32,00,30,00,46,\
  00,35,00,45,00,45,00,30,00,44,00,7d,00,5c,00,5f,00,36,00,46,00,45,00,46,00,\
  46,00,39,00,42,00,36,00,38,00,32,00,31,00,38,00,34,00,31,00,37,00,46,00,39,\
  00,38,00,46,00,35,00,34,00,39,00,2e,00,65,00,78,00,65,00,2c,00,30,00,00,00

// Product code GUID is: {F7F214E9-ED37-4AE1-B0D2-93427973E60A}, which is different from below but I probably changed it at some point for some reason
// %APPDATA%\Microsoft\Installer\{B641760B-7DB7-4F1B-AD6E-0A3420F5EE0D}\_6FEFF9B68218417F98F549.exe,0

[HKEY_CLASSES_ROOT\Account Manager Encrypted XML File\shell]
@="open"

[HKEY_CLASSES_ROOT\Account Manager Encrypted XML File\shell\open]
@="&Open"

[HKEY_CLASSES_ROOT\Account Manager Encrypted XML File\shell\open\command]
@="\"C:\\Program Files\\Petroules Enterprises\\Account Manager\\AccountManager.exe\" \"%1\""
"command"=hex(7):4c,00,29,00,25,00,59,00,63,00,73,00,67,00,2d,00,4c,00,41,00,\
  28,00,30,00,64,00,66,00,34,00,36,00,75,00,5f,00,50,00,27,00,3e,00,27,00,7d,\
  00,27,00,66,00,25,00,6f,00,59,00,64,00,4b,00,69,00,48,00,74,00,7a,00,35,00,\
  21,00,55,00,2b,00,6c,00,68,00,54,00,20,00,22,00,25,00,31,00,22,00,00,00,00,\
  00

// This is a bizarre-looking value... what's up with that?
// L)%Ycsg-LA(0df46u_P'>'}'f%oYdKiHtz5!U+lhT "%1"
Run Code Online (Sandbox Code Playgroud)
[HKEY_CLASSES_ROOT\.whr]
"Content Type"="application/octet-stream"
@="Work Hours Record"

[HKEY_CLASSES_ROOT\.whr\Work Hours Record]

[HKEY_CLASSES_ROOT\.whr\Work Hours Record\ShellNew]
Run Code Online (Sandbox Code Playgroud)
[HKEY_CLASSES_ROOT\Work Hours Record]
@="Work Hours Record"

[HKEY_CLASSES_ROOT\Work Hours Record\DefaultIcon]
@=hex(2):25,00,41,00,50,00,50,00,44,00,41,00,54,00,41,00,25,00,5c,00,4d,00,69,\
  00,63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,5c,00,49,00,6e,00,73,00,74,00,\
  61,00,6c,00,6c,00,65,00,72,00,5c,00,7b,00,46,00,41,00,32,00,33,00,44,00,37,\
  00,36,00,34,00,2d,00,46,00,36,00,34,00,39,00,2d,00,34,00,38,00,46,00,39,00,\
  2d,00,38,00,44,00,30,00,42,00,2d,00,45,00,31,00,38,00,38,00,35,00,41,00,39,\
  00,38,00,31,00,46,00,39,00,39,00,7d,00,5c,00,5f,00,36,00,46,00,45,00,46,00,\
  46,00,39,00,42,00,36,00,38,00,32,00,31,00,38,00,34,00,31,00,37,00,46,00,39,\
  00,38,00,46,00,35,00,34,00,39,00,2e,00,65,00,78,00,65,00,2c,00,30,00,00,00

// Product code GUID: {FA23D764-F649-48F9-8D0B-E1885A981F99}, same as below
// %APPDATA%\Microsoft\Installer\{FA23D764-F649-48F9-8D0B-E1885A981F99}\_6FEFF9B68218417F98F549.exe,0

[HKEY_CLASSES_ROOT\Work Hours Record\shell]

[HKEY_CLASSES_ROOT\Work Hours Record\shell\open]
@="&Open"

[HKEY_CLASSES_ROOT\Work Hours Record\shell\open\command]
@="\"C:\\Program Files\\Petroules Enterprises\\Work Hours Calculator\\WorkHoursCalculator.exe\" \"%1\""
"command"=hex(7):28,00,5d,00,56,00,49,00,79,00,55,00,7b,00,5e,00,4e,00,3f,00,\
  26,00,68,00,48,00,7e,00,53,00,24,00,6e,00,31,00,36,00,59,00,3e,00,33,00,75,\
  00,5f,00,7d,00,47,00,26,00,70,00,79,00,75,00,78,00,38,00,4e,00,72,00,43,00,\
  6e,00,67,00,27,00,44,00,67,00,42,00,20,00,22,00,25,00,31,00,22,00,00,00,00,\
  00

// Same bizarre-looking type of value as before, but different...
// (]VIyU{^N?&hH~S$n16Y>3u_}G&pyux8NrCng'DgB "%1"
Run Code Online (Sandbox Code Playgroud)

Chr*_*ter 2

在 Windows Installer 中,我们使用 RegisterExtensionInfo 标准操作:

http://msdn.microsoft.com/en-us/library/aa371156(v=VS.85).aspx

其中主要使用 Extension 和 Verb 表以及一些与 COM 相关表的联接:

http://msdn.microsoft.com/en-us/library/aa368571 (v=VS.85).aspx(扩展表) http://msdn.microsoft.com/en-us/library/aa372487(v= VS.85).aspx(动词表)