有没有办法使用.NET触发硬件刷新(也就是设备管理器)?

时间:2009-09-22 08:54:57

标签: .net api hardware device-manager

我不介意它是否只能在最新版本的Windows中使用,但我想知道是否有办法使用.NET触发它:

Device Manager Hardware Refresh http://imgbag.com/josh/joshx/StackOverflow/devicemanager.png?p=Rectangle(130,430,270,100,10,Yellow)

1 个答案:

答案 0 :(得分:2)

发现这段代码可以帮助您指明正确的方向。您需要将windows api添加到项目中并模仿:

#INCLUDE "Win32Api.inc"
DECLARE FUNCTION fCM_Locate_DevNode (BYREF dvInst AS LONG, BYVAL n AS LONG, BYVAL c AS LONG) AS LONG
DECLARE FUNCTION fCM_Reenumerate_DevNode (BYVAL dvInst AS LONG, BYVAL n AS LONG) AS LONG

FUNCTION Scan_for_hardware_changes () AS LONG

    %CR_SUCCESS = 0
    %CM_LOCATE_DEVNODE_NORMAL = 0

    LOCAL hLib AS LONG, pCM_DevNode AS DWORD, fSTATUS AS LONG, dvInst AS LONG

    hLib = LoadLibrary( "cfgmgr32.dll" )
    IF hLib THEN
        pCM_DevNode = GetProcAddress( hLib, "CM_Locate_DevNodeA" )
        IF pCM_DevNode THEN
            CALL DWORD pCM_DevNode USING fCM_Locate_DevNode(dvInst, 0, %CM_LOCATE_DEVNODE_NORMAL ) TO fSTATUS
            IF fSTATUS=%CR_SUCCESS THEN
                pCM_DevNode = GetProcAddress( hLib, "CM_Reenumerate_DevNode" )
                IF pCM_DevNode THEN
                    CALL DWORD pCM_DevNode USING fCM_Reenumerate_DevNode(dvInst, 0 ) TO fSTATUS
                    IF fSTATUS=%CR_SUCCESS THEN FUNCTION=%TRUE
                END IF
            END IF
        END IF
        FreeLibrary hLib
    END IF

END FUNCTION

FUNCTION PBMAIN

  IF Scan_for_hardware_changes() THEN MSGBOX "OK!" ELSE MSGBOX "Sorry!"

END FUNCTION