private void butCheckKeyboard_Click(object sender, EventArgs e) {
uint check = 0;
Registry.GetDWORDValue(Registry.HKCU, "SOFTWARE\\Microsoft\\Shell",
"HasKeyboard", ref check);
lblInfo.Text = Convert.ToBoolean(check).ToString();
}
В этом примере используется функция-оболочка GetDWORDValue из класса Registry. Если же вы предпочитаете обходиться без функций-оболочек, а обращаться напрямую к функциям API, то пример можно переписать так, как показано в листинге 13.19.
private static bool IsKeyboard() {
uint dwordResult;
UIntPtr hkey = UIntPtr.Zero;
try {
int result =
Registry.RegOpenKeyEx(Registry.HKCU, "SOFTWARE\\Microsoft\\Shell", 0,
Registry.KeyAccess.None, ref hkey);
if (Registry.ERROR_SUCCESS != result) return false;
byte[] bytes = null;
uint length = 0;
Registry.KeyType keyType = Registry.KeyType.None;
result =
Registry.RegQueryValueEx(hkey, "HasKeyboard", IntPtr.Zero, ref keyType,
null, ref length);
if (Registry.ERROR_SUCCESS != result) return false;
bytes = new byte[Marshal.SizeOf(typeof(uint))];
length = (uint)bytes.Length;
keyType = Registry.KeyType.None;
result =
Registry.RegQueryValueEx(hkey, "HasKeyboard", IntPtr.Zero, ref keyType,
bytes, ref length);
if (Registry.ERROR_SUCCESS != result) return false;
dwordResult = BitConverter.ToUInt32(bytes, 0);