c#实现"扫描检测硬件改动"

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);
}

  

调用方法:

int pdnDevInst = 0;
Win32Api.CM_Locate_DevNodeA(ref pdnDevInst, null, Win32Api.CM_LOCATE_DEVNODE_NORMAL); Win32Api.CM_Reenumerate_DevNode(pdnDevInst, Win32Api.CM_REENUMERATE_NORMAL);

 

 

参考链接:

https://stackoverflow.com/questions/2181525/is-there-an-api-call-to-start-a-scan-for-hardware-devices

posted @ 2019-05-26 10:32  sherlock-merlin  阅读(810)  评论(0编辑  收藏  举报