0

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

设备管理器硬件刷新 http://imgbag.com/josh/joshx/StackOverflow/devicemanager.png?p=Rectangle(130,430,270,100,10,Yellow)

4

1 回答 1

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   
于 2009-09-22T09:00:30.527 回答