关闭

KEY_NOTIFY 有什么用

标签: KEY_NOTIFY 有什么用
162人阅读 评论(0) 收藏 举报
分类:
搜索KEY_NOTIFY的结果是:许可提供更该通知,
msdn上说,但并没有详细解释

Required to request change notifications for a registry key or for subkeys of a registry key.

其实这个值与

Required to request


 change notifications for a registry key or for subkeys of a registry key.


RegNotifyChangeKeyValue 函数有关

代码

Required to request


 change notifications for a registry key or for subkeys of a registry key.


#include <stdio.h>
#include <windows.h>

void main(int argc, char *argv[])
{
   DWORD  dwFilter = REG_NOTIFY_CHANGE_NAME |
                     REG_NOTIFY_CHANGE_ATTRIBUTES |
                     REG_NOTIFY_CHANGE_LAST_SET |
                     REG_NOTIFY_CHANGE_SECURITY; 

   HANDLE hEvent;
   HKEY   hMainKey;
   HKEY   hKey;
   LONG   lErrorCode;

   // Display the usage error message.
   if (argc != 3) 
   {
      printf("Usage: notify [HKLM/HKU/HKCU/HKCR/HCC] [subkey]\n");
      return;
   }

   // Convert parameters to appropriate handles.
   if (strcmp("HKLM", argv[1]) == 0) hMainKey = HKEY_LOCAL_MACHINE;
   else if (strcmp("HKU", argv[1]) == 0) hMainKey = HKEY_USERS;
   else if (strcmp("HKCU", argv[1]) == 0) hMainKey = HKEY_CURRENT_USER;
   else if (strcmp("HKCR", argv[1]) == 0) hMainKey = HKEY_CLASSES_ROOT;
   else if (strcmp("HCC", argv[1]) == 0) hMainKey = HKEY_CURRENT_CONFIG;
   else 
   {
      printf("Usage: notify [HKLM/HKU/HKCU/HKCR/HCC] [subkey]\n");
      return;
   }

   // Open a key.
   lErrorCode = RegOpenKeyEx(hMainKey, argv[2], 0, KEY_NOTIFY, &hKey);
   if (lErrorCode != ERROR_SUCCESS)
   {
      printf("Error in RegOpenKeyEx.\n");
      return;
   }

   // Create an event.
   hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
   if (hEvent == NULL)
   {
      printf("Error in CreateEvent.\n");
      return;
   }

   // Watch the registry key for a change of value.
   lErrorCode = RegNotifyChangeKeyValue(hKey, 
                                        TRUE, 
                                        dwFilter, 
                                        hEvent, 
                                        TRUE);
   if (lErrorCode != ERROR_SUCCESS)
   {
      printf("Error in RegNotifyChangeKeyValue.\n");
      return;
   }

   // Wait for an event to occur.
   if (WaitForSingleObject(hEvent, INFINITE) == WAIT_FAILED)
   {
      printf("Error in WaitForSingleObject.\n");
      return;
   }

   // Close the key.
   lErrorCode = RegCloseKey(hKey);
   if (lErrorCode != ERROR_SUCCESS)
   {
      printf("Error in RegCloseKey.\n");
      return;
   }

   // Close the handle.
   if (!RegCloseKey(hEvent))
   {
      printf("Error in RegCloseKey.\n");
      return;
   }
}






Required to request


 change notifications for a registry key or for subkeys of a registry key.

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:20768次
    • 积分:571
    • 等级:
    • 排名:千里之外
    • 原创:36篇
    • 转载:5篇
    • 译文:1篇
    • 评论:8条
    最新评论