网站首页  词典首页

请输入您要查询的函数:

 

术语 regnotifychangekeyvalue
释义 RegNotifyChangeKeyValue
语法:
C++
LONG WINAPI RegNotifyChangeKeyValue(
__in HKEY hKey,
__in BOOL bWatchSubtree,
__in DWORD dwNotifyFilter,
__in_opt HANDLE hEvent,
__in BOOL fAsynchronous
);
RegNotifyChangeKeyValue功能
通知有关的属性或指定的注册表项内容的变化来电。
参数
hKey [in]
句柄到打开注册表项。这种处理是由RegCreateKeyEx的或RegOpenKeyEx函数返回。它也可以是下列预定义项之一:
HKEY_CLASSES_ROOT
HKEY_CURRENT_CONFIG
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_USERS
此参数必须是本地处理。如果RegNotifyChangeKeyValue是与远程处理调用,它返回出现ERROR_INVALID_HANDLE。
关键必须是开放的KEY_NOTIFY访问权限。有关更多信息,请参见注册表关键的安全和访问权限。
bWatchSubtree [in]
如果此参数为TRUE,函数报告指定键和其子项的变化。如果该参数为FALSE,函数报告仅在指定的重要变化。
dwNotifyFilter [in]
一个值,指示应报告的变化。此参数可以是一个或多个下列值。
ValueMeaning
REG_NOTIFY_CHANGE_NAME
0x00000001LNotify调用,如果一个子项添加或删除。
REG_NOTIFY_CHANGE_ATTRIBUTES
0x00000002LNotify了对来电者的属性变化的关键,如安全描述符的信息。
REG_NOTIFY_CHANGE_LAST_SET
0x00000004LNotify的一个关键价值的变化来电。这包括添加或删除一个值,或更改现有的值。
REG_NOTIFY_CHANGE_SECURITY
0x00000008LNotify了对关键的安全描述符变化来电。
hEvent [中,可选]
阿处理的事件。如果fAsynchronous参数为true,函数立即返回和变化影响的报告表明这一事件。如果fAsynchronous为FALSE,hEvent被忽略。
fAsynchronous [in]
如果此参数为TRUE,则函数返回,并立即报告指定的事件信号的变化。如果此参数为FALSE,函数不返回,直到发生了变化。
如果hEvent没有指定一个有效的情况下,fAsynchronous参数是不正确的。
返回值
如果函数成功,返回值是ERROR_SUCCESS。
如果函数失败,返回值是一个非零错误代码Winerror.h中定义。您可以使用带有FORMAT_MESSAGE_FROM_SYSTEM标记的FormatMessage函数获得错误的一般说明。
备注
这个功能可以检测每一个变化。来电后,收到一个通知事件,应该再次调用该函数接收下一个通知。
此函数不能用于检测使用的RegRestoreKey功能的注册表变化的结果。
如果指定的键关闭,该事件被触发。这意味着应用程序不应该取决于被从后等待操作返回的事件公开的关键。
如果线程调用RegNotifyChangeKeyValue退出,该事件被触发。继续监测的关键值的其他变动,从另一个线程RegNotifyChangeKeyValue了。
这个函数必须被要求持续线程。如果调用线程是从一个线程池,这是不是持久,该事件标志着每次线程终止,而不仅仅是在有更改注册表。为了确保准确的结果,设置线程池的最大等于最小线程池使用SetThreadpoolThreadMaximum和SetThreadpoolThreadMinimum功能,或创建自己的线程使用CreateThread函数。 (对于原来的线程池API,指定WT_EXECUTEINPERSISTENTTHREAD使用QueueUserWorkItem函数。)
此函数不应该被称为具有相同价值的多个倍hKey但对bWatchSubtree和dwNotifyFilter不同的参数值。该函数会成功,但变化将被忽略。要更改监视参数,您必须先关闭密钥句柄调用RegCloseKey,重新打开密钥句柄调用RegOpenKeyEx,然后调用新参数RegNotifyChangeKeyValue。
每次进程调用RegNotifyChangeKeyValue与同一组的参数,它建立一个等待操作,造成资源泄漏。因此,请检查您不调用,直至前等待操作相同的参数RegNotifyChangeKeyValue已完成。
为了监测更详细的注册表操作,请书记官处。
实例
下面的程序说明如何使用RegNotifyChangeKeyValue。
#include
#include
#include
//void main(int argc, char *argv[])
void __cdecl _tmain(int argc, TCHAR *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)
{
_tprintf(TEXT("Usage: notify [HKLM|HKU|HKCU|HKCR|HCC] []\\n"));
return;
}
// Convert parameters to appropriate handles.
if (_tcscmp(TEXT("HKLM"), argv[1]) == 0) hMainKey=HKEY_LOCAL_MACHINE;
else if(_tcscmp(TEXT("HKU"), argv[1]) == 0) hMainKey=HKEY_USERS;
else if(_tcscmp(TEXT("HKCU"), argv[1]) == 0) hMainKey=HKEY_CURRENT_USER;
else if(_tcscmp(TEXT("HKCR"), argv[1]) == 0) hMainKey=HKEY_CLASSES_ROOT;
else if(_tcscmp(TEXT("HCC"), argv[1]) == 0) hMainKey=HKEY_CURRENT_CONFIG;
else
{
_tprintf(TEXT("Usage: notify [HKLM|HKU|HKCU|HKCR|HCC] []\\n"));
return;
}
// Open a key.
lErrorCode = RegOpenKeyEx(hMainKey, argv[2], 0, KEY_NOTIFY, &hKey);
if (lErrorCode != ERROR_SUCCESS)
{
_tprintf(TEXT("Error in RegOpenKeyEx (%d).\\n"), lErrorCode);
return;
}
// Create an event.
hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (hEvent == NULL)
{
_tprintf(TEXT("Error in CreateEvent (%d).\\n"), GetLastError());
return;
}
// Watch the registry key for a change of value.
lErrorCode = RegNotifyChangeKeyValue(hKey,
TRUE,
dwFilter,
hEvent,
TRUE);
if (lErrorCode != ERROR_SUCCESS)
{
_tprintf(TEXT("Error in RegNotifyChangeKeyValue (%d).\\n"), lErrorCode);
return;
}
// Wait for an event to occur.
_tprintf(TEXT("Waiting for a change in the specified key...\\n"));
if (WaitForSingleObject(hEvent, INFINITE) == WAIT_FAILED)
{
_tprintf(TEXT("Error in WaitForSingleObject (%d).\\n"), GetLastError());
return;
}
else _tprintf(TEXT("\\nChange has occurred.\\n"));
// Close the key.
lErrorCode = RegCloseKey(hKey);
if (lErrorCode != ERROR_SUCCESS)
{
_tprintf(TEXT("Error in RegCloseKey (%d).\\n"), GetLastError());
return;
}

