驱动注册表操作
(2009-12-05 22:04:51) 标签: 杂谈 |
//------------------DeleteKey--------------------------------------------
NTSTATUS status = STATUS_SUCCESS;
HANDLE hSubKey;
OBJECT_ATTRIBUTES oa;
UNICODE_STRING usRegistryPath;
RtlInitUnicodeString(&usRegistryPath,L"\\Registry\\Machine\\SOFTWARE\\3721\\CnsMin");
InitializeObjectAttribut
status=ZwOpenKey(&hSubKey, KEY_ALL_ACCESS, &oa);
DbgPrint("Open Key %d\n",status);
status=ZwDeleteKey(hSubKey);
DbgPrint("Delete Key %d\n",status);
//----------------------CreateKey-----------------------------------------
HANDLE hSubKey;
OBJECT_ATTRIBUTES oa;
UNICODE_STRING RegistryPath;
RtlInitUnicodeString(&RegistryPath,L"\\Registry\\Machine\\SOFTWARE\\3721\\CnsMin") ;
InitializeObjectAttribut
status= ZwCreateKey(&hSubKey, KEY_ALL_ACCESS, &oa,0,&RegistryPath,REG_OPTION_NON_VOLATILE, NULL);
DbgPrint("Create Key %d\n",status);
//----------------------SetValue---------ULONG--------------------------------
NTSTATUS status = STATUS_SUCCESS;
HANDLE hSubKey;
ULONG dwKeyValue=1987;
UNICODE_STRING usValueName;
UNICODE_STRING usRegistryPath;
OBJECT_ATTRIBUTES oa;
OBJECT_ATTRIBUTES oa2;
RtlInitUnicodeString(&usRegistryPath,L"\\Registry\\Machine\\SOFTWARE\\3721\\CnsMin") ;
InitializeObjectAttribut
RtlInitUnicodeString(&usValueName,L"DrSmart") ;
InitializeObjectAttribut
//------------------SetValue---------WCHAR-----------------------------------------
NTSTATUS status = STATUS_SUCCESS;
HANDLE hSubKey;
OBJECT_ATTRIBUTES oa;
OBJECT_ATTRIBUTES oa2;
WCHAR
UNICODE_STRING usValueName;
UNICODE_STRING usRegistryPath;
RtlInitUnicodeString(&usRegistryPath,L"\\Registry\\Machine\\SOFTWARE\\3721\\CnsMin") ;
InitializeObjectAttribut
RtlInitUnicodeString(&usValueName,L"DrSmart");
InitializeObjectAttribut
//--------------------------SetValue----------wchar---------------------------
WCHAR wszKeyValue[256]={0};
memset(wszKeyValue,0,256*2);
wcsncpy(wszKeyValue, L"F:\\Program Files\\Tencent\\TM\\TMShell.exe",256);
RtlWriteRegistryValue(RTL_REGISTRY_ABSOLUTE,L"\\Registry\\Machine\\SOFTWARE\\Microsoft\\Windows
//-------------------check key exist--------------------------------------
status= RtlCheckRegistryKey(RTL_REGISTRY_ABSOLUTE,L"\\Registry\\Machine\\SOFTWARE\\Microsoft\\Windows
//-------------------------QueryValue-----------------------------------
UNICODE_STRING usKeyName;
//-------------------enum key---------------------------------------------
ULONG GetAdapterRegistry()
{
NTSTATUS status = STATUS_SUCCESS;
NDIS_STRING UC_SubKey = NDIS_STRING_CONST("\\REGISTRY\\MACHINE\\SYSTEM\\CurrentControlSet\\Services\\" );
NDIS_STRING UC_KeyValue = NDIS_STRING_CONST( "ImagePath" );
NDIS_STRING NetCardName;
UNICODE_STRING NetCardKey;
UNICODE_STRING NetCardDev;
HANDLE hKey, hKeyNet;
PWCHAR NetCardGuid = NULL;
ULONG i, lRtn;
UCHAR keyBuffer[2048]={0};
OBJECT_ATTRIBUTES KeyAttrib;
OBJECT_ATTRIBUTES KeyAttribNet;
PKEY_BASIC_INFORMATION pKeyInfo;
KEY_VALUE_PARTIAL_INFORMATION * KeyValueInfo;
RtlZeroMemory( &KeyAttrib, sizeof(OBJECT_ATTRIBUTES) );
RtlInitUnicodeString(&NetCardKey,L"\\REGISTRY\\MACHINE\\SYSTEM\\CurrentControlSet\\Services" );
InitializeObjectAttribut
status = ZwOpenKey( &hKey, KEY_ALL_ACCESS, &KeyAttrib );
if( NT_SUCCESS(status) )
{
for( i = 0 ; ; i++ )
{
}
ZwClose(hKey);
}
else
DbgPrint( "Can`t Open Registry \n!") ;
}
转自:http://hi.baidu.com/xwind85/blog/item/6a32d2438941fc1973f05ddf