我不介意它是否只能在最新版本的Windows中使用,但我想知道是否有办法使用.NET触发它:
答案 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