2018-09-27 08:05:10 +00:00
|
|
|
|
using System;
|
|
|
|
|
using Microsoft.Win32;
|
2016-01-27 08:37:46 +00:00
|
|
|
|
|
2018-10-04 19:49:24 +00:00
|
|
|
|
namespace Quasar.Server.Extensions
|
2016-01-27 08:37:46 +00:00
|
|
|
|
{
|
|
|
|
|
public static class RegistryKeyExtensions
|
|
|
|
|
{
|
|
|
|
|
public static string RegistryTypeToString(this RegistryValueKind valueKind, object valueData)
|
|
|
|
|
{
|
2016-04-22 20:12:48 +00:00
|
|
|
|
if (valueData == null)
|
|
|
|
|
return "(value not set)";
|
|
|
|
|
|
2016-01-27 08:37:46 +00:00
|
|
|
|
switch (valueKind)
|
|
|
|
|
{
|
|
|
|
|
case RegistryValueKind.Binary:
|
|
|
|
|
return ((byte[])valueData).Length > 0 ? BitConverter.ToString((byte[])valueData).Replace("-", " ").ToLower() : "(zero-length binary value)";
|
|
|
|
|
case RegistryValueKind.MultiString:
|
|
|
|
|
return string.Join(" ", (string[])valueData);
|
|
|
|
|
case RegistryValueKind.DWord: //Convert with hexadecimal before int
|
2016-02-08 10:40:14 +00:00
|
|
|
|
return String.Format("0x{0} ({1})", ((uint)((int)valueData)).ToString("x8"), ((uint)((int)valueData)).ToString());
|
2016-01-27 08:37:46 +00:00
|
|
|
|
case RegistryValueKind.QWord:
|
2016-02-08 10:40:14 +00:00
|
|
|
|
return String.Format("0x{0} ({1})", ((ulong)((long)valueData)).ToString("x8"), ((ulong)((long)valueData)).ToString());
|
2016-01-27 08:37:46 +00:00
|
|
|
|
case RegistryValueKind.String:
|
|
|
|
|
case RegistryValueKind.ExpandString:
|
|
|
|
|
return valueData.ToString();
|
|
|
|
|
case RegistryValueKind.Unknown:
|
|
|
|
|
default:
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string RegistryTypeToString(this RegistryValueKind valueKind)
|
|
|
|
|
{
|
|
|
|
|
switch (valueKind)
|
|
|
|
|
{
|
|
|
|
|
case RegistryValueKind.Binary:
|
|
|
|
|
return "REG_BINARY";
|
|
|
|
|
case RegistryValueKind.MultiString:
|
|
|
|
|
return "REG_MULTI_SZ";
|
|
|
|
|
case RegistryValueKind.DWord:
|
|
|
|
|
return "REG_DWORD";
|
|
|
|
|
case RegistryValueKind.QWord:
|
|
|
|
|
return "REG_QWORD";
|
|
|
|
|
case RegistryValueKind.String:
|
|
|
|
|
return "REG_SZ";
|
|
|
|
|
case RegistryValueKind.ExpandString:
|
|
|
|
|
return "REG_EXPAND_SZ";
|
|
|
|
|
case RegistryValueKind.Unknown:
|
|
|
|
|
return "(Unknown)";
|
|
|
|
|
default:
|
|
|
|
|
return "REG_NONE";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|