【发布时间】: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 中是可能的。
-
我可以更改权限,但这不是解决方案,因为这仅适用于我的电脑...
-
您也可以使用清单。但是为什么不在设置过程中这样做呢?