concatanate is not working in C3

josesalaz 21 Reputation points
2023-04-14T14:58:40.2333333+00:00

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:

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 debug1

debug2

debug3

any idea, please? regards, Jose

Windows for business | Windows Server | User experience | Other
Developer technologies | C#
{count} votes

1 answer

Sort by: Most helpful
  1. josesalaz 21 Reputation points
    2023-04-14T15:19:06.8233333+00:00

    I got a mistake. The right way is + "{" + subKey + "}"

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.