使用 netcfg 删除 NDIS LWF 不会将其从驱动程序存储中删除?

Using netcfg to remove an NDIS LWF doesn't remove it from the driver store?

当我尝试使用 netcfg -u 删除我的 NDIS LWF 时,我注意到它没有从驱动程序存储中删除它(可以通过 pnputil /enum-drivers 查看)。

这会导致问题,因为在某些 Windows 10 台机器上,如果我们卸载以前版本的 NDIS LWF 并使用 netcfg 安装新版本,由于某种未知原因,旧的 inf 是还是用来安装吧!我假设它是因为 inf 仍然具有相同的 componentID?我们正在更新 INF 文件,以便附加到我们以前无法附加的一些虚拟适配器。请注意,这不会发生在 Windows 7 中,我们可以毫无问题地安装新的。

所以我的问题是:

  1. 当我们尝试安装具有不同 INF 的新更新驱动程序时,为什么 Windows 仍在使用驱动程序商店中以前的 INF?

  2. 完全删除以前的 NDIS LWF(包括从驱动程序存储中删除)的正确方法是什么?如果我们需要使用 pnputil 将其从驱动程序存储中完全删除,那么考虑到 pnputil -d 需要 OEM 编号,找到 OEM 编号的正确方法是什么?

是的,如您所见,netcfg.exe -inetcfg.exe -u 并不完全相反。

安装执行以下步骤:

  1. -l 提供的 INF 安装到 driver 商店 (SetupCopyOEMInf)

  2. 致电INetCfgClassSetup::Install至:

    1. 在 PNP 中查询您提供的 componentId 的“最佳匹配”-iSetupDiBuildDriverInfoListSetupDiSelectBestCompatDrv
    2. 运行 INF 中的所有部分(AddRegAddService 等)
    3. 使用 Ndi 注册表项中的信息向系统注册 LWF/Protocol/TDI driver

卸载执行以下步骤:

  1. 致电 INetCfgComponent::DeInstall 以:
    1. 注销您的 LWF/Protocol/TDI driver 系统
    2. 运行 INF 的特殊 .Remove section(希望它包含 DelRegDelService 以撤消在安装步骤 #2.2 期间完成的所有操作)

(上面的描述忽略了 driver refcount 系统(又名 OBO_TOKEN),因为它不经常使用 — 大多数 driver 只使用一个 refcount。如果你专门使用 netcfg.exe 来管理您的 driver,那么您也可以忽略引用计数。)

您可能想知道:为什么这么 less-than-awesome?这里的背景故事是 netcfg.exe 从来没有真正打算成为第 3 方软件管理其 driver 的 general-purpose 工具。它仅供内部使用,用于 OS 中内置的 driver(ms_tcpip 等)。假设第 3 方 driver 安装程序想要调用适当的 API,如 INetCfg,而不是 CreateProcess 一些可执行文件和 screen-scrape 输出。所以 netcfg.exe 只是为了满足我们内部需求的最低要求而建立的。特别是很少有人关注卸载,因为 built-in driver 很少被卸载。 (同样,参数解析不灵活,帮助文本没有帮助,错误处理也不健壮。)

从Windows 10开始,built-in driver不再使用netcfg.exe安装,所以OS本身不需要netcfg.exe 完全没有了。但到那时,第 3 方产品已经发现它并依赖它,所以我们不能再删除 netcfg.exe。嗯嗯

Why is Windows still using the previous INF from driver store when we try to install the new updated driver that has a different INF?

这是一个常见问题。请注意,在安装期间,步骤#1 和#2 之间没有关联。您可以同时安装打印机 INF 和 LWF — netcfg.exe -l foo.inf -i bar 不做任何努力来确保在步骤 #2.2 中选择的“最佳”组件实际上来自在步骤 #1 安装的 INF。

为了保证你想要的driver是“最好的”driver,你要保证你看好的driver胜出the PNP driver selection algorithm。我个人一直被这个困扰,因为我在开发迭代期间没有碰到 DriverVer 行。确保每次 更改 driver.

时增加 DriverVer

What is the proper way to fully remove the previous NDIS LWF, including from driver store? If we need to use pnputil to fully remove it from driver store, then what is the proper way of finding the OEM number, considering that pnputil -d requires an OEM number?

老实说,如果您想真正正确地做每件事,我建议完全避免 netcfg.exe。请改用底层 INetCfg API。那么您的安装程序将必须管理 driver (SetupCopyOEMInf / SetupUninstallOEMInf).

您放弃 netcfg.exe 并自己致电 INetCfg 并不会损失太多。 netcfg.exe 没有对 INetCfg 做任何特别花哨的事情:它自己的实现几乎完全取自 this sample code。如果您从那里开始并在顶部调用 SetupCopyOEMInf,您将几乎与 netcfg.exe 持平。从那里,您可以通过更强大的 INF 卸载来改进它。您甚至可以编写一些代码来使用您的 componentId 清点所有 INF,以确保没有隐藏的 INF 的陈旧副本。

您仍然需要实现信任的飞跃,从安装 INF 到希望 INetCfgClassSetup::Install 认为您的 recently-installed INF 是“最佳”INF。但是,如果您删除了每个 other INF 与该 componentId,那么您可以确定唯一剩余的 INF 必须是最佳匹配。