I tried many many ways to Convert a value to String so part of my tool set I made a form that will tell you your HWID HardWare ID. I found the registry with the value in it.
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\IDConfigDB\Hardware Profiles\0001"\HwProfileGuid"
-> This gives long test string
I want to Discord that on a label I tried all ways i know But none work My latest one I tried is
Microsoft.Win32.RegistryKey key3;
key3 = "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\IDConfigDB\Hardware Profiles\0001\HwProfileGuid2";
So this is my code:
string regg = (string)key3.GetValue("");
label2.Text = regg;
I got that code form here
but it gives an error saying :
Cannot implicitly convert type 'string' to 'Microsoft.Win32.RegistryKey'
I looked all over google what now, but they are always talking about something else. No matter how I tried it gave some error. I just want to display the HWID Value on button click to a label.
I'm using C# Visual Studio 2017.
I even tried
try
{
label2.Text = Registry.LocalMachine.OpenSubKey("SYSTEM\\ControlSet001\\Control\\IDConfigDB\\Hardware Profiles\\0001\\", true).GetValue("HwProfileGuid");
}
catch(Exception ex)
{
}
says now: Cannot implicitly convert type 'object' to 'string'. An explicit conversion exists (are you missing a cast?)
Cannot implicitly convert type 'string' to 'Microsoft.Win32.RegistryKey'
Is caused because your key3 variable is declared as a RegistryKey, and you're trying to put a string into it, rather than assigning it to the result of the OpenSubKey method. Put that string in parentheses, remove the HKEY_LOCAL_MACHINE\ and put "Registry.LocalMachine.OpenSubKey" before the opening parenthesis.
That key3 will be disposable, so put it in a 'using' block.
I don't have access to a Windows registry from here, but if HwProfileGuid is the name of the key, then your GetEntry("") is the way to read the 'default value', which would be correct. However, if HwProfileGuid is the name of the value, then remove that and the trailing backslash, and put HwProfileGuid inside the quotes of GetEntry.
The next point is that the type of the value may not be a string. (Again... I don't have registry so can't check) If you store the result of GetValue in an object (rather than a string) then you can step through with the debugger and it will show you what the type is.
Here's a good example of reading a registry key... https://stackoverflow.com/a/18234755/5198140