Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Wildcard in registry key

Posted on 2004-08-29
2
Medium Priority
?
1,569 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 1000 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

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

916 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