Tom_lyd
驱动大牛
驱动大牛
  • 注册日期2001-09-02
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分10分
  • 威望1点
  • 贡献值0点
  • 好评度1点
  • 原创分0分
  • 专家分0分
20楼#
发布于:2002-06-07 14:00
我为什么在内核态打开这个键失败?
代码如下:
BOOLEAN ret = FALSE;
    NTSTATUS status;

    OBJECT_ATTRIBUTES Attributes;
    HANDLE LogonKey;
    ULONG BufferSize, ResultLength;
    PVOID Buffer = NULL;

    PKEY_VALUE_PARTIAL_INFORMATION pValuePartialInfo;

//
// The registry key that the current logon usre name stays.
//
WCHAR UserKey[]
= L\"\\\\Registry\\\\User\\\\Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Explorer\";
UNICODE_STRING Logon;

WCHAR UserName[] = L\"\\\\Logon User Name\";
UNICODE_STRING LogonUser;

__try
{
__try
{
//
// Initialize the registry key.
//
RtlInitUnicodeString( &Logon, UserKey );
InitializeObjectAttributes( &Attributes,
&Logon,
OBJ_CASE_INSENSITIVE,
NULL,
NULL ); //Void return

status = ZwOpenKey( &LogonKey, KEY_READ, &Attributes );
if( !NT_SUCCESS(status) )
{
LogonKey = NULL;
return( ret=FALSE );
}

BufferSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + USERNAMELEN;
Buffer = ExAllocatePool(NonPagedPool, BufferSize);

if( !Buffer )
return( ret=FALSE );
//
// Read the \"Logon User Name\" from the registry key
//
RtlInitUnicodeString( &LogonUser, UserName );

status = ZwQueryValueKey( LogonKey,
&LogonUser,
KeyValuePartialInformation,
Buffer,
BufferSize,
&ResultLength);

if( NT_SUCCESS(status) )
{
pValuePartialInfo = (PKEY_VALUE_PARTIAL_INFORMATION) Buffer;
ASSERT( pValuePartialInfo->Type == REG_SZ );
//        gMaxRecordsToAllocate = *((PLONG)&(pValuePartialInfo->Data));
RtlCopyMemory( pGlobalData->LogonUserName,
(PCHAR)(pValuePartialInfo->Data),
pValuePartialInfo->DataLength );
} else {

RtlCopyMemory( pGlobalData->LogonUserName, \"???\", 3 );
}
}
__except( EXCEPTION_EXECUTE_HANDLER )
{
DbgPrint((\"Read registry key value error\\n\"));
}
}
__finally
{
if( Buffer)
ExFreePool( Buffer );

if( LogonKey )
ZwClose( LogonKey );
}
    return ret;
Tom_lyd
guardee
驱动巨牛
驱动巨牛
  • 注册日期2002-11-08
  • 最后登录2010-05-29
  • 粉丝2
  • 关注1
  • 积分2分
  • 威望34点
  • 贡献值0点
  • 好评度6点
  • 原创分0分
  • 专家分0分
21楼#
发布于:2002-06-07 14:57
你的驱动程序是什么时候运行这部分代码的啊!用户登陆之前还是之后啊?
Tom_lyd
驱动大牛
驱动大牛
  • 注册日期2001-09-02
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分10分
  • 威望1点
  • 贡献值0点
  • 好评度1点
  • 原创分0分
  • 专家分0分
22楼#
发布于:2002-06-07 17:03
是登录以后运行的。
Tom_lyd
上一页 下一页
游客

返回顶部