.nethardwaredevice-manager

Is there a way to trigger a hardware refresh (aka Device Manager) using .NET?


Is there a way to trigger a hardware refresh (aka Device Manager) using .NET?

I don't mind if it's only possible in the latest version of Windows, but I am wondering if there is a way to trigger this using .NET:

Device Manager Hardware Refresh


Solution

  • found this piece of code which could help to point you in the right direction. You will need to add the windows api to your project and mimic this:

    #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