【问题标题】:How to add application in "Open with..." section of system menu in Windows 7?如何在 Windows 7 系统菜单的“打开方式...”部分添加应用程序?
【发布时间】:2013-06-11 19:50:50
【问题描述】:

真正的问题和疑问是: 如何在 Windows 7 的注册表配置单元“HKEY_CLASSES_ROOT”中添加键?

我知道在哪里创建密钥,但只有当我以管理员身份运行程序时才能实现。或手动... :) 否则,会出现错误消息,提示无法添加/创建密钥。

没有管理员权限可以吗?

该键的位置: "HKEY_CLASSES_ROOT\Applications\MyAppName.exe\shell\open\comand"

我用来在注册表中编写的代码:

procedure TForm1.Button1Click(Sender: TObject);
var 
   Reg: TRegistry;
   appfilename: string;
begin
appfilename:= application.ExeName;
reg := TRegistry.Create;
reg.RootKey := HKEY_CLASSES_ROOT;
if not reg.KeyExists('Applications\MyAppName.exe\shell\open\command') then
begin
 if reg.OpenKey('Applications\MyAppName.exe\shell\open\command', True) then
 begin
  reg.WriteString('', '"' + appfilename + '" "%1"');
  reg.CloseKey;
 end;
end;

结束;

【问题讨论】:

  • 您有严重的内存泄漏。您必须释放 TRegistry 对象。使用try..finally
  • 只是一个想法:这不是您的设置实用程序的工作吗?无论如何,它都以提升的权限运行?
  • 好的,TRY 和 FINALLLY 必须在代码中,但添加它并没有帮助。我相信这在 XP 或更高版本的 Win OS 中是可能的。
  • 我可以更改权限,但这不是解决方案,因为这仅适用于我的电脑...
  • 您也可以使用清单。但是为什么不在设置过程中这样做呢?

标签: delphi registry key


【解决方案1】:

您需要在HKEY_CURRENT_USER\Software\Classes 中输入密钥。这将被 Windows 复制到HKEY_CLASSES_ROOT

【讨论】:

  • 它不会被复制到任何地方。 HKCR 是一个合并视图。是虚拟的。禁止复制。
【解决方案2】:

我相信这对某人有用。这是在 Windows 7 系统菜单的“打开方式...”部分添加您的应用程序的方法(我没有在其他操作系统上检查这一点)。 感谢@John Clement,这是答案:

procedure TForm1.AddAppInOpenWith;
var Reg: TRegistry;
         appfilename: string;
begin
  appfilename:= application.ExeName;
  reg := TRegistry.Create;
  reg.RootKey := HKEY_CURRENT_USER;
  try
  if not reg.KeyExists('Software\Classes\Applications\AppName.exe\shell\open\command') then
  begin
    if reg.OpenKey('Software\Classes\Applications\AppName.exe\shell\open\command', True) then
    begin
      reg.WriteString('', '"' + appfilename + '" "%1"');
      reg.CloseKey;
    end;
  end;
  finally Reg.Free;
  end;
end;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-06
    • 1970-01-01
    • 1970-01-01
    • 2016-02-04
    • 2013-08-27
    • 2017-08-03
    • 1970-01-01
    • 2012-11-03
    相关资源
    最近更新 更多