SetupDi系列函數


SetupDiClassGuidsFromName

WINSETUPAPI BOOL SetupDiClassGuidsFromNameA( PCSTR ClassName,

LPGUID ClassGuidList,

DWORD ClassGuidListSize,

PDWORD RequiredSize );

 

SetupDiClassGuidsFromName函數檢索與指定類名關聯的GUID。

ClassName:要檢索的GUID的類名字;

ClassGuidList:一個數組的指針,以獲得與指定類名稱關聯的GUID列表;

ClassGuidListSize:ClassGuidList列表數組中GUID的數量;

RequiredSize :提供一個指向變量的指針,該變量接收與類名關聯的guid數。如果這個數字大於ClassGuidList緩沖區的大小,那么這個數字表示為了存儲所有的guid,數組必須有多大。

返回值:

如何調用成功返回TRUE,失敗返回FALSE;

 

SetupDiGetClassDevs

WINSETUPAPI HDEVINFO SetupDiGetClassDevsW( const GUID *ClassGuid,

PCWSTR Enumerator,

HWND hwndParent,

DWORD Flags );

 

該函數返回一個設備信息集的句柄看,該設備信息集包含本地計算機所請求的設備信息元素。

 

參數:

ClassGuid:一個指向設備安裝類或設備接口類的GUID的指針;該指針是隨意的也可以為空。

Enumerator:一個指向空字符結尾的字符串,列舉如下:

  • 即插即用設備枚舉樹的ID,此ID既可以是全局唯一標識符(GUID)也可以是符號名稱。比如:“PCI”可以用於指定PCI的PnP值,符號名稱則包括像“USB”,“PCMCIA”和“SCSI”這樣的Pnp值。

  • 一個PnP設備句柄ID。當指定了一個PnP設備句柄ID時,DIGCF_DEVICEINTERFACE必須在Flag參數上被設置。

hwndParent:用於與在設備信息集中安裝設備實例相關聯的用戶界面的頂級窗口句柄。該句柄是可選的,並且可以為NULL。

Flags :  Flags是一個DWORD類型的變量,通過此參數來過濾指定的設備信息集中的設備。此參數可以是以下標志位中的一個或多個的按位或組合。

DIGCF_ALLCLASSES 
  返回所有已安裝設備的列表或所有設備接口類。

DIGCF_DEVICEINTERFACE 
  返回支持指定設備接口類的設備。如果Enumerators參數制定了設備的實例ID,那么必須在Flags參數中設置此標志位。

DIGCF_DEFAULT 
  對於指定的設備接口類,只返回與系統默認設備接口相關聯的設備(如果已設置的話)。

DIGCF_PRESENT 
  只返回當前系統中存在的(已連接)設備。

DIGCF_PROFILE 
  只返回當前硬件列表中的一部分設備。

返回值

如果調用成功,SetupDiGetClassDevs將返回一個設備信息集的句柄,該句柄包含了與所提供參數所匹配的所有設備。如果調用失敗,函數返回INVALID_HANDLE_VALUE。要進一步獲取錯誤信息,請調用GetLastError。

 

SetupDiEnumDeviceInfo 函數

WINSETUPAPI BOOL SetupDiEnumDeviceInfo( HDEVINFO DeviceInfoSet,

DWORD MemberIndex,

PSP_DEVINFO_DATA DeviceInfoData );

說明:

功能:返回一個SP_DEVINFO_DATA結構體,這個結構體是在一個設備信息集中指定的一個設備信息元素

反復的調用該函數會返回不同設備的設備信息元素。

枚舉設備信息元素,最初調用該函數時要將MemberIndex參數設置為0,然后每次調用遞增MemberIndex參數的值,直到沒有更多設備的設備信息元素返回(即

SetupDiEnumDeviceInfo函數調用失敗,使用GetLastError函數會返回ERROR_NO_MORE_ITEMS);

參數:

DeviceInfoSet:設備信息集的句柄,用於返回表示設備信息元素的PSP_DEVINFO_DATA 數據結構。

MemberIndex:要檢索的從零開始的設備信息元素。

DeviceInfoData :指向PSP_DEVINFO_DATA 數據結構的指針,用於接收關於枚舉設備信息元素的信息。調用者必須設置DeviceInfoData。

cbSize設置成sizeof(PSP_DEVINFO_DATA )。

返回值:

如果成功返回TRUE,失敗返回FALSE;

 

 

SetupDiGetDeviceRegistryProperty 函數

WINSETUPAPI BOOL SetupDiGetDeviceRegistryPropertyA( HDEVINFO DeviceInfoSet,

PSP_DEVINFO_DATA DeviceInfoData,

DWORD Property,

PDWORD PropertyRegDataType,

PBYTE PropertyBuffer,

DWORD PropertyBufferSize,

PDWORD RequiredSize );

該函數用於檢索一個指定的即插即用設備的屬性;

 

參數:

DeviceInfoSet:指向一個設備信息集的指針,表示要檢索即插即用屬性的設備。

DeviceInfoData:一個PSP_DEVINFO_DATA 結構體,指定DeviceInfoSet中的設備信息元素。

