先发个部分的,全的再去找<br>//--------------------------------------------------------------------<br>//<br>// SetupDI.pas<br>//<br>//--------------------------------------------------------------------<br>unit SetupDI;<br><br>interface<br><br>uses<br> Windows, Dialogs, SysUtils;<br><br>// GUID<br> type<br> P_GUID_ = ^_GUID_;<br> _GUID_ = record<br> Data1: DWord;<br> Data2: word;<br> Data3: word;<br> Data4: array [0..7] of Byte;<br> end;<br><br>// 側丄挿偄....柤慜....<br>// SP_DEVICE_INTERFACE_DETAIL_DATA_A, *PSP_DEVICE_INTERFACE_DETAIL_DATA_A;<br> type<br> P_SP_INTERF_DETAIL_ = ^_SP_INTERF_DETAIL_;<br> _SP_INTERF_DETAIL_ = packed record<br> cbSize: DWord;<br> DevPath: char; // 側傫偱億僀儞僞偱側偄偺丠<br> end;<br><br>// 偙傟傑偨...<br>// SP_DEVICE_INTERFACE_DATA, *PSP_DEVICE_INTERFACE_DATA;<br> type<br> P_SP_INTERF_ = ^_SP_INTERF_;<br> _SP_INTERF_ = record<br> cbSize: DWord;<br> Guid: _GUID_;<br> Flags: DWord;<br> Reserve: Pointer;<br> end;<br><br><br>// 偙傟偼宆偺愰尵偩偗偱偡丅<br>// SP_DEVINFO_DATA, *PSP_DEVINFO_DATA;<br> type<br> P_SP_INFO_ = ^_SP_INFO_;<br> _SP_INFO_ = record<br> cbSize: DWord;<br> Guid: _GUID_;<br> DevInst: DWord;<br> Reserve: DWord;<br> end;<br><br><br>type<br> TSetupDI = class( TObject )<br> private<br> public<br> constructor Create;<br> function GetPathName( const pGuid: P_GUID_; var PathName: array of char ): bool;<br> end;<br><br>implementation<br><br>//<br>// 巊梡偡傞娭悢孮偺愰尵 SetupApi.DLL 撪偵懚嵼<br>//<br>function SetupDiGetClassDevsA( Guid: P_GUID_; Enumrator: PChar; hPar: THANDLE; Flags: DWord ):<br> THANDLE; stdcall; external 'SETUPAPI.DLL';<br>function SetupDiEnumDeviceInterfaces( DevInfo: THANDLE; InfoData: P_SP_INFO_;<br> Guid: P_GUID_; Index: DWord; DevInterfD: P_SP_INTERF_ ):<br> bool; stdcall; external 'SETUPAPI.DLL';<br>function SetupDiDestroyDeviceInfoList( hPar: THANDLE ): bool; stdcall; external 'SETUPAPI.DLL';<br>function SetupDiGetDeviceInterfaceDetailA( DevInfo: THANDLE; InterData: P_SP_INTERF_;<br> InfoDetail: P_SP_INTERF_DETAIL_; DetailSize: DWord; ReqSize: PDWord;<br> InfoData: P_SP_INFO_ ): bool; stdcall; external 'SETUPAPI.DLL';<br><br><br>// use SetupDiGetClassDevsA<br>const DIGCF_DEFAULT = $001;<br>const DIGCF_PRESENT = $002;<br>const DIGCF_ALLCLASSES = $004;<br>const DIGCF_PROFILE = $008;<br>const DIGCF_DEVICEINTERFACE = $010;<br><br>//--------------------------------------------<br>// Constructor<br>//--------------------------------------------<br>constructor TSetupDI.Create;<br>begin<br> inherited Create;<br>end;<br><br>//--------------------------------------------<br>// GetPathName<br>//--------------------------------------------<br>function TSetupDI.GetPathName( const pGuid: P_GUID_; var PathName: array of char ): bool;<br>var<br> hDevInfo: THANDLE;<br> func_dev: P_SP_INTERF_DETAIL_;<br> devInfo_Data: _SP_INTERF_;<br> predi_len: DWord;<br> req_len: DWord;<br> retb: bool;<br>begin<br><br> //<br> // 埲壓偺娭悢孮偺徻偟偄摦嶌偵偮偄偰偼晄柧丅<br> // 偦偺偆偪嶨帍偵偰夝愢偝傟傞偲巚偄傑偡丅....<br> //<br> hDevInfo := SetupDiGetClassDevsA(<br> pGuid,<br> nil,<br> 0,<br> DIGCF_PRESENT or<br> DIGCF_DEVICEINTERFACE );<br><br> if INVALID_HANDLE_VALUE = hDevInfo then<br> begin<br> MessageDlg('SetupDiGetClassDevsA 幐攕', mtWarning,[mbYes], 0);<br> Result := False;<br> exit;<br> end;<br><br> devInfo_Data.cbSize := sizeof(_SP_INTERF_);<br> retb := SetupDiEnumDeviceInterfaces(<br> hDevInfo,<br> nil,<br> pGuid,<br> 0,<br> @devInfo_Data );<br> if not retb then<br> begin<br> SetupDiDestroyDeviceInfoList( hDevInfo );<br> MessageDlg('SetupDiEnumDeviceInterfaces 幐攕', mtWarning,[mbYes], 0);<br> Result := False;<br> exit;<br> end;<br><br> //<br> // 偙偺 bool 娭悢偼忢偵 False 偑曉傞丅 擂?..<br> //<br> SetupDiGetDeviceInterfaceDetailA(<br> hDevInfo,<br> @devInfo_Data,<br> nil,<br> 0,<br> @req_len,<br> nil );<br><br> predi_len := req_len;<br> try<br> GetMem( func_dev, predi_len );<br> except<br> MessageDlg('Memory 晄懌', mtWarning,[mbYes], 0);<br> SetupDiDestroyDeviceInfoList( hDevInfo );<br> Result := False;<br> exit;<br> end;<br><br> func_dev.cbSize := sizeof( _SP_INTERF_DETAIL_ );<br> retb := SetupDiGetDeviceInterfaceDetailA(<br> hDevInfo,<br> @devInfo_Data,<br> func_dev,<br> predi_len,<br> @req_len,<br> nil );<br><br> if not retb then<br> begin<br> FreeMem( func_dev );<br> SetupDiDestroyDeviceInfoList( hDevInfo );<br> MessageDlg('SetupDiGetDeviceInterfaceDetailA 幐攕', mtWarning,[mbYes], 0);<br> Result := False;<br> exit;<br> end;<br><br> // 僪儔僀僶偺 PathName 偑曉傞丅<br> StrCopy( PathName, @func_dev.DevPath );<br><br> retb := SetupDiDestroyDeviceInfoList( hDevInfo );<br> if not retb then<br> begin<br> FreeMem( func_dev );<br> MessageDlg('SetupDiDestroyDeviceInfoList 幐攕', mtWarning,[mbYes], 0);<br> Result := False;<br> exit;<br> end;<br><br> FreeMem( func_dev );<br> Result := True;<br>end;<br><br>end.