var
MainForm: TMainForm;
const
SRootKey = HKEY_LOCAL_MACHINE;
SKey = 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles';
implementation
{$R *.dfm}
{ TMainForm }
procedure TMainForm.GetKeys(OutList: TStrings);
var
Reg: TRegistry;
begin
OutList.BeginUpdate;
try
OutList.Clear;
Reg := TRegistry.Create(KEY_READ);
try
Reg.RootKey := SRootKey;
if (Reg.OpenKeyReadOnly(SKey)) and (Reg.HasSubKeys) then
begin
Reg.GetKeyNames(OutList);
Reg.CloseKey;
end;
finally
Reg.Free;
end;
finally
OutList.EndUpdate;
end;
end;
procedure TMainForm.btnScanClick(Sender: TObject);
begin
GetKeys(ListBox1.Items);
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
GetKeys(ListBox1.Items);
end;
这似乎没有做任何事情.
我可以验证注册表路径(Windows 8.1),我甚至更改了SKey进行测试而没有任何问题,但是像这样的某些键没有返回任何内容.
我甚至尝试以管理员身份从Windows运行该程序,但仍然没有.
还有什么我需要改变的吗?什么会使某些键可读而其他键不可读?
您的进程是32位,并且您在64位计算机上运行它.因此,您需要遵守 registry redirection.The registry redirector isolates 32-bit and 64-bit applications by providing separate logical views of certain portions of the registry on WOW64. The registry redirector intercepts 32-bit and 64-bit registry calls to their respective logical registry views and maps them to the corresponding physical registry location. The redirection process is transparent to the application. Therefore, a 32-bit application can access registry data as if it were running on 32-bit Windows even if the data is stored in a different location on 64-bit Windows.
你正在关注的关键
HKLM\SOFTWARE
被重定向.在您的32位进程中,尝试打开此密钥将重定向到注册表的32位视图,该视图作为实现细节存储在
HKLM\SOFTWARE\Wow6432Node
你在这里要做的是访问注册表的64位视图.为此,您需要access an alternate registry view.这意味着在打开任何键时传递KEY_WOW64_64KEY键.
在Delphi中,您可以通过在Access标志中包含KEY_WOW64_64KEY,或者将它包含在传递给构造函数的标志中来实现.
Reg := TRegistry.Create(KEY_READ or KEY_WOW64_64KEY);
最重要的是,对于此特定密钥,由于此密钥的注册表安全性配置,您需要使用管理员权限运行才能打开密钥.即使你只打算阅读它.
