存在一些CLSID注册表项,但无法读取 [英] Some CLSID Registry keys exist but cannot be read

查看:72
本文介绍了存在一些CLSID注册表项,但无法读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的程序,该程序读取所有CLSID注册表项并在列表框中显示其名称;它是用Delphi编写的,但问题并非特定于Delphi.而是有关Windows注册表的问题.

I have following program that reads all CLSID registry keys and displays their name on a listbox; it is written in Delp but the question is not specific to Delphi; it is rather a question about the Windows Registry.

procedure TForm2.Button1Click(Sender: TObject);
var
  guid: string;
  reg: TRegistry;
  sl: TStringList;
  i: Integer;
  name: string;
begin
  memo1.Clear;

  reg := TRegistry.Create;
  sl := TStringList.Create;
  memo1.Lines.BeginUpdate;
  try
    reg.RootKey := HKEY_CLASSES_ROOT;
    if reg.OpenKeyReadOnly('\CLSID\') then
    begin
      reg.GetKeyNames(sl);
      reg.CloseKey;

      for i := 1 to sl.Count-1 do
      begin
    guid := sl.Strings[i];

    if reg.OpenKeyReadOnly('\CLSID\'+guid) then
    begin
      try
        name := reg.ReadString('');
      except
        name := '!!! <ERROR1> !!!';
      end;
      reg.CloseKey;
    end;

    memo1.Lines.Add(guid + ' ' + name);
      end;
    end;
  finally
    sl.Free;
    reg.Free;
    memo1.Lines.EndUpdate;
  end;
end;

问题在于以下注册表项确实存在(它们在GetKeyNames中列出),但是无法读取(读取默认值).我收到异常"的数据类型无效".

The problem is that following registry keys do exist (they are listed in GetKeyNames), but they cannot be read (reading the default value). I get the Exception "Invalid data type for ''".

失败的关键是:

{33297C9D-2A25-1679-1475-A1CE3901C86D} !!! <ERROR1> !!!
{45049248-47E9-7CEE-A822-1E555F74D237} !!! <ERROR1> !!!
{69C5BE90-E717-97A6-CCEF-C44D93111A5A} !!! <ERROR1> !!!
{8663D540-C578-44AE-9D24-4A9D9A4881C3} !!! <ERROR1> !!!
{9A73B3FA-50DF-3410-930D-51C35FC9237E} !!! <ERROR1> !!!
{EACF7497-3D67-8044-DE95-81429597BB8F} !!! <ERROR1> !!!

即使我在NT-AUTHORITY \ SYSTEM上下文中运行RegEdit(实际上显示了所有内容),这些键也不会出现在 regedit.exe 中.

These keys do not appear in regedit.exe, even if I run RegEdit in the NT-AUTHORITY\SYSTEM context (which shows really everything).

您是否遇到相同的问题,或者我的注册表因某种原因被损坏了?

Do you have the same problem, or is my registry somehow damaged?

推荐答案

显而易见的解释是这些键存在,但是您在错误的位置寻找它们.我敢打赌,您在64位计算机上具有32位进程,并且键由注册表重定向器.

The obvious explanation is that the keys exist but you look for them in the wrong place. I bet you have a 32 bit process on a 64 bit machine and the keys are redirected by the registry redirector.

在regedit下的32位CLSID部分中查找

Look for the 32 bit CLSID section in regedit under

HKCR\Wow6432Node\CLSID

可以在受WOW64影响的注册表项中找到更多有用的信息.在MSDN上.

然后,在找到密钥后,默认值似乎不具有您期望的数据类型.您期望使用字符串,但是某些键显然具有不同的类型.您需要在程序中添加一些弹性以应对这种情况.

Then when you've located the key, it would seem that the default value does not have the data type that you expect. You are expecting a string, but some keys clearly have a different type. You'll need to add some resiliency to your program to deal with that.

在我的机器上,确实没有第一个CLSID,它是在64位注册表 HKCR \ CLSID 下找到的.但是在 HKCR \ Wow6432Node \ CLSID \ {33297C9D-2A25-1679-1475-A1CE3901C86D} 下存在.并且默认值的类型为 REG_BINARY .

Taking your first CLSID, on my machine indeed it is not to be found under HKCR\CLSID, the 64 bit registry. But under HKCR\Wow6432Node\CLSID\{33297C9D-2A25-1679-1475-A1CE3901C86D} is present. And the default value has type REG_BINARY.

总而言之,这是我的结论:

So, to summarise, here are my conclusions:

  • 您的注册表很好.
  • 您的程序从32位视图读取,但是您一直在regedit中的64位视图中查找.
  • 并非所有CLSID密钥的默认值都使用 REG_SZ .

如果您决定要从与程序的位数不匹配的其他注册表视图中读取,请使用 KEY_WOW64_64KEY KEY_WOW64_32KEY 标志指定视图.如访问备用注册表视图中所述.在您的情况下,您可以使用 KEY_WOW64_64KEY 从64位视图中读取.

Should you decide that you want to read from a different registry view than that matched to your program's bitness, use the KEY_WOW64_64KEY or KEY_WOW64_32KEY flags to specify the view. As detailed in Accessing an Alternate Registry View. In your case you might use KEY_WOW64_64KEY to read from the 64 bit view.

顺便说一句,您的 for 循环应从 0 开始,而不是从 1 开始.

As an aside, your for loop should start from 0 rather than 1.

这篇关于存在一些CLSID注册表项,但无法读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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