Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Wildcard in registry key

Posted on 2004-08-29
2
Medium Priority
?
1,563 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

721 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