C# Count registry keys existing using a partial value

Posted by cheeseman on Stack Overflow See other posts from Stack Overflow or by cheeseman
Published on 2012-04-04T15:24:09Z Indexed on 2012/04/04 17:28 UTC
Read the original article Hit count: 179

Filed under:
|
|
Microsoft.Win32.RegistryKey registryPath = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Testing");

Microsoft.Win32.RegistryKey entryKey = registryPath.OpenSubKey("Entry Point");

I have a lot of keys in Testing, in the format: "Entry Point 011", "Entry Point 123" - so Entry Point with random numbers after it.

Would I be able to search the registryPath variable above and get a count of the number of keys containing the "Entry Point" keyword? Assuming that there are also other keys existing without this keyword.

At the moment I have been using a for loop and looping for all possible combinations to get a count of all the keys, checking if the key exists or not, but as there are keys as high as "Entry Point 9000" having a for loop execute 9000 times is very inefficient.

 for (int i = 0; i <= highestEntryPointValue; i++)
 {
     Microsoft.Win32.RegistryKey entryKey = steamApps64.OpenSubKey("Entry Point " + Convert.ToString(i));

     if (entryKey != null)
     {
         count++;
     }
 }

© Stack Overflow or respective owner

Related posts about c#

Related posts about registry