如何从驱动程序代码中读取注册表?

时间:2013-07-29 11:27:14

标签: c windows registry driver

我的机器是Windows 8机器。我想从我的自定义驱动程序中读取HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{36fc9e60-c465-11cf-8056-444553540000}中的“UpperFilters”键,以通过USB设备获得过滤器驱动程序。

2 个答案:

答案 0 :(得分:3)

自XP时代以来,我还没有编写过驱动程序,但假设您正在讨论内核模式驱动程序,我相信您需要ZwOpenKeyZwQueryValueKeyZwClose。一般指导here

答案 1 :(得分:-1)

here是在c

中读取注册表的代码示例

这是一个示例:

DWORD BufferSize = TOTALBYTES;
DWORD cbData;
DWORD dwRet;

PPERF_DATA_BLOCK PerfData = (PPERF_DATA_BLOCK) malloc( BufferSize );
cbData = BufferSize;

printf("\nRetrieving the data...");

dwRet = RegQueryValueEx( HKEY_PERFORMANCE_DATA,
                         TEXT("Global"),
                         NULL,
                         NULL,
                         (LPBYTE) PerfData,
                         &cbData );
while( dwRet == ERROR_MORE_DATA )
{
    // Get a buffer that is big enough.

    BufferSize += BYTEINCREMENT;
    PerfData = (PPERF_DATA_BLOCK) realloc( PerfData, BufferSize );
    cbData = BufferSize;

    printf(".");
    dwRet = RegQueryValueEx( HKEY_PERFORMANCE_DATA,
                     TEXT("Global"),
                     NULL,
                     NULL,
                     (LPBYTE) PerfData,
                     &cbData );
}
if( dwRet == ERROR_SUCCESS )
    printf("\n\nFinal buffer size is %d\n", BufferSize);
else printf("\nRegQueryValueEx failed (%d)\n", dwRet);

或在一个简单的例子中

RegGetValue(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Class", "{36fc9e60-c465-11cf-8056-444553540000}", RRF_RT_ANY, NULL, (PVOID)&value, &BufferSize);