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); }
調用方法:api
int pdnDevInst = 0;
Win32Api.CM_Locate_DevNodeA(ref pdnDevInst, null, Win32Api.CM_LOCATE_DEVNODE_NORMAL); Win32Api.CM_Reenumerate_DevNode(pdnDevInst, Win32Api.CM_REENUMERATE_NORMAL);
參考連接:spa