I am really get stucked with something. I have a string which includes hex values:
string creatorSid = @"01,05,00,00,00,00,00,05,15,00,00,00,10,b1,9d,4a,7a,85,7b,05, 79,05,b3,7c,ee,03,00,00";
I want to put that into the registrykey which requires binary values.
I tried this:
key.SetValue("creatorSID", creatorSid , RegistryValueKind.Binary);
But I got error message that it can not be converted.
Here is the complete Code so far:
class Program
{
static void Main(string[] args)
{
String printerName = "Naked";
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\Print\Printers\" + printerName , true);
string security = "01,00,0c,80,d0,00,00,00,dc,00,00,00,00,00,00,00,14,00,00,00,02," +
"00,bc,00,07,00,00,00,00,00,24,00,0c,00,0f,00,01,05,00,00,00,00,00,05,15,00," +
"00,00,10,b1,9d,4a,7a,85,7b,05,79,05,b3,7c,ee,03,00,00,00,09,24,00,30,00,0f," +
"00,01,05,00,00,00,00,00,05,15,00,00,00,10,b1,9d,4a,7a,85,7b,05,79,05,b3,7c," +
"ee,03,00,00,00,09,14,00,00,00,00,10,01,01,00,00,00,00,00,03,00,00,00,00,00," +
"00,14,00,08,00,02,00,01,01,00,00,00,00,00,01,00,00,00,00,00,0a,14,00,00,00," +
"00,20,01,01,00,00,00,00,00,01,00,00,00,00,00,00,18,00,0c,00,0f,00,01,02,00," +
"00,00,00,00,05,20,00,00,00,20,02,00,00,00,0b,18,00,00,00,00,10,01,02,00,00," +
"00,00,00,05,20,00,00,00,20,02,00,00,01,01,00,00,00,00,00,05,12,00,00,00,01," +
"01,00,00,00,00,00,05,12,00,00,00";
var data = Encoding.Unicode.GetBytes(security);
try
{
key.SetValue("Security", data, RegistryValueKind.Binary);
}
catch (Exception exc)
{
Console.WriteLine(exc.Message);
Console.WriteLine(exc.StackTrace);
}
}
}
It`s writing the entry now, but the values are changed. If i check the key there is: "30 00 31 00 ....." in it. But it must be: "01 00 0c 80....." (must be exactly the value from the string)