我试图通过读取注册表在驱动程序中设置一些变量。,键不存在,我使用此函数创建键。,但没有在注册表中更新 [英] I am trying to set some variables in driver by reading registry.,keys are not present,I am creating keys using this function.,But nothing is updated in registry
问题描述
NTSTATUS SetRegistryKeyValue(IN WDFDEVICE hDevice,IN PWCHAR pcValueName,ULONG ulType,IN PVOID Data,IN ULONG ulDataLength)
NTSTATUS SetRegistryKeyValue ( IN WDFDEVICE hDevice,IN PWCHAR pcValueName,ULONG ulType,IN PVOID Data,IN ULONG ulDataLength)
{
ULONG                     ulLength;
UNICODE_STRING
RequiredKeyName;
WDFKEY
hKey = NULL;
WDFKEY
hSubKey = NULL;
NTSTATUS                 lStatus = STATUS_INSUFFICIENT_RESOURCES;
OBJECT_ATTRIBUTES
stKeyAttributes;
WDFSTRING
RequiredKeyString;
ULONG ulCreateDisposition;
WDF_OBJECT_ATTRIBUTES
stStringAttributes;
ULONG ulAssignValue;
  DECLARE_UNICODE_STRING_SIZE(symbolicLinkName,SYMBOLIC_NAME_LENGTH);
// PAGED_CODE();
RtlInitUnicodeString(& RequiredKeyName,pcValueName);
  WDF_OBJECT_ATTRIBUTES_INIT(& stStringAttributes);
  stStringAttributes.ParentObject = hDevice;
$
lStatus = WdfStringCreate(NULL,& stStringAttributes,& RequiredKeyString);
$
  if(!NT_SUCCESS(lStatus))
{
KdPrint((DRIVERNAME"WdfStringCreate失败,状态:0X%x \ n",lStatus));
    return lStatus;
  }
//打开注册表并获取它将其存储在设备上的父键
lStatus = WdfDeviceOpenRegistryKey(hDevice,
PLUGPLAY_REGKEY_DRIVER,
KEY_ALL_ACCESS,
WDF_NO_OBJECT_ATTRIBUTES,
& hKey
);
if(!NT_SUCCESS(lStatus))
{
< span style ="white-space:pre"> KdPrint((DRIVERNAME"WdfDeviceOpenRegistryKey失败状态:0X%x \ n",lStatus));
返回lStatus;
}
//在父键下打开一个子键并创建或打开所要求类型的钥匙
lStatus = WdfRegistryCreateKey(
hKey,
& RequiredKeyName,
KEY_ALL_ACCESS,
REG_OPTION_NON_VOLATILE,
& ulCreateDisposition,
WDF_NO_OBJECT_ATTRIBUTES,
& NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; & hSubKey
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ); $
if(!NT_SUCCESS(lStatus))
{
KdPrint((DRIVERNAME"WdfRegistryCreateKey失败,状态:0X%x \ n",lStatus));
返回lStatus;
}
/ /如果子键可用,则在设备上下文中读取和存储数据
lStatus = WdfRegistryAssignValue(hSubKey,
& RequiredKeyName,
ulType,
ulDataLength,
数据
);
if(!NT_SUCCESS(lStatus))
{
KdPrint((DRIVERNAME"WdfRegistryQueryValue失败,状态:0X%x \ n",lStatus));
返回lStatus;
}
// lStatus = RtlWriteRegistryValue(RTL_REGISTRY_HANDLE,SERIAL_DEVICE_MAP,pcValueName,REG_SZ,Data,ulDataLength);
$
if(NULL!= hSubKey)
WdfRegistryClose(hSubKey);
if(NULL!= hKey)
WdfRegistryClose(hKey);
返回lStatus;
}
ULONG ulLength;
UNICODE_STRING
RequiredKeyName;
WDFKEY
hKey=NULL;
WDFKEY
hSubKey=NULL;
NTSTATUS lStatus = STATUS_INSUFFICIENT_RESOURCES;
OBJECT_ATTRIBUTES
stKeyAttributes;
WDFSTRING
RequiredKeyString;
ULONG ulCreateDisposition;
WDF_OBJECT_ATTRIBUTES
stStringAttributes;
ULONG ulAssignValue;
DECLARE_UNICODE_STRING_SIZE(symbolicLinkName,SYMBOLIC_NAME_LENGTH ) ;
// PAGED_CODE();
RtlInitUnicodeString (&RequiredKeyName, pcValueName);
WDF_OBJECT_ATTRIBUTES_INIT(&stStringAttributes);
stStringAttributes.ParentObject = hDevice;
lStatus = WdfStringCreate(NULL,&stStringAttributes, &RequiredKeyString);
if(!NT_SUCCESS(lStatus))
{
KdPrint((DRIVERNAME" WdfStringCreate is Fail with Status : 0X%x \n",lStatus));
return lStatus;
}
//Open the Registry and Get the Parent Key it store it in device contect
lStatus = WdfDeviceOpenRegistryKey( hDevice,
PLUGPLAY_REGKEY_DRIVER,
KEY_ALL_ACCESS,
WDF_NO_OBJECT_ATTRIBUTES,
&hKey
);
if (!NT_SUCCESS(lStatus))
{
KdPrint((DRIVERNAME"WdfDeviceOpenRegistryKey Failed with Status : 0X%x \n",lStatus));
return lStatus;
}
//Open a Sub-key under Parent Key and create or open the key of requested Type
lStatus = WdfRegistryCreateKey(
hKey,
&RequiredKeyName,
KEY_ALL_ACCESS,
REG_OPTION_NON_VOLATILE,
&ulCreateDisposition,
WDF_NO_OBJECT_ATTRIBUTES,
&hSubKey
);
if (!NT_SUCCESS(lStatus))
{
KdPrint((DRIVERNAME"WdfRegistryCreateKey Failed with Status : 0X%x \n",lStatus));
return lStatus;
}
//If sub key available read and store data in Device Context
lStatus = WdfRegistryAssignValue(hSubKey,
&RequiredKeyName,
ulType,
ulDataLength,
Data
);
if (!NT_SUCCESS(lStatus))
{
KdPrint((DRIVERNAME"WdfRegistryQueryValue Failed with Status : 0X%x \n",lStatus));
return lStatus;
}
// lStatus = RtlWriteRegistryValue(RTL_REGISTRY_HANDLE, SERIAL_DEVICE_MAP,pcValueName,REG_SZ,Data,ulDataLength);
if(NULL!=hSubKey)
WdfRegistryClose(hSubKey);
if(NULL!=hKey)
WdfRegistryClose(hKey);
return lStatus;
}
vidyasagar196
vidyasagar196
推荐答案
注册表键就像目录一样,注册表值就像文件一样&NBSP;您正在创建名为"RequiredKeyName"的密钥然后在该键下创建一个名为"RequiredKeyName"的值。 这真的是你想要的吗?
Registry Keys are like directories, Registry values are like files. You are creating a Key named "RequiredKeyName" then creating a value under that key with the name "RequiredKeyName". Is this really what you want?
这篇关于我试图通过读取注册表在驱动程序中设置一些变量。,键不存在,我使用此函数创建键。,但没有在注册表中更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!