Delphi写到HKEY LOCAL MACHINE [英] Delphi Writing to HKEY LOCAL MACHINE

查看:65
本文介绍了Delphi写到HKEY LOCAL MACHINE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个编写的备份应用程序,我需要它在启动时始终为所有用户运行.我要使用

I have a back up application that I wrote and I need it to run on start up, always for all users. I want to use

key := '\Software\Microsoft\Windows\CurrentVersion\Run';
Reg := TRegIniFile.Create;
try
  Reg.RootKey:=HKEY_LOCAL_MACHINE;
  Reg.CreateKey(Key);
  if Reg.OpenKey(Key,False) then Reg.WriteString(key, 'Backup', 'c:\backup.exe');
finally
  Reg.Free;
end;

我已经编写了清单,并将其添加为资源,它每次运行时都要求管理员特权.但是,它没有添加reg值,我不确定为什么.

I have written a manifest and added it as a resource, It asks for admin privileges every time it runs. However, it is not adding the the reg value and I am not sure why.

推荐答案

您的代码以32位进程运行.因此,它受注册表重定向器的约束.该技术可为注册表的某些部分维护单独的32位和64位视图.

Your code runs in a 32 bit process. And as such it is subject to the registry redirector. That is the technology that maintains separate 32 and 64 bit views of certain portions the registry.

这种实现方式是将 HKLM \ Software 的32位视图存储在 HKLM \ Software \ Wow6432Node 下.这就是您的注册表写入被重定向到的地方.

The way this is implemented is that the 32 bit view of HKLM\Software is stored under HKLM\Software\Wow6432Node. And that's where your registry writes are being re-directed to.

现在,您可以选择使用 KEY_WOW64_64KEY 标志写入注册表的64位视图.但是,没有必要这样做.您可以简单地写入注册表的32位视图.当用户登录Windows时,将从注册表的32位和64位视图中处理 Software \ Microsoft \ Windows \ CurrentVersion \ Run 启动应用程序.

Now you could choose to write to the 64 bit view of the registry by using the KEY_WOW64_64KEY flag. However, there's no need to do that. You can simply write to the 32 bit view of the registry. When a user logs on Windows processes the Software\Microsoft\Windows\CurrentVersion\Run startup apps from both 32 and 64 bit views of the registry.

许多程序都可以这样做.看着我的机器,我可以在 SOFTWARE \ Wow6432Node \ Microsoft \ Windows \ CurrentVersion \ Run 下看到以下条目:

Many programs do this. Looking at my machine I can see the following entries under SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run:

  • Apple Push
  • iTunesHelper
  • QuickTime任务
  • DivXUpdate
  • SunJavaUpdate

换句话说,问题中的代码已经可以使用了.

In other words, the code in the question already works.

这篇关于Delphi写到HKEY LOCAL MACHINE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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