Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than setupapi, prefix the name with the module name and a period.
/// <summary>
/// The SetupDiGetDeviceRegistryProperty function retrieves the specified device property.
/// This handle is typically returned by the SetupDiGetClassDevs or SetupDiGetClassDevsEx function.
/// </summary>
/// <param Name="DeviceInfoSet">Handle to the device information set that contains the interface and its underlying device.</param>
/// <param Name="DeviceInfoData">Pointer to an SP_DEVINFO_DATA structure that defines the device instance.</param>
/// <param Name="Property">Device property to be retrieved. SEE MSDN</param>
/// <param Name="PropertyRegDataType">Pointer to a variable that receives the registry data Type. This parameter can be NULL.</param>
/// <param Name="PropertyBuffer">Pointer to a buffer that receives the requested device property.</param>
/// <param Name="PropertyBufferSize">Size of the buffer, in bytes.</param>
/// <param Name="RequiredSize">Pointer to a variable that receives the required buffer size, in bytes. This parameter can be NULL.</param>
/// <returns>If the function succeeds, the return value is nonzero.</returns>
[DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool SetupDiGetDeviceRegistryProperty(
IntPtr deviceInfoSet,
ref SP_DEVINFO_DATA deviceInfoData,
uint property,
out UInt32 propertyRegDataType,
byte[] propertyBuffer,
uint propertyBufferSize,
out UInt32 requiredSize
IntPtr DeviceInfoSet,
ref SP_DEVINFO_DATA DeviceInfoData,
uint Property,
out UInt32 PropertyRegDataType,
byte[] PropertyBuffer,
uint PropertyBufferSize,
out UInt32 RequiredSize
);
Alternate C# Signature:
[DllImport("setupapi.dll", SetLastError = true)]
public static extern bool SetupDiGetDeviceRegistryProperty(
IntPtr deviceInfoSet,
ref SP_DEVINFO_DATA deviceInfoData,
uint property,
out UInt32 propertyRegDataType,
IntPtr propertyBuffer, // the difference between this signature and the one above.
uint propertyBufferSize,
out UInt32 requiredSize
IntPtr DeviceInfoSet,
ref SP_DEVINFO_DATA DeviceInfoData,
uint Property,
out UInt32 PropertyRegDataType,
IntPtr PropertyBuffer, // the difference between this signature and the one above.
uint PropertyBufferSize,
out UInt32 RequiredSize
);
Parameters:
deviceInfoSet, Handle to the device information set that contains the interface and its underlying device
deviceInfoData, Pointer to an SP_DEVINFO_DATA structure that defines the device instance.
property, Device property to be retrieved. SEE MSDN.
propertyRegDataType, Pointer to a variable that receives the registry data Type. This parameter can be NULL.</param>
propertyBuffer, Pointer to a buffer that receives the requested device property.</param>
propertyBufferSize, Size of the buffer, in bytes.</param>
requiredSize, Pointer to a variable that receives the required buffer size, in bytes. This parameter can be NULL.</param>
VB Signature:
<DllImport("setupapi.dll", SetLastError:=True)> _
Public Shared Function SetupDiGetDeviceRegistryProperty( _
ByVal DeviceInfoSet As Integer, _
ByRef DeviceInfoData As SP_DEVINFO_DATA, _
ByVal [Property] As Integer, _
ByRef PropertyRegDataType As Integer, _
ByVal PropertyBuffer As Byte(), _
ByVal PropertyBufferSize As Integer, _
ByRef RequiredSize As Integer) As Boolean
End Function
/// <summary>
/// Flags for SetupDiGetDeviceRegistryProperty().
/// The SP_DEVINFO_DATA structure defines a device instance that is a member of a device information set.
/// </summary>
enum SetupDiGetDeviceRegistryPropertyEnum : uint
public struct SP_DEVINFO_DATA
{
/// <summary>Size of the structure, in bytes.</summary>
public uint cbSize;
/// <summary>GUID of the device interface class.</summary>
public Guid ClassGuid;
/// <summary>Handle to this device instance.</summary>
public uint DevInst;
/// <summary>Reserved; do not use.</summary>
public IntPtr Reserved;
}
// We start at the "root" of the device tree and look for all
// devices that match the interface GUID of a disk
IntPtr h = SetupDiGetClassDevs(ref DiskGUID, 0, IntPtr.Zero, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if (h.ToInt32() != INVALID_HANDLE_VALUE)
{
bool Success = true;
int i = 0;
while (Success)
{
// create a Device Interface Data structure
SP_DEVICE_INTERFACE_DATA dia = new SP_DEVICE_INTERFACE_DATA();
dia.cbSize = Marshal.SizeOf(dia);
// start the enumeration
Success = SetupDiEnumDeviceInterfaces(h, IntPtr.Zero, ref DiskGUID, i, ref dia);
if (Success)
{
// build a DevInfo Data structure
SP_DEVINFO_DATA da = new SP_DEVINFO_DATA();
da.cbSize = Marshal.SizeOf(da);
// build a Device Interface Detail Data structure
SP_DEVICE_INTERFACE_DETAIL_DATA didd = new SP_DEVICE_INTERFACE_DETAIL_DATA();
didd.cbSize = 4 + Marshal.SystemDefaultCharSize; // trust me :)
// now we can get some more detailed information
int nRequiredSize = 0;
int nBytes = BUFFER_SIZE;
if (SetupDiGetDeviceInterfaceDetail(h, ref dia, ref didd, nBytes, ref nRequiredSize, ref da))
{
// get the Device Description and DriverKeyName
Uint32 RequiredSize;
Uint32 RegType;
byte[] buffer = new byte[BUFFER_SIZE];
byte[] ptrBuf = new byte[BUFFER_SIZE];
if (SetupDiGetDeviceRegistryProperty(h, ref da, SPDRP_DEVICEDESC, out RegType, buffer, BUFFER_SIZE, out RequiredSize))
if (SetupDiGetDeviceRegistryProperty(h, ref da, SPDRP_DEVICEDESC, out RegType, ptrBuf, BUFFER_SIZE, out RequiredSize))
{
string ControllerDeviceDesc = Encoding.Unicode.GetString(buffer).TrimEnd('\0');
string ControllerDeviceDesc = Marshal.PtrToStringAuto(ptrBuf);
}
if (SetupDiGetDeviceRegistryProperty(h, ref da, SPDRP_DRIVER, out RegType, buffer, BUFFER_SIZE, out RequiredSize))
if (SetupDiGetDeviceRegistryProperty(h, ref da, SPDRP_DRIVER, out RegType, ptrBuf, BUFFER_SIZE, out RequiredSize))
{
string ControllerDriverKeyName = Encoding.Unicode.GetString(buffer).TrimEnd('\0');
string ControllerDriverKeyName = Marshal.PtrToStringAuto(ptrBuf);
}
}
}
}
i++;
}
SetupDiDestroyDeviceInfoList(h);
Alternative Sample Code:
Everything is the same as above until you get to the line "//get the Device Description and DriverKeyName".
This code uses the Alternative C# signature of the external function.
if ( SetupDiGetDeviceRegistryProperty(h, ref da, SPDRP_DEVICEDESC, out regType, ptrBuffer, BUFFER_SIZE, out RequiredSize) )
{
string ControllerDeviceDesc = Marshal.PtrToStringAuto(ptrBuffer);
string ControllerDeviceDesc = Marshal.PtrToStringAnsi(ptrBuffer);
}
if ( SetupDiGetDeviceRegistryProperty(h, ref da, SPDRP_DRIVER, out regType, ptrBuffer, BUFFER_SIZE, out RequiredSize) )
{
string ControllerDriverKeyName = Marshal.PtrToStringAuto(ptrBuffer);
string ControllerDriverKeyName = Marshal.PtrToStringAnsi(ptrBuffer);
}
Marshal.FreeHGlobal(ptrBuffer);
The SetupDiGetDeviceRegistryProperty function retrieves the specified device property. This handle is typically returned by the SetupDiGetClassDevs or SetupDiGetClassDevsEx function. If the function succeeds, the return value is nonzero.
2/23/2020 9:55:52 PM - -14.9.137.224
Retrieve a device information set for the devices in a specified class.
3/24/2020 6:32:30 PM - -24.98.243.63
The SetupDiGetDeviceRegistryProperty function retrieves the specified device property. This handle is typically returned by the SetupDiGetClassDevs or SetupDiGetClassDevsEx function. If the function succeeds, the return value is nonzero.
2/23/2020 9:55:52 PM - -14.9.137.224
Retrieve a device information set for the devices in a specified class.
3/24/2020 6:32:30 PM - -24.98.243.63
defines a device instance that is a member of the device information set
4/21/2018 9:30:32 AM - 172.56.32.78
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).