Solved

Wildcard in registry key

Posted on 2004-08-29
2
1,556 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 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

728 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