Property:以下要被檢索的指定屬性:     

SPDRP_ADDRESS

The function retrieves the device's address.

SPDRP_BUSNUMBER

The function retrieves the device's bus number.

SPDRP_BUSTYPEGUID

The function retrieves the GUID for the device's bus type.

SPDRP_CAPABILITIES

The function retrieves a bitwise OR of the following CM_DEVCAP_Xxx flags in a DWORD. The device capabilities that are represented by these flags correspond to the device capabilities that are represented by the members of the DEVICE_CAPABILITIES structure. The CM_DEVCAP_Xxx constants are defined in Cfgmgr32.h.

CM_DEVCAP_Xxx flag Corresponding DEVICE_CAPABILITIES structure member
CM_DEVCAP_LOCKSUPPORTED LockSupported
CM_DEVCAP_EJECTSUPPORTED EjectSupported
CM_DEVCAP_REMOVABLE Removable
CM_DEVCAP_DOCKDEVICE DockDevice
CM_DEVCAP_UNIQUEID UniqueID
CM_DEVCAP_SILENTINSTALL SilentInstall
CM_DEVCAP_RAWDEVICEOK RawDeviceOK
CM_DEVCAP_SURPRISEREMOVALOK SurpriseRemovalOK
CM_DEVCAP_HARDWAREDISABLED HardwareDisabled
CM_DEVCAP_NONDYNAMIC NonDynamic

 

SPDRP_CHARACTERISTICS

The function retrieves a bitwise OR of a device's characteristics flags in a DWORD. For a description of these flags, which are defined in Wdm.h and Ntddk.h, see the DeviceCharacteristics parameter of the IoCreateDevice function.

SPDRP_CLASS

The function retrieves a REG_SZ string that contains the device setup class of a device.

SPDRP_CLASSGUID

The function retrieves a REG_SZ string that contains the GUID that represents the device setup class of a device.

SPDRP_COMPATIBLEIDS

The function retrieves a REG_MULTI_SZ string that contains the list of compatible IDs for a device. For information about compatible IDs, see Device Identification Strings.

SPDRP_CONFIGFLAGS

The function retrieves a bitwise OR of a device's configuration flags in a DWORD value. The configuration flags are represented by the CONFIGFLAG_Xxx bitmasks that are defined in Regstr.h.

SPDRP_DEVICE_POWER_DATA

(Windows XP and later) The function retrieves a CM_POWER_DATA structure that contains the device's power management information.

SPDRP_DEVICEDESC

The function retrieves a REG_SZ string that contains the description of a device.

SPDRP_DEVTYPE

The function retrieves a DWORD value that represents the device's type. For more information, see Specifying Device Types.

SPDRP_DRIVER

The function retrieves a string that identifies the device's software key (sometimes called the driver key). For more information about driver keys, see Registry Trees and Keys for Devices and Drivers.

SPDRP_ENUMERATOR_NAME

The function retrieves a REG_SZ string that contains the name of the device's enumerator.

SPDRP_EXCLUSIVE

The function retrieves a DWORD value that indicates whether a user can obtain exclusive use of the device. The returned value is one if exclusive use is allowed, or zero otherwise. For more information, see IoCreateDevice.

SPDRP_FRIENDLYNAME

The function retrieves a REG_SZ string that contains the friendly name of a device.

SPDRP_HARDWAREID

The function retrieves a REG_MULTI_SZ string that contains the list of hardware IDs for a device. For information about hardware IDs, see Device Identification Strings.

SPDRP_INSTALL_STATE

(Windows XP and later) The function retrieves a DWORD value that indicates the installation state of a device. The installation state is represented by one of the CM_INSTALL_STATE_Xxxvalues that are defined in Cfgmgr32.h. The CM_INSTALL_STATE_Xxx values correspond to the DEVICE_INSTALL_STATE enumeration values.

SPDRP_LEGACYBUSTYPE

The function retrieves the device's legacy bus type as an INTERFACE_TYPE value (defined in Wdm.h and Ntddk.h).

SPDRP_LOCATION_INFORMATION

The function retrieves a REG_SZ string that contains the hardware location of a device.

SPDRP_LOCATION_PATHS

(Windows Server 2003 and later) The function retrieves a REG_MULTI_SZ string that represents the location of the device in the device tree.

SPDRP_LOWERFILTERS

The function retrieves a REG_MULTI_SZ string that contains the names of a device's lower-filter drivers.

SPDRP_MFG

The function retrieves a REG_SZ string that contains the name of the device manufacturer.

SPDRP_PHYSICAL_DEVICE_OBJECT_NAME

The function retrieves a REG_SZ string that contains the name that is associated with the device's PDO. For more information, see IoCreateDevice.

SPDRP_REMOVAL_POLICY

(Windows XP and later) The function retrieves the device's current removal policy as a DWORD that contains one of the CM_REMOVAL_POLICY_Xxx values that are defined in Cfgmgr32.h.

SPDRP_REMOVAL_POLICY_HW_DEFAULT

(Windows XP and later) The function retrieves the device's hardware-specified default removal policy as a DWORD that contains one of the CM_REMOVAL_POLICY_Xxx values that are defined in Cfgmgr32.h.

