Solved

Wildcard in registry key

Posted on 2004-08-29
2
1,547 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now