// Close the handle.
if (!CloseHandle(hEvent))
{
_tprintf(TEXT("Error in CloseHandle.\\n"));
return;
}
}
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWinreg.h(头文件:winuser.h)
LibraryAdvapi32.lib
DLLAdvapi32.dll
参见
RegCloseKey
RegDeleteKey
RegEnumKeyEx
RegEnumValue
登记职能
RegQueryInfoKey
RegQueryValueEx
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月27日
==英文原文==RegNotifyChangeKeyValue Function
Notifies the caller about changes to the attributes or contents of a specified registry key.
Syntax
C++
LONG WINAPI RegNotifyChangeKeyValue(
__in HKEY hKey,
__in BOOL bWatchSubtree,
__in DWORD dwNotifyFilter,
__in_opt HANDLE hEvent,
__in BOOL fAsynchronous
);
Parameters
hKey [in]
A handle to an open registry key. This handle is returned by the RegCreateKeyEx or RegOpenKeyEx function. It can also be one of the following predefined keys :
HKEY_CLASSES_ROOT
HKEY_CURRENT_CONFIG
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_USERS
This parameter must be a local handle. If RegNotifyChangeKeyValue is called with a remote handle, it returns ERROR_INVALID_HANDLE.
The key must have been opened with the KEY_NOTIFY access right. For more information, see Registry Key Security and Access Rights .
bWatchSubtree [in]
If this parameter is TRUE, the function reports changes in the specified key and its subkeys. If the parameter is FALSE, the function reports changes only in the specified key.
dwNotifyFilter [in]
A value that indicates the changes that should be reported. This parameter can be one or more of the following values.
ValueMeaning
REG_NOTIFY_CHANGE_NAME
0x00000001LNotify the caller if a subkey is added or deleted.
REG_NOTIFY_CHANGE_ATTRIBUTES
0x00000002LNotify the caller of changes to the attributes of the key, such as the security descriptor information.
REG_NOTIFY_CHANGE_LAST_SET
0x00000004LNotify the caller of changes to a value of the key. This can include adding or deleting a value, or changing an existing value.
REG_NOTIFY_CHANGE_SECURITY
0x00000008LNotify the caller of changes to the security descriptor of the key.

