gpt4 book ai didi

c# - 读取 Registry_binary 并转换为字符串

转载 作者:行者123 更新时间:2023-11-30 15:01:05 26 4
gpt4 key购买 nike

过去 2 个小时我一直在搜索,实际上我一直在搜索愚蠢的东西。

我正在尝试读取 Registry_binary 值并将其转换为字符串。我尝试了一些我在网上找到的东西(包括一些 stackoverflow 帖子),但似乎我无法让它工作:

class Class1 {
RegistryKey RegKey;
String keys;

static void Main() {
Class1 c=new Class1();
c.initialize();
}

void initialize() {
RegKey=Registry.LocalMachine.OpenSubKey("the location", true);
var bytearray=Converter<RegKey.GetValue("key"), String[keys]>;
Console.WriteLine(bytearray);
System.Threading.Thread.Sleep(5000);
}
}

我也尝试过使用:

keys=keys+BitConverter.ToString(System.byte[RegKey.GetValue("key")]);

根据要求:

RegKey=Registry.LocalMachine.OpenSubKey("Software\\MXstudios\\riseingtesharts", true);
keys=RegKey.GetValue("key");

这将输出 System.Bytes[]

最佳答案

假设 key 被打开

var valueName = "some binary registry value";
var valueKind = registryKey.GetValueKind(valueName);
if (valueKind == RegistryValueKind.Binary)
{
var value = (byte[])registryKey.GetValue(valueName);
var valueAsString = BitConverter.ToString(value);
}

编辑:一些解释:

GetValue 返回对象,BitConverter.ToString 获取字节数组作为参数。因此,我们将 GetValue 返回的值转换为 byte[],以便能够在 BitConverter.ToString 中使用它。但首先我们检查注册表值是否实际上是二进制的。然后你可以安全地将它转换为 byte[],因为 GetValue 为二进制值返回的对象实际上是字节数组。

关于c# - 读取 Registry_binary 并转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14668091/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com