Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class reg
- {
- public void write(string key, string valueName, string value)
- {
- Byte[] byteValue = System.Text.Encoding.UTF8.GetBytes(value);
- Registry.SetValue(key, valueName, value, RegistryValueKind.Binary);
- }
- }
- string key = @"HKEY_CLASSES_ROOT.sgdk2";
- string valueName = string.Empty; // "(Default)" value
- string value = "sgdk2file";
- Microsoft.Win32.Registry.SetValue(key,valueName, value,
- Microsoft.Win32.RegistryValueKind.String);
- static byte[] HexToBin(string hex)
- {
- var result = new byte[hex.Length/2];
- for (int i = 0; i < hex.Length; i += 2)
- {
- result[i / 2] = byte.Parse(hex.Substring(i, 2), System.Globalization.NumberStyles.HexNumber);
- }
- return result;
- }
- static string BytesToHex(byte[] bytes)
- {
- System.Text.StringBuilder sb = new StringBuilder();
- for (int i = 0; i < bytes.Length; i++)
- {
- sb.Append(bytes[i].ToString("x2"));
- }
- return sb.ToString();
- }
- static void Main(string[] args)
- {
- byte[] bytes = HexToBin("0eff10");
- Console.WriteLine(BytesToBinaryString(bytes));
- }
- static byte[] HexToBin(string hex)
- {
- var result = new byte[hex.Length / 2];
- for (int i = 0; i < hex.Length; i += 2)
- {
- result[i / 2] = byte.Parse(hex.Substring(i, 2), System.Globalization.NumberStyles.HexNumber);
- }
- return result;
- }
- static string BytesToBinaryString(byte[] bytes)
- {
- var ba = new System.Collections.BitArray(bytes);
- System.Text.StringBuilder sb = new StringBuilder();
- for (int i = 0; i < ba.Length; i++)
- {
- int byteStart = (i / 8) * 8;
- int bit = 7 - i % 8;
- sb.Append(ba[byteStart + bit] ? '1' : '0');
- if (i % 8 == 7)
- sb.Append(' ');
- }
- return sb.ToString();
- }
- string valueString = "this is my test string";
- byte[] value = System.Text.Encoding.ASCII.GetBytes(valueString);
- Microsoft.Win32.Registry.SetValue(keyName, valueName, valueString, Microsoft.Win32.RegistryValueKind.Binary);
Add Comment
Please, Sign In to add comment