Solved

Wildcard in registry key

Posted on 2004-08-29
2
1,553 Views
Last Modified: 2012-06-27
I'm making a program which turns on/off system sound acceleration.

I have this as a string:

\SYSTEM\ControlSet001\Hardware Profiles\0001\System\CurrentControlSet\Enum\PCI\VEN_1102&DEV_0002&SUBSYS_80671102&REV_0A\4&3b1d9ab8&0&5040\DirectSound\Device Presence

VEN_1102&DEV_0002&SUBSYS_80671102&REV_0A\4&3b1d9ab8&0&5040 is dependant on the computer. It can change. Is there any way to put a wildacard into this?

I need \SYSTEM\ControlSet001\Hardware Profiles\0001\System\CurrentControlSet\Enum\PCI\*\*\DirectSound\Device Presence

Except that doesnt' work.

Here is my code:

var key: string;
begin

Key := '\SYSTEM\ControlSet001\Hardware Profiles\0001\System\CurrentControlSet\Enum\PCI\VEN_1102&DEV_0002&SUBSYS_80671102&REV_0A\4&3b1d9ab8&0&5040\DirectSound\Device Presence';
reg := TRegistry.Create;
Reg.RootKey := HKEY_LOCAL_MACHINE;
Reg.OpenKey(Key, false);
Reg.WriteInteger('WDM',1);
Reg.WriteInteger('VxD',1);
Reg.CloseKey;
Reg.Free;

end;

Is there any way I can use wildcards in that string? Thanks.

0
Comment
Question by:TheJkWhoSaysNi
2 Comments
 
LVL 2

Accepted Solution

by:
gary_williams earned 250 total points
ID: 11927974
Perhaps this will be of help.  It's a generic registry-searching function I just wrote, that takes a RootPath and calls itself recursively until it finds DesiredKey.

uses
  Registry;

function FindNestedRegistryKey(const RootKey: HKEY;
                               const RootPath: String;
                               const DesiredKey: String): String;
var
  Reg: TRegistry;
  Subkeys: TStrings;
  I: Integer;
begin
  Result := '';

  Reg := TRegistry.Create;
  Subkeys := TStringList.Create;
  try
    Reg.RootKey := RootKey;
    if (Reg.OpenKey(RootPath, False)) then
      begin
      Reg.GetKeyNames(Subkeys);

      if (Subkeys.IndexOf(DesiredKey) <> -1) then
        Result := RootPath + '\' + DesiredKey
      else
        for I := 0 to (Subkeys.Count - 1) do
          begin
          Result := FindNestedRegistryKey(RootKey, RootPath + '\' + Subkeys[I], DesiredKey);

          if (Result <> '') then
            Break;
          end;
      end;
  finally
    Subkeys.Free;
    Reg.Free;
  end;
end;


// Example use follows

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(FindNestedRegistryKey(HKEY_LOCAL_MACHINE, '\SYSTEM\ControlSet001\Hardware Profiles\0001\System\CurrentControlSet\Enum\PCI', 'DirectSound') + '\Device Presence');
end;
0
 

Author Comment

by:TheJkWhoSaysNi
ID: 11931816
That does exactly what I need. Thanks :)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question