locked
programmatically installing NDIS filter driver RRS feed

  • Question

  • I am trying to write C++ code programmatically installing NDIS 6.0 lightweight filter driver. After reviewing WinDDK, online examples and MSDN documentation I ended up with the code sample below. (Error handling is omitted for clarity) The problem is that INetCfgClassSetup::Install always returns error 0x8004a024. (I could not find the error code in header files.)

    Manual installation of the driver using the same .inf file works just fine.

    The Bindview sample from WinDDK installs the driver just fine as long as it takes the path calling INetCfgClassSetup::SelectAndInstall. The alternative path using INetCfgClassSetup::Install does not work.

    Kernel debugging is enabled on my machine so driver signing is not required.

    Is anything missing in the code below?

    Thanks.

    ....
    isCopied = SetupCopyOEMInfA(pathToInf, // path to inf file
                                pathToBin, // dir containing driver binary
                                SPOST_PATH,
                                0,
                                DestinationInfFileName,
                                256,
                                NULL,
                                NULL);
    ....
    INetCfg      *pnc = NULL;
    INetCfgClassSetup   *pncClassSetup = NULL;
    HRESULT      hr;
    OBO_TOKEN           OboToken;
    ....
    hr = CoCreateInstance( CLSID_CNetCfg,
                           NULL, CLSCTX_INPROC_SERVER,
                           IID_INetCfg,
                           (void**)&pnc );
    ....
    hr = pnc->QueryNetCfgClass ( &GUID_DEVCLASS_NETSERVICE,
                                 IID_INetCfgClassSetup,
                                 (void**)&pncClassSetup );
    ....
    ZeroMemory( &OboToken, sizeof(OboToken) );
    OboToken.Type = OBO_USER;
    //
    // this call fails:
    hr = pncClassSetup->Install(COMPONENT_ID,
                                &OboToken,
                                0,
                                0,
                                0,
                                0,
                                NULL);

    Anatoliy Glagolev

    Thursday, April 26, 2012 2:46 AM

Answers

  • Hi,

    Error 0x8004a024 is NETCFG_E_NO_WRITE_LOCK. Your code is missing INetCfgLock::AcquireWriteLock() function before pnc->QueryNetCfgClass().

    -- Antti

    Thursday, April 26, 2012 5:46 AM
  • It turned out I was using a wrong GUID in QueryNetCfgClass (GUID_DEVCLASS_NETTRANS instead of GUID_DEVCLASS_NETSERVICE). With the right GUID everything works fine.

    Anatoliy Glagolev

    Saturday, April 28, 2012 2:12 AM

