Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8377963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:48:30+00:00 2026-06-09T15:48:30+00:00

I am trying to install a driver during a windows-setup project. The first step

  • 0

I am trying to install a driver during a windows-setup project.

The first step I do is to copy the INF file and preinstall the driver.

SetupCopyOEMInf(infFile, null, 1, 0, null, 0, 0, null);

This correctly preinstalls the driver, but the device is not ready to use until a hardware rescan is done in Device Manager. I want to automate this as well. I have tried using the setupapi.dll to invoke the hardware rescan, but it was not always successful for me. Using devcon.exe rescan always forces the hardware rescan, but it is a synchronous command, and it returns before the device is finished installing. Is there any way to get a return result after the hardware scan completes and the driver is successfully installed?

Thanks,

Misha

Edit

Here is my working code:

    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;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:48:31+00:00Added an answer on June 9, 2026 at 3:48 pm

    The source for devcon is available in the WDK. It’s in the src\setup\devcon directory. The logic for the rescan command is in the cmdRescan function in cmds.cpp. It would be a simple matter to copy that logic into your own code and make sure it doesn’t return immediately.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to install driver behind the user: I've create DLL which call SetupCopyOEMInf
I am trying to write an Setup Project/Installer for a class library driver that
I'm trying to install the firebird driver for node under windows. When I try
I am trying to install a windows printer driver( OEMUNI ) provided as a
I am trying to install a Windows Installer File i.e. BAT file which consist
I am trying to install an odbc driver for vPostgres (Vmware's version for postgres)
When trying to install my 32bit service on a Windows 64bit machine my installer
I'm trying to install a linux driver for my wireless network card (D-Link DWL-G510)
I am trying to install mongodb on my local computer. I have windows 7
I am trying to install SQL Server 2008 and during the pre requisite check

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.