I'm a BATCH fan and I am trying to implement my key using C# winForms instead of batch.
I made a simple batch Script:
@echo off
reg add "HKEY_CURRENT_USER\Software\TestProgram\Kool" /f /v "Setting" /t REG_BINARY /d h4h999d27e93f3666188231a018c9d44406136wb 1>nul 2>&1
Which updates my reg key no worries whatsoever. However I want to try and implement the same result with C# WinForms and I believe I have the correct formula but the result is not correct.
I tried the following(after checking if the reg_binary exists first and deleting it first):
private void button1_Click(object sender, EventArgs e)
{
if (Registry.GetValue(@"HKEY_CURRENT_USER\Software\TestProgram\Kool", "Setting", null) == null)
{
RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\TestProgram\Kool");
try
{
var data = Encoding.Unicode.GetBytes("h4h999d27e93f3666188231a018c9d44406136wb");
//Storing the values
key.SetValue("Setting", data, RegistryValueKind.Binary);
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
MessageBox.Show(exc.StackTrace);
}
key.Close();
MessageBox.Show("binary key created");
}
else
{
MessageBox.Show("error");
}
}
Which makes the key no worries but its not the same format or result as what I get when i do it through batch, can anyone explain to me why? I am after the same result as when I do it with my batch file.
I feel like I am missing something simple maybe its incorrect bytes I just can't seem to work it out.
I have read these for help: Write a Stringformated Hex Block to registry in Binary value How to retrieve a REG_BINARY value from registry and convert to string How can I read binary data from registry to byte array Read Registry_binary and convert to string
But still no success.