hEvent [in, optional]
A handle to an event. If the fAsynchronous parameter is TRUE, the function returns immediately and changes are reported by signaling this event. If fAsynchronous is FALSE, hEvent is ignored.
fAsynchronous [in]
If this parameter is TRUE, the function returns immediately and reports changes by signaling the specified event. If this parameter is FALSE, the function does not return until a change has occurred.
If hEvent does not specify a valid event, the fAsynchronous parameter cannot be TRUE.
Return Value
If the function succeeds, the return value is ERROR_SUCCESS.
If the function fails, the return value is a nonzero error code defined in Winerror.h. You can use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error.
Remarks
This function detects a single change. After the caller receives a notification event, it should call the function again to receive the next notification.
This function cannot be used to detect changes to the registry that result from using the RegRestoreKey function.
If the specified key is closed, the event is signaled. This means that an application should not depend on the key being open after returning from a wait operation on the event.
If the thread that called RegNotifyChangeKeyValue exits, the event is signaled. To continue to monitor additional changes in the value of the key, call RegNotifyChangeKeyValue again from another thread.
This function must be called on a persistent thread. If the calling thread is from a thread pool and it is not persistent, the event is signaled every time the thread terminates, not just when there is a registry change. To ensure accurate results, set the thread pool maximum equal to the thread pool minimum using the SetThreadpoolThreadMaximum and SetThreadpoolThreadMinimum functions, or create your own thread using the CreateThread function. (For the original thread pool API, specify WT_EXECUTEINPERSISTENTTHREAD using the QueueUserWorkItem function.)
This function should not be called multiple times with the same value for the hKey but different values for the bWatchSubtree and dwNotifyFilter parameters. The function will succeed but the changes will be ignored. To change the watch parameters, you must first close the key handle by calling RegCloseKey , reopen the key handle by calling RegOpenKeyEx , and then call RegNotifyChangeKeyValue with the new parameters.
Each time a process calls RegNotifyChangeKeyValue with the same set of parameters, it establishes another wait operation, creating a resource leak. Therefore, check that you are not calling RegNotifyChangeKeyValue with the same parameters until the previous wait operation has completed.
To monitor registry operations in more detail, see Registry .
Examples
The following program illustrates how to use RegNotifyChangeKeyValue.
#include
#include
#include
//void main(int argc, char *argv[])
void __cdecl _tmain(int argc, TCHAR *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)
{
_tprintf(TEXT("Usage: notify [HKLM|HKU|HKCU|HKCR|HCC] []\\n"));
return;
}
// Convert parameters to appropriate handles.
if (_tcscmp(TEXT("HKLM"), argv[1]) == 0) hMainKey=HKEY_LOCAL_MACHINE;
else if(_tcscmp(TEXT("HKU"), argv[1]) == 0) hMainKey=HKEY_USERS;
else if(_tcscmp(TEXT("HKCU"), argv[1]) == 0) hMainKey=HKEY_CURRENT_USER;
else if(_tcscmp(TEXT("HKCR"), argv[1]) == 0) hMainKey=HKEY_CLASSES_ROOT;
else if(_tcscmp(TEXT("HCC"), argv[1]) == 0) hMainKey=HKEY_CURRENT_CONFIG;
else
{
_tprintf(TEXT("Usage: notify [HKLM|HKU|HKCU|HKCR|HCC] []\\n"));
return;
}
// Open a key.
lErrorCode = RegOpenKeyEx(hMainKey, argv[2], 0, KEY_NOTIFY, &hKey);
if (lErrorCode != ERROR_SUCCESS)
{
_tprintf(TEXT("Error in RegOpenKeyEx (%d).\\n"), lErrorCode);
return;
}
// Create an event.
hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (hEvent == NULL)
{
_tprintf(TEXT("Error in CreateEvent (%d).\\n"), GetLastError());
return;
}
// Watch the registry key for a change of value.
lErrorCode = RegNotifyChangeKeyValue(hKey,
TRUE,
dwFilter,
hEvent,
TRUE);
if (lErrorCode != ERROR_SUCCESS)
{
_tprintf(TEXT("Error in RegNotifyChangeKeyValue (%d).\\n"), lErrorCode);
return;
}
// Wait for an event to occur.
_tprintf(TEXT("Waiting for a change in the specified key...\\n"));
if (WaitForSingleObject(hEvent, INFINITE) == WAIT_FAILED)
{
_tprintf(TEXT("Error in WaitForSingleObject (%d).\\n"), GetLastError());
return;
}
else _tprintf(TEXT("\\nChange has occurred.\\n"));
// Close the key.
lErrorCode = RegCloseKey(hKey);
if (lErrorCode != ERROR_SUCCESS)
{
_tprintf(TEXT("Error in RegCloseKey (%d).\\n"), GetLastError());
return;
}

// Close the handle.
if (!CloseHandle(hEvent))
{
_tprintf(TEXT("Error in CloseHandle.\\n"));
return;
}
}
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinreg.h (include Windows.h)
LibraryAdvapi32.lib
DLLAdvapi32.dll
See Also
RegCloseKey
RegDeleteKey
RegEnumKeyEx
RegEnumValue
Registry Functions
RegQueryInfoKey
RegQueryValueEx
Send comments about this topic to Microsoft
Build date: 8/27/2009
==原始网址==http://msdn.microsoft.com/en-us/library/ms724892(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 13:26:06