如何以十六进制

时间:2015-08-26 03:57:22

标签: c# registry registrykey

我想从十六进制的地址中获取state键值

RegistryKey winTrust = Registry.CurrentUser.OpenSubKey(
  @"Software\Microsoft\Windows\CurrentVersion\WinTrust\Trust Providers\Software Publishing", true);

然后将其与23c00值进行比较,如果不相同,请将其设置为23c00

string currentKey = winTrust.GetValue("State").ToString();
if (!currentKey.Equals("23c00"))
 {
   winTrust.SetValue("State", "23c00", RegistryValueKind.DWord);
   winTrust.Close();
 }

它不能正常工作并比较小数值。

我该怎么做?

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。

// Convert value as a hex in a string variable
string currentKey = Convert.ToInt32(winTrust.GetValue("State").ToString()).ToString("x");
if (!currentKey.Equals("23c00"))
 {
  winTrust.SetValue("State", 0x00023c00, RegistryValueKind.DWord);
  winTrust.Close();
 }