none
How to read/write my parameters into Registry??? RRS feed

  • Question

  • Hi, Sir:

    I don't have any experience about read/write parameters into Registry in kmdf driver
    I hope to put parameters(MasterResX, MasterResY,...) at path: \Services\DriverName\Parameters
    I tried to find sample code in MSDN, but it confused me(WdfFdoInitXXX or WdfDeviceXXX??? or WdfRegistryXXX???)
    How to read/write parameters into Registry???

    When loading driver at first time, not have subkey and value in registry, what value to get?

    Thank you for your help

    BR,
    Alan

    Thursday, November 12, 2015 10:06 AM

Answers

  • Take a look at https://msdn.microsoft.com/en-us/library/windows/hardware/ff546320%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396 for the directives to add registry entries to the INF files.  If you look at the Toaster Sample in the WDK the FUNC driver FEATURED versions inf, wdffeatured.inf has an example of adding a registry value called "BeepCount" to the driver parameters.


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

    • Marked as answer by alan.emc Tuesday, December 15, 2015 2:36 AM
    Monday, November 16, 2015 1:18 PM
  • You should use the WdfRegistryXXX functions.

    use WdfRegistryCreateKey() to create\open existing registry key (use the REG_CREATED_NEW_KEY to know if key was created or already exist)

    use WdfRegistryAssignXXX() to set values to registry key

    use WdfRegistryQueryXXX() to get values from registry key.

    • Proposed as answer by Shosho Gold Thursday, November 12, 2015 10:44 AM
    • Marked as answer by Doron Holan [MSFT] Thursday, November 12, 2015 7:22 PM
    Thursday, November 12, 2015 10:41 AM

All replies

  • You should use the WdfRegistryXXX functions.

    use WdfRegistryCreateKey() to create\open existing registry key (use the REG_CREATED_NEW_KEY to know if key was created or already exist)

    use WdfRegistryAssignXXX() to set values to registry key

    use WdfRegistryQueryXXX() to get values from registry key.

    • Proposed as answer by Shosho Gold Thursday, November 12, 2015 10:44 AM
    • Marked as answer by Doron Holan [MSFT] Thursday, November 12, 2015 7:22 PM
    Thursday, November 12, 2015 10:41 AM
  • As was described above use the WdfRegistryXXX functions for reading and writing.  For initial values when the driver is first loaded you can create them in the INF file.


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

    Thursday, November 12, 2015 12:02 PM
  • Thanks for Gold's information

    Below is my code, is it correct???

    //----------------------------------For Reading---------------------------------------//
     status = WdfDeviceOpenRegistryKey(hDevice,
      PLUGPLAY_REGKEY_DRIVER,
      STANDARD_RIGHTS_ALL,
      WDF_NO_OBJECT_ATTRIBUTES,
      &hKey);
     if (!NT_SUCCESS(status)){
      return;
     }

     RtlInitUnicodeString(&KeyStr, L"Parameters");
     status = WdfRegistryCreateKey(
      hKey,
      &KeyStr,
      KEY_READ,
      REG_OPTION_NON_VOLATILE,
      NULL,
      WDF_NO_OBJECT_ATTRIBUTES,
      &hSubKey
      );
     if (!NT_SUCCESS(status)){
      return;
     }

     RtlInitUnicodeString(&valueName, L"MasterResX");
     ulValue = 0;
     status = WdfRegistryQueryULong(hSubKey, &valueName, &ulValue);
     if (!NT_SUCCESS(status)){
      return;
     }

    //------------------------------------------------------------------------------------//
    //----------------------------------For Writing---------------------------------------//
     status = WdfDeviceOpenRegistryKey(hDevice,
      PLUGPLAY_REGKEY_DRIVER,
      STANDARD_RIGHTS_ALL,
      WDF_NO_OBJECT_ATTRIBUTES,
      &hKey);
     if (!NT_SUCCESS(status)){
      return;
     }

     RtlInitUnicodeString(&KeyStr, L"Parameters");
     status = WdfRegistryCreateKey(
      hKey,
      &KeyStr,
      KEY_READ,
      REG_OPTION_NON_VOLATILE,
      NULL,
      WDF_NO_OBJECT_ATTRIBUTES,
      &hSubKey
      );
     if (!NT_SUCCESS(status)){
      return;
     }

     RtlInitUnicodeString(&valueName, L"MasterResX");
     status = WdfRegistryAssignULong(hSubKey, &valueName, (ULONG)lMasterRes);
     if (!NT_SUCCESS(status)){
      return;
     }
    //------------------------------------------------------------------------------------//

    Monday, November 16, 2015 2:01 AM
  • Thanks for Don's information

    Below is context, is it correct???

    [eTouchfiltr.HW.AddReg]
    HKLM, SYSTEM\CurrentControlSet\Services\DriverName, "Parameters\MasterResX", ,1024

     
    BR,
    Alan

    • Edited by alan.emc Monday, November 16, 2015 2:17 AM
    Monday, November 16, 2015 2:04 AM
  • Take a look at https://msdn.microsoft.com/en-us/library/windows/hardware/ff546320%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396 for the directives to add registry entries to the INF files.  If you look at the Toaster Sample in the WDK the FUNC driver FEATURED versions inf, wdffeatured.inf has an example of adding a registry value called "BeepCount" to the driver parameters.


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

    • Marked as answer by alan.emc Tuesday, December 15, 2015 2:36 AM
    Monday, November 16, 2015 1:18 PM
  • Dear Don:

    Thanks for your information

    It is great for me.

    I add custom parameters in inf file and the context is like
     "HKLM, System\CurrentControlSet\Services\Moufiltr\Parameters, MasterResX, 0x00010001, 0x400"

    And in the driver to read/write these parameters
     So I add below code(only list read part)
     But I found it read/write wrong path(under HKLM\SYSTEM\CurrentControlSet\Control\Class\{...}\0003\Parameters)

     How to get right and the same path set by ini file???

     Thank you for your great help

    //------------------------------------------------------------------------------------------//
     status = WdfDeviceOpenRegistryKey(hDevice,
      PLUGPLAY_REGKEY_DRIVER,
      STANDARD_RIGHTS_ALL,
      WDF_NO_OBJECT_ATTRIBUTES,
      &hKey);
     if (!NT_SUCCESS(status)){
      return;
     }

     RtlInitUnicodeString(&KeyStr, L"Parameters");
     status = WdfRegistryCreateKey(
      hKey,
      &KeyStr,
      KEY_READ,
      REG_OPTION_NON_VOLATILE,
      NULL,
      WDF_NO_OBJECT_ATTRIBUTES,
      &hSubKey
      );
     if (!NT_SUCCESS(status)){
      return;
     }

     RtlInitUnicodeString(&valueName, L"MasterResX");
     ulValue = 0;
     status = WdfRegistryQueryULong(hSubKey, &valueName, &ulValue);
     if (!NT_SUCCESS(status)){
      return;
     }
    //------------------------------------------------------------------------------------------//

    Wednesday, December 2, 2015 9:43 AM