All replies

  • did you look at the pnp setup logs? what os and architecture is this on?

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Thursday, April 26, 2012 4:38 AM
  • Hi,

    Error 0x8004a024 is NETCFG_E_NO_WRITE_LOCK. Your code is missing INetCfgLock::AcquireWriteLock() function before pnc->QueryNetCfgClass().

    -- Antti

    Thursday, April 26, 2012 5:46 AM
  • With the lock acquired the error code changes. It becomes 0x800F0203 .

    Anatoliy Glagolev

    Thursday, April 26, 2012 9:45 PM
  • Not sure what pnp setup logs are. I found a log at c:\windows\inf\setupapi.dev.log keeping records on each SetupCopyOEMInfA invokation. It looks as SetupCopyOEMInf completes just fine.

    The platform is Windows Server 2008 R2 (x64).


    Anatoliy Glagolev

    Thursday, April 26, 2012 9:51 PM
  • With the lock acquired the error code changes. It becomes 0x800F0203

    New error is "There is no driver selected for the device information set or element". Is COMPONENT_ID same as driver name in inf's NTamd64 install section?

    For the .inf installation you can check c:\Windows\Inf\setupapi.dev.log file. It is also good idea to make sure that you don't have multiple (and potentially invalid) .inf files installed for your driver.

    -- Antti

    Friday, April 27, 2012 6:41 AM
  • I think my COMPONENT_ID is OK. I am using the .inf file from WinDDK Ndis Lightweight filter example, the COMPONENT_ID is "MS_NdisLwf".

    Uninstalling all .inf files created during my past attempts did not help.

    The text in my setupapi.dev.log suggests that setup API completed successfully.


    Anatoliy Glagolev

    Friday, April 27, 2012 10:50 PM
  • It turned out I was using a wrong GUID in QueryNetCfgClass (GUID_DEVCLASS_NETTRANS instead of GUID_DEVCLASS_NETSERVICE). With the right GUID everything works fine.

    Anatoliy Glagolev

    Saturday, April 28, 2012 2:12 AM
  • I am trying to write C++ code programmatically installing NDIS 6.0 lightweight filter driver. After reviewing WinDDK, online examples and MSDN documentation I ended up with the code sample below. (Error handling is omitted for clarity) The problem is that INetCfgClassSetup::Install always returns error 0x8004a024. (I could not find the error code in header files.)

    Manual installation of the driver using the same .inf file works just fine.

    The Bindview sample from WinDDK installs the driver just fine as long as it takes the path calling INetCfgClassSetup::SelectAndInstall. The alternative path using INetCfgClassSetup::Install does not work.

    Kernel debugging is enabled on my machine so driver signing is not required.

    Is anything missing in the code below?

    Thanks.

    ....
    isCopied = SetupCopyOEMInfA(pathToInf, // path to inf file
                                pathToBin, // dir containing driver binary
                                SPOST_PATH,
                                0,
                                DestinationInfFileName,
                                256,
                                NULL,
                                NULL);
    ....
    INetCfg      *pnc = NULL;
    INetCfgClassSetup   *pncClassSetup = NULL;
    HRESULT      hr;
    OBO_TOKEN           OboToken;
    ....
    hr = CoCreateInstance( CLSID_CNetCfg,
                           NULL, CLSCTX_INPROC_SERVER,
                           IID_INetCfg,
                           (void**)&pnc );
    ....
    hr = pnc->QueryNetCfgClass ( &GUID_DEVCLASS_NETSERVICE,
                                 IID_INetCfgClassSetup,
                                 (void**)&pncClassSetup );
    ....
    ZeroMemory( &OboToken, sizeof(OboToken) );
    OboToken.Type = OBO_USER;
    //
    // this call fails:
    hr = pncClassSetup->Install(COMPONENT_ID,
                                &OboToken,
                                0,
                                0,
                                0,
                                0,
                                NULL);

    Anatoliy Glagolev

    I want to install the passthru.sys driver with the netsf.inf file.

    In my code,

    hr = pnc->QueryNetCfgClass ( &GUID_DEVCLASS_NETTRANS,
                                 IID_INetCfgClassSetup,
                                 (void**)&pncClassSetup );

    ...

    and the COMPONENT_ID is "ms_passthrump", and before installing it, I have copied the netsf_m.inf file to the c:\windows\inf\ directory, but this call

    hr = pncClassSetup->Install(COMPONENT_ID,
                                &OboToken,
                                0,
                                0,
                                0,
                                0,
                                NULL);

    always returns 0x800f0203.

    Does anybody tell me what's wrong with my code? Thanks very much!

    Tuesday, February 26, 2013 8:09 AM
  • I want to install the passthru.sys driver with the netsf.inf file.

    In my code,

    hr = pnc->QueryNetCfgClass ( &GUID_DEVCLASS_NETTRANS,
                                 IID_INetCfgClassSetup,
                                 (void**)&pncClassSetup );

    GUID_DEVCLASS_NETTRANS should be GUID_DEVCLASS_NETSERVICE

    BR, Antti

    • Proposed as answer by Carl Bao Wednesday, February 27, 2013 2:36 AM
    Tuesday, February 26, 2013 12:02 PM