Not sure if this will help your overall problem but this should answer the question in your first sentence.
I originally did something like this using Nullsoft's NSIS installer a few years ago.
If you just want to trigger a vanilla hardware scan you can use the following code (provided in C# per the .net tag in this question):
This is the wrapper class for the P/Invoke functions
public static class Win32Api
{
public const int CM_LOCATE_DEVNODE_NORMAL = 0x00000000;
public const int CM_REENUMERATE_NORMAL = 0x00000000;
public const int CR_SUCCESS = 0x00000000;
[DllImport("CfgMgr32.dll", SetLastError=true)]
public static extern int CM_Locate_DevNodeA(ref int pdnDevInst, string pDeviceID, int ulFlags);
[DllImport("CfgMgr32.dll", SetLastError=true)]
public static extern int CM_Reenumerate_DevNode(int dnDevInst, int ulFlags);
}
This is a sample of how to use them
int pdnDevInst = 0;
if (Win32Api.CM_Locate_DevNodeA(ref pdnDevInst, null, Win32Api.CM_LOCATE_DEVNODE_NORMAL) != Win32Api.CR_SUCCESS)
throw new Exception("something...");
if (Win32Api.CM_Reenumerate_DevNode(pdnDevInst, Win32Api.CM_REENUMERATE_NORMAL) != Win32Api.CR_SUCCESS)
throw new Exception("something else...");
I just quickly translated this from the MSDN C++ docs and tested it in a spike so I know it works but it's not production quality. Also, if you care about the specific return codes you can look them up in cfgmgr32.h.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…