programmatically installing NDIS filter driver

ⅰ亾dé卋堺 提交于 2020-01-02 09:55:12

问题


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 skipped 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 wrong with 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);

回答1:


Error code 0x8004a024 stands for NETCFG_E_NO_WRITE_LOCK. The Install function requires a write-lock so try obtaining one with INetCfg->AcquireWriteLock. Don't forget to eventually release the lock and then the interface.



来源:https://stackoverflow.com/questions/10308583/programmatically-installing-ndis-filter-driver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!