none
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 RRS feed

  • Question

  • 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 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

    Friday, August 8, 2014 4:08 PM

All replies

  • 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?


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com

    Friday, August 8, 2014 4:16 PM
  • Yes,

    RequiredKeyName is unique for the DeviceObject

    and Value also need to be same .

    But Only Key is created and no values are present in it.



    vidyasagar196

    Friday, August 8, 2014 4:26 PM