Installation 在重新扫描后,DevCon是否可以在驱动程序安装完成时发出通知?

Installation 在重新扫描后,DevCon是否可以在驱动程序安装完成时发出通知?,installation,driver,wdk,inf,device-manager,Installation,Driver,Wdk,Inf,Device Manager,我试图在windows安装项目期间安装驱动程序 我做的第一步是复制INF文件并预安装驱动程序 SetupCopyOEMInfinfFile,null,1,0,null,0,0,null 这将正确地预安装驱动程序,但在设备管理器中完成硬件重新扫描之前,设备尚未准备好使用。我还想让它自动化。我试过使用,但对我来说并不总是成功。使用devcon.exe rescan总是强制硬件重新扫描,但它是一个同步命令,并且在设备安装完成之前返回。在硬件扫描完成并成功安装驱动程序后,是否有方法获得返回结果 谢谢 米

我试图在windows安装项目期间安装驱动程序

我做的第一步是复制INF文件并预安装驱动程序

SetupCopyOEMInfinfFile,null,1,0,null,0,0,null

这将正确地预安装驱动程序,但在设备管理器中完成硬件重新扫描之前,设备尚未准备好使用。我还想让它自动化。我试过使用,但对我来说并不总是成功。使用devcon.exe rescan总是强制硬件重新扫描,但它是一个同步命令,并且在设备安装完成之前返回。在硬件扫描完成并成功安装驱动程序后,是否有方法获得返回结果

谢谢

米沙

编辑

这是我的工作代码:

    public const UInt32 CR_SUCCESS = 0;
    public const UInt64 CM_REENUMERATE_SYNCHRONOUS = 1;
    public const UInt64 CM_LOCATE_DEVNODE_NORMAL = 0;

    [DllImport("setupapi.dll")]
    public static extern bool SetupCopyOEMInf(
      string SourceInfFileName,
      string OEMSourceMediaLocation,
      int OEMSourceMediaType,
      int CopyStyle,
      string DestinationInfFileName,
      int DestinationInfFileNameSize,
      int RequiredSize,
      string DestinationInfFileNameComponent
      );

    [DllImport("cfgmgr32.dll")]
    public static extern int CM_Locate_DevNode_Ex(ref IntPtr deviceHandle, int deviceId, uint flags, IntPtr machineHandle);

    [DllImport("cfgmgr32.dll")]
    public static extern int CM_Reenumerate_DevNode_Ex(IntPtr devInst, UInt64 flags);

    [DllImport("cfgmgr32.dll")]
    public static extern int CMP_WaitNoPendingInstallEvents(UInt32 timeOut);

    static void Main() {
      bool success = SetupCopyOEMInf(infFile, null, 1, 0, null, 0, 0, null);

      if(!success) {
        throw new Exception("Error installing driver");
      }

      success = RescanAllDevices();

      if (!success) {
        throw new Exception("Error installing driver");
      }
    }

    public static bool RescanAllDevices() {
      int ResultCode = 0;
      IntPtr LocalMachineInstance = IntPtr.Zero;
      IntPtr DeviceInstance = IntPtr.Zero;
      UInt32 PendingTime = 30000;

      ResultCode = CM_Locate_DevNode_Ex(ref DeviceInstance, 0, 0, LocalMachineInstance);
      if (CR_SUCCESS == ResultCode) {
        ResultCode = CM_Reenumerate_DevNode_Ex(DeviceInstance, CM_REENUMERATE_SYNCHRONOUS);
        ResultCode = CMP_WaitNoPendingInstallEvents(PendingTime);
      }
      return ResultCode == CR_SUCCESS;
    }

devcon的源代码在WDK中可用。它位于src\setup\devcon目录中。rescan命令的逻辑位于cmds.cpp中的cmdRescan函数中。将该逻辑复制到您自己的代码中并确保它不会立即返回将是一件简单的事情。

devcon的源代码在WDK中可用。它位于src\setup\devcon目录中。rescan命令的逻辑位于cmds.cpp中的cmdRescan函数中。将该逻辑复制到您自己的代码中,并确保它不会立即返回,这将是一件简单的事情。

谢谢您的代码!但是,如果之前驱动程序安装失败并且安装了虚拟驱动程序,则只有重新启动系统才能安装新的驱动程序。因此,重启似乎是最安全的方法。请参阅代码谢谢!但是,如果之前驱动程序安装失败并且安装了虚拟驱动程序,则只有重新启动系统才能安装新的驱动程序。因此,重启似乎是最安全的方法。请参阅Devcon无法解决此问题:它使用异步rescan@ColinJensen除了第一句,你没有读我的答案,是吗?我说过源代码是可用的,并且可以很容易地修改为同步的rescan@ColinJensen除了第一句,你没有读我的答案,是吗?我说源代码是可用的,可以很容易地修改为同步的。