Resolved concatenated in C#

josesalaz

New member
Joined
Apr 14, 2023
Messages
4
Programming Experience
Beginner
Hello guys, I have a code where I get the registry subKey and I have assigned the value to a variable named subKey (this value came from wmic process and the final data came without {}) but I need to add {} and the beginning and end of this value in order to get the information that I need. The problem is that when I print the value to validate that I have gotten the right information, the debug shows me that the variable is null. I think the issue is the concatenation. Please, follow the code here below:

keyValue:
SystemInfo systemInfo = new SystemInfo();
            wmic Wmic = new wmic();
            Wmic.IdentifyingNumber = GetSipeliaInfo("output4");

            //I have to us eregex because I need to remove those characters
             // (\r\r\n\r\r\n) from  "C3BCB0F2-5303-489D-AFAB-218B416D000D  \r\r\n\r\r\n"
            string input = Regex.Replace(Wmic.IdentifyingNumber, @"\s+", "");
            Console.WriteLine(input);
            
            string subKey = input;
            
        
            RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" + "\\{" + subKey + "\\}");
            Console.WriteLine(key);


the right line should be something like that RegistryKey key2 = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{C3BCB0F2-5303-489D-AFAB-218B416D000D}"); please, follow the information from the debug attached here. in the debug3 you will see that the variable key is null

any idea, please?
regards,
Jose
 

Attachments

  • debug1.png
    debug1.png
    77.9 KB · Views: 9
  • debug2.png
    debug2.png
    69.6 KB · Views: 10
  • debug3.png
    debug3.png
    69.3 KB · Views: 9
I suggest something like this so that the debugger can help you when needed:
C#:
var keyPath = @$"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{{{productCode}}}";
using (var key = Registry.LocalMachine.OpenSubKey(keyPath))
{
}
You will be able to inspect productCode, keyPath, and key if ever you have an issue with the code.
 
Back
Top Bottom