SPDRP_REMOVAL_POLICY_OVERRIDE

(Windows XP and later) The function retrieves the device's override removal policy (if it exists) from the registry, as a DWORD that contains one of the CM_REMOVAL_POLICY_Xxx values that are defined in Cfgmgr32.h.

SPDRP_SECURITY

The function retrieves a SECURITY_DESCRIPTOR structure for a device.

SPDRP_SECURITY_SDS

The function retrieves a REG_SZ string that contains the device's security descriptor. For information about security descriptor strings, see Security Descriptor Definition Language (Windows). For information about the format of security descriptor strings, see Security Descriptor Definition Language (Windows).

SPDRP_SERVICE

The function retrieves a REG_SZ string that contains the service name for a device.

SPDRP_UI_NUMBER

The function retrieves a DWORD value set to the value of the UINumber member of the device's DEVICE_CAPABILITIES structure.

SPDRP_UI_NUMBER_DESC_FORMAT

The function retrieves a format string (REG_SZ) used to display the UINumber value.

SPDRP_UPPERFILTERS

The function retrieves a REG_MULTI_SZ string that contains the names of a device's upper filter drivers.

 

PropertyRegDataType:指向一個變量的指針,該變量接收正在檢索的屬性的數據類型。這是標准注冊表數據類型之一。此參數是可選的,可以為空。

PropertyBuffer:一個指向緩沖區的指針,該緩沖區接收要檢索的屬性。如果將該參數設置為NULL,並將PropertyBufferSize設置為0,則函數將在RequiredSize中返回                              緩沖區所需的大小。

PropertyBufferSize:屬性緩沖區大小;

RequiredSize:指向類型為DWORD的變量的指針,該變量接收PropertyBuffer緩沖區所需大小(以字節為單位),該緩沖區用於保存所請求屬性的數據。此參數是可選                             的,可以為空

返回值:

如果調用成功返回TRUE,失敗返回FALSE;

 

SetupDiOpenDevRegKey

WINSETUPAPI HKEY SetupDiOpenDevRegKey( HDEVINFO DeviceInfoSet,

PSP_DEVINFO_DATA DeviceInfoData,

DWORD Scope,

DWORD HwProfile,

DWORD KeyType,

REGSAM samDesired );

 

SetupDiOpenDevRegKey函數為特定設備的配置信息打開注冊表項。

 

參數:

DeviceInfoSet:設備信息集的句柄,該句柄包含一個設備信息元素,該元素表示要為其打開注冊表項的設備。

DeviceInfoData:一個指向SP DEVINFO數據結構的指針,該結構指定DeviceInfoSet中的設備信息元素。

Scope:要打開的注冊表項的范圍。范圍決定信息存儲在何處。范圍可以是全局的,也可以是特定於硬件配置文件的。范圍由下列值之一指定:    

DICS_FLAG_GLOBAL

打開存儲全局配置信息的鍵值項。此信息並不特定於特定的硬件配置文件。這將打開一個根在 HKEY_LOCAL_MACHINE。打開的確切鍵取決於KeyType的值。

DICS_FLAG_CONFIGSPECIFIC

打開存儲特定於硬件概要文件的配置信息的鍵值項。此鍵根植於硬件配置文件特定的分支之一,而不是HKEY_LOCAL_MACHINE。打開的確切鍵取決於KeyType的值。

HwProfile:硬件配置文件值,設置如下:

  • If Scope is set to DICS_FLAG_CONFIGSPECIFIC, HwProfile specifies the hardware profile of the key that is to be opened.
  • If HwProfile is 0, the key for the current hardware profile is opened.
  • If Scope is DICS_FLAG_GLOBAL, HwProfile is ignored.

  (如果HwProfile為0,打開當前硬件配置文件的鍵。)

KeyType:要打開的注冊表存儲鍵的類型,可以是以下值之一:

DIREG_DEV

Open a hardware key for the device.

DIREG_DRV

Open a software key for the device.

For more information about a device's hardware and software keys, see Registry Trees and Keys for Devices and Drivers.

samDesired:請求的鍵值項所需的注冊表安全訪問。

    

返回值:

如果函數成功,它將返回打開的注冊表項的句柄,其中可以存儲/檢索關於此設備實例的私有配置數據。

如果失敗返回INVALID_HANDLE_VALUE。

 

 

RegQueryValueEx(E)函數

函數RegQueryValueEx找回一個打開的注冊表鍵值相關聯的給定的變量數據或者變量。
LONG RegQueryValueEx(
  HKEY hKey,            // handle to key  主鍵句柄
  LPCTSTR lpValueName,  // value name     子鍵名稱
  LPDWORD lpReserved,   // reserved      保留
  LPDWORD lpType,       // type buffer  
  LPBYTE lpData,        // data buffer   存儲返回值的緩沖區
  LPDWORD lpcbData      // size of data buffer存儲返回值的緩沖區的大小
);
---------------------
作者:ju_feng
來源:CSDN
原文:https://blog.csdn.net/ju_feng/article/details/6459
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM