Sign in to follow this  
Followers 0
Gordon J. Tyler

problem using setupAPI.dll on 64-bit OSes

2 posts in this topic

Here's a piece of code that lists all of the PCI network adapters in a computer.

If it finds one that is disabled, it will enable it.

I can't seem to get it to work on Windows 7 64-bit.

If I compile it as 32-bit, it can list the adapters but gets an error when it tries to enable the adapter.

If I compile it as 64-bit, it can't even list the adapters.

I tried to use the new struct align features in the 3.3.7 BETA versions, but it didn't help - the data sizes did not change.

I wrote the code by looking at the Microsoft devcom source (available in their DDK download) and pulling some functions from SetupAPI.au3

This shouldn't be impossible because the 64-bit version of devcon.exe can do it.

Not sure what I am missing.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=Y
#AutoIt3Wrapper_Change2CUI=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <Misc.au3>

Global Const $SETUPAPI_DllHandle = DllOpen("SetupApi.dll")
Global Const $KERNEL32_DllHandleA = DllOpen("Kernel32.dll")

Global $tagSP_DEVICEINFO_DATA = "dword Size;byte Guid[16];dword DevInst;ulong_ptr Reserved"
Global $tagSP_CLASSINSTALL_HEADER = "dword Size;dword DIFCode"
Global $tagSP_PROPCHANGE_PARAMS = "dword Size;dword DIFCode;dword State;dword Scope;dword HwProfile"
Global $struct_align_prefix = ""

;; version 3.3.7 BETA version supports stuct alignment which we may need to get this to work in 64-bit mode
If StringLeft(@AutoItVersion, 5) = "3.3.7" Then
    $struct_align_prefix = _Iif(@OSArch = "X86", "ALIGN 1;", "ALIGN 8;")
    $tagSP_DEVICEINFO_DATA = $struct_align_prefix & "dword Size;byte Guid[16];dword DevInst;ulong_ptr Reserved"
    $tagSP_CLASSINSTALL_HEADER = $struct_align_prefix & "dword Size;dword DIFCode"
    $tagSP_PROPCHANGE_PARAMS = $struct_align_prefix & "STRUCT;dword Size;dword DIFCode;ENDSTRUCT;dword State;dword Scope;dword HwProfile"
EndIf

; ####  SetupDiGetClassDevs Constants ####
; ==============================================================================
Global Const $DIGCF_DEFAULT = 1
Global Const $DIGCF_PRESENT = 2
Global Const $DIGCF_ALLCLASSES = 4
Global Const $DIGCF_PROFILE = 8
Global Const $DIGCF_DEVICEINTERFACE = 16
; ==============================================================================
; #### Flags for the SPDRP_CONFIGFLAGS in SetupDiGetDeviceRegistryProperty ####
; ==============================================================================
Const $CONFIGFLAG_DISABLED = 0x00000001 ; Set if disabled
Const $CONFIGFLAG_REMOVED = 0x00000002 ; Set if a present hardware enum device deleted
Const $CONFIGFLAG_MANUAL_INSTALL = 0x00000004 ; Set if the devnode was manually installed
Const $CONFIGFLAG_IGNORE_BOOT_LC = 0x00000008 ; Set if skip the boot config
Const $CONFIGFLAG_NET_BOOT = 0x00000010 ; Load this devnode when in net boot
Const $CONFIGFLAG_REINSTALL = 0x00000020 ; Redo install
Const $CONFIGFLAG_FAILEDINSTALL = 0x00000040 ; Failed the install
Const $CONFIGFLAG_CANTSTOPACHILD = 0x00000080 ; Can't stop/remove a single child
Const $CONFIGFLAG_OKREMOVEROM = 0x00000100 ; Can remove even if rom.
Const $CONFIGFLAG_NOREMOVEEXIT = 0x00000200 ; Don't remove at exit.
Const $CONFIGFLAG_FINISH_INSTALL = 0x00000400 ; Complete install for devnode running 'raw'
Const $CONFIGFLAG_NEEDS_FORCED_CONFIG = 0x00000800 ; This devnode requires a forced config

Const $CSCONFIGFLAG_BITS = 0x00000007 ; OR of below bits
Const $CSCONFIGFLAG_NONE = 0
Const $CSCONFIGFLAG_DISABLED = 0x00000001 ; Set if
Const $CSCONFIGFLAG_DO_NOT_CREATE = 0x00000002 ; Set if
Const $CSCONFIGFLAG_DO_NOT_START = 0x00000004 ; Set if
; ==============================================================================
; #### Property for _SetupDiGetDeviceRegistryProperty ####
; ==============================================================================
Const $SPDRP_DEVICEDESC = 0x00000000 ; DeviceDesc (R/W)
Const $SPDRP_HARDWAREID = 0x00000001 ; HardwareID (R/W)
Const $SPDRP_COMPATIBLEIDS = 0x00000002 ; CompatibleIDs (R/W)
Const $SPDRP_NTDEVICEPATHS = 0x00000003 ; Unsupported, DO NOT USE
Const $SPDRP_SERVICE = 0x00000004 ; Service (R/W)
Const $SPDRP_CONFIGURATION = 0x00000005 ; Configuration (R)
Const $SPDRP_CONFIGURATIONVECTOR = 0x00000006 ; ConfigurationVector (R)
Const $SPDRP_CLASS = 0x00000007 ; Class (R)--tied to ClassGUID
Const $SPDRP_CLASSGUID = 0x00000008 ; ClassGUID (R/W)
Const $SPDRP_DRIVER = 0x00000009 ; Driver (R/W)
Const $SPDRP_CONFIGFLAGS = 0x0000000A ; ConfigFlags (R/W)
Const $SPDRP_MFG = 0x0000000B ; Mfg (R/W)
Const $SPDRP_FRIENDLYNAME = 0x0000000C ; FriendlyName (R/W)
Const $SPDRP_LOCATION_INFORMATION = 0x0000000D ; LocationInformation (R/W)
Const $SPDRP_PHYSICAL_DEVICE_OBJECT_NAME = 0x0000000E ; PhysicalDeviceObjectName (R)
Const $SPDRP_CAPABILITIES = 0x0000000F ; Capabilities (R)
Const $SPDRP_UI_NUMBER = 0x00000010 ; UiNumber (R)
Const $SPDRP_UPPERFILTERS = 0x00000011 ; UpperFilters (R/W)
Const $SPDRP_LOWERFILTERS = 0x00000012 ; LowerFilters (R/W)
Const $SPDRP_MAXIMUM_PROPERTY = 0x00000013 ; Upper bound on ordinals
Const $SPDRP_REMOVAL_POLICY = 0x1F
Const $SPDRP_REMOVAL_POLICY_HW_DEFAULT = 0x20
; ==============================================================================
; Values indicating a change in a devices' state
; ====================================================================================
Const $DICS_ENABLE = 0x00000001
Const $DICS_DISABLE = 0x00000002
Const $DICS_PROPCHANGE = 0x00000003
Const $DICS_START = 0x00000004
Const $DICS_STOP = 0x00000005
; =====================================================================================
; #### DIF (device installation function) code ####
; ====================================================================================
Const $DIF_SELECTDEVICE = 0x00000001
Const $DIF_INSTALLDEVICE = 0x00000002
Const $DIF_ASSIGNRESOURCES = 0x00000003
Const $DIF_PROPERTIES = 0x00000004
Const $DIF_REMOVE = 0x00000005
Const $DIF_FIRSTTIMESETUP = 0x00000006
Const $DIF_FOUNDDEVICE = 0x00000007
Const $DIF_SELECTCLASSDRIVERS = 0x00000008
Const $DIF_VALIDATECLASSDRIVERS = 0x00000009
Const $DIF_INSTALLCLASSDRIVERS = 0x0000000A
Const $DIF_CALCDISKSPACE = 0x0000000B
Const $DIF_DESTROYPRIVATEDATA = 0x0000000C
Const $DIF_VALIDATEDRIVER = 0x0000000D
Const $DIF_MOVEDEVICE = 0x0000000E
Const $DIF_DETECT = 0x0000000F
Const $DIF_INSTALLWIZARD = 0x00000010
Const $DIF_DESTROYWIZARDDATA = 0x00000011
Const $DIF_PROPERTYCHANGE = 0x00000012
Const $DIF_ENABLECLASS = 0x00000013
Const $DIF_DETECTVERIFY = 0x00000014
Const $DIF_INSTALLDEVICEFILES = 0x00000015
Const $DIF_UNREMOVE = 0x00000016
Const $DIF_SELECTBESTCOMPATDRV = 0x00000017
Const $DIF_ALLOW_INSTALL = 0x00000018
Const $DIF_REGISTERDEVICE = 0x00000019
Const $DIF_INSTALLINTERFACES = 0x00000020
Const $DIF_DETECTCANCEL = 0x00000021
Const $DIF_REGISTER_COINSTALLERS = 0x00000022
Const $DIF_POWERMESSAGEWAKE = 0x27
; ====================================================================================
; Values specifying the scope of a device property change
; ====================================================================================
Const $DICS_FLAG_GLOBAL = 0x00000001
Const $DICS_FLAG_CONFIGSPECIFIC = 0x00000002
Const $DICS_FLAG_CONFIGGENERAL = 0x00000004
; ====================================================================================

; #### Removal policies (retrievable via _SetupDiGetDeviceRegistryProperty with
; the SPDRP_REMOVAL_POLICY, or SPDRP_REMOVAL_POLICY_HW_DFAULT properties) ####
; ====================================================================================
Const $CM_REMOVAL_POLICY_EXPECT_NO_REMOVAL = 1
Const $CM_REMOVAL_POLICY_EXPECT_ORDERLY_REMOVAL = 2
Const $CM_REMOVAL_POLICY_EXPECT_SURPRISE_REMOVAL = 3
; ====================================================================================

Global $hGlobalDevs = 0

ConsoleWrite("sizeof(" & $tagSP_DEVICEINFO_DATA & ") = " & DllStructGetSize(DllStructCreate($tagSP_DEVICEINFO_DATA)) & @CRLF)
ConsoleWrite("sizeof(" & $tagSP_PROPCHANGE_PARAMS & ") = " & DllStructGetSize(DllStructCreate($tagSP_PROPCHANGE_PARAMS)) & @CRLF)

net_checkAdapters()

Func net_checkAdapters()
ConsoleWrite("calling _SetupDiClassGuidsFromName(net)" & @CRLF)
    Local $guid = _SetupDiClassGuidsFromName("net")
    Local $cnt = @extended
    If Not @error Then
ConsoleWrite("cnt=" & $cnt & " " & $guid & @CRLF)
ConsoleWrite("calling _SetupDiGetClassDevs()" & @CRLF)
        $hGlobalDevs = _SetupDiGetClassDevs($DIGCF_PRESENT, $guid, "PCI")
        If Not @error Then
ConsoleWrite("handle returned" & @CRLF)
            Local $iIndex = 0
            While True
                Local $tSP_DEVINFO_DATA
                _SetupDiEnumDeviceInfo($hGlobalDevs, $iIndex, $tSP_DEVINFO_DATA)
                If @error Then ExitLoop
                Local $desc = _SetupDiGetDeviceRegistryProperty($hGlobalDevs, $tSP_DEVINFO_DATA, $SPDRP_DEVICEDESC)
                Local $disabled = _Iif(BitAND(_SetupDiGetDeviceRegistryProperty($hGlobalDevs, $tSP_DEVINFO_DATA, $SPDRP_CONFIGFLAGS), $CONFIGFLAG_DISABLED) = $CONFIGFLAG_DISABLED, True, False)
ConsoleWrite($iIndex & ": " & $desc & @CRLF)
                If $disabled Then
                    net_changeAdapterProperty($iIndex, $DICS_ENABLE)
ConsoleWriteError("net_changeAdapterProperty() returned " & @error & "." & @extended & @CRLF)
                EndIf
                $iIndex += 1
            WEnd
        EndIf
    EndIf
    _SetupDiDestroyDeviceInfoList($hGlobalDevs)
    If @error Then ConsoleWriteError("_SetupDiDestroyDeviceInfoList() returned " & @error & @CRLF)
ConsoleWrite("done" & @CRLF)
EndFunc

Func net_changeAdapterProperty($iIndex, $nDICS_Code)
    Local $tSP_DEVINFO_DATA
    _SetupDiEnumDeviceInfo($hGlobalDevs, $iIndex, $tSP_DEVINFO_DATA)
    If @error Then Return SetError(@error, 1, False)
    Local $tSP_PROPCHANGE_PARAMS = DllStructCreate($tagSP_PROPCHANGE_PARAMS)
    DllStructSetData($tSP_PROPCHANGE_PARAMS, "Size", DllStructGetSize(DllStructCreate($tagSP_CLASSINSTALL_HEADER)))
    DllStructSetData($tSP_PROPCHANGE_PARAMS, "DIFCode", $DIF_PROPERTYCHANGE)
    DllStructSetData($tSP_PROPCHANGE_PARAMS, "State", $nDICS_Code)
    DllStructSetData($tSP_PROPCHANGE_PARAMS, "Scope", $DICS_FLAG_GLOBAL)  ;; $DICS_FLAG_CONFIGSPECIFIC
    DllStructSetData($tSP_PROPCHANGE_PARAMS, "HwProfile", 0)
    _SetupDiSetClassInstallParams($hGlobalDevs, $tSP_DEVINFO_DATA, $tSP_PROPCHANGE_PARAMS, DllStructGetSize($tSP_PROPCHANGE_PARAMS))
    If @error Then Return SetError(@error, 2, False)
    _SetupDiCallClassInstaller($hGlobalDevs, $tSP_DEVINFO_DATA, $DIF_PROPERTYCHANGE)
    If @error Then Return SetError(@error, 3, False)
    Return True
EndFunc

; #### FUNCTION ####
; =========================================================================
; Name  : _SetupDiClassGuidsFromName
; Description   : Return the GUID of the specified device class.
; Parameter(s)  : $sClassName   - The name of the device class, (NET/Keyboard...).
; Return values : If succeeds, returns a GUID structure (contains one member - Guid), and @extended is set to non-zero. If fails, returns a GUID structure either, but @extended is set to zero.
; Author    : Pusofalse
; =========================================================================
Func _SetupDiClassGuidsFromName($sClassName)
    Local $tGuid, $pGuid, $iResult
    $tGuid = DllStructCreate($struct_align_prefix & "byte Guid[16]")
    $pGuid = DllStructGetPtr($tGuid)
    $iResult = DllCall($SETUPAPI_DllHandle, "int", "SetupDiClassGuidsFromName", "str", $sClassName, "ptr", $pGuid, "dword", 1, "int*", 0)
    Return SetError(_CM_Get_Last_Error(), $iResult[4], $tGuid)
EndFunc ;==>_SetupDiClassGuidsFromName

Func _CM_Get_Last_Error()
    Local $iResult
    $iResult = DllCall($Kernel32_DllHandleA, "long", "GetLastError")
    Return $iResult[0]
EndFunc ;==>_CM_Get_Last_Error

Func _CM_GUID_From_String($sGUID)
    Local $tGUID = DllStructCreate($struct_align_prefix & "byte Guid[16]"), $iResult
    $iResult = DllCall("Ole32.dll", "int", "CLSIDFromString", "wstr", $sGUID, "ptr", DllStructGetPtr($tGUID))
    Return SetError($iResult[0], 0, $tGUID)
EndFunc ;==>_CM_GUID_From_String

; #### FUNCTION ####
; ==============================================================================
; Name  : _SetupDiGetClassDevs
; Description   : Retrieves A handle to device information set.
; Parameter(s)  : $iFlags   - A value of type DWORD that specifies control options that filter the device information elements that are added to the device information set. This parameter can be a bitwise OR of zero or more of the following flags, can be a combination of the following values:
;       :   - $DIGCF_ALLCLASSES
;       :   - Return a list of installed devices for all device setup classes or all device interface classes.
;       :   - $DIGCF_DEVICEINTERFACE
;       :   - Return devices that support device interfaces for the specified device interface classes. This flag must be set in the Flags parameter if the Enumerator parameter specifies a device instance ID.
;       :   - $DIGCF_DEFAULT
;       :   - Return only the device that is associated with the system default device interface, if one is set, for the specified device interface classes.
;       :   - $DIGCF_PRESENT
;       :   - Return only devices that are currently present in a system.
;       :   - $DIGCF_PROFILE
;       :   - Return only devices that are a part of the current hardware profile
;       : $vGuid    - An optional variable-type GUID value for a device setup class or a device interface class.
;       : $sEnumerator  - Enumerator for this device information set (PCI/SCSI/PCMCIA...).
; Return values : If succeeds, returns a handle to device information set contains the control options. Otherwise, returns ERROR_INVALID_HANDLE (-1) and sets @error to a system error code.
; Author    : Pusofalse
; =========================================================================
Func _SetupDiGetClassDevs($iFlags, $vGuid = 0, $sEnumerator = "")
    Local $iResult, $tGuid, $pGuid = 0, $sType = "ptr"
    If $sEnumerator <> "" Then $sType = "str"
    If IsString($vGuid) Then
        If StringLeft($vGuid, 1) & StringRight($vGuid, 1) = "{}" Then
            $tGUID = _CM_GUID_From_String($vGuid)
            $pGuid = DllStructGetPtr($tGUID)
        ElseIf $vGuid <> "" Then
            $tGuid = _SetupDiClassGuidsFromName($vGuid)
            $pGuid = DllStructGetPtr($tGuid)
        EndIf
    ElseIf IsDllStruct($vGuid) Then
        $pGuid = DllStructGetPtr($vGuid)
    ElseIf IsPtr($vGuid) Then
        $pGuid = $vGuid
    Else
        $pGuid = 0
    EndIf
    $iResult = DllCall($SETUPAPI_DllHandle, "ptr", "SetupDiGetClassDevs", "ptr", $pGuid, $sType, $sEnumerator, "hWnd", 0, "dword", $iFlags)
    Return SetError(_CM_Get_Last_Error(), _SetupDiApiBufferFree($tGuid), $iResult[0])
EndFunc ;==>_SetupDiGetClassDevs

; #### FUNCTION ####
; =========================================================================
; Name  : _SetupDiEnumDeviceInfo
; Description   : Enumerates a device information element in the device information set.
; Parameter(s)  : $hDevs    - A handle to the device information set.
;       : $iIndex   - The zero-based index of the device information element to retrieve.
;       : $tSP_DEVINFO_DATA - A variable receives a SP_DEVINFO_DATA structure contains the device information element.
; Return values : True indicates success, false to failure, in which case, @error is set to a system error code.
; Author    : Pusofalse
; =========================================================================
Func _SetupDiEnumDeviceInfo($hDevs, $iIndex, ByRef $tSP_DEVINFO_DATA)
    Local $iResult, $pSP_DEVINFO_DATA
    If Not IsDllStruct($tSP_DEVINFO_DATA) Then
        $tSP_DEVINFO_DATA = DllStructCreate($tagSP_DEVICEINFO_DATA)
        DllStructSetData($tSP_DEVINFO_DATA, "Size", 28)
    EndIf
    $pSP_DEVINFO_DATA = DllStructGetPtr($tSP_DEVINFO_DATA)
    $iResult = DllCall($SETUPAPI_DllHandle, "int", "SetupDiEnumDeviceInfo", "ptr", $hDevs, "int", $iIndex, "ptr", $pSP_DEVINFO_DATA)
    Return SetError(_CM_Get_Last_Error(), $iResult[0], $iResult[0])
EndFunc ;==>_SetupDiEnumDeviceInfo

; #### FUNCTION ####
; =========================================================================
; Name  : _SetupDiApiBufferFree
; Description   : Frees a memory buffer, internal used only.
; Parameter(s)  : $vBuffer - Buffer to be freed.
; Return values : None.
; Author    : Pusofalse
; =========================================================================
Func _SetupDiApiBufferFree(ByRef $vBuffer, $vValue = 0, $vReturn = "", $iError = @error, $iExtended = @Extended)
    $vBuffer = $vValue
    Return SetError($iError, $iExtended, $vReturn)
EndFunc ;==>_SetupDiApiBufferFree

; #### FUNCTION ####
; =========================================================================
; Name  : _SetupDiGetDeviceRegistryProperty
; Description   : Retrieve the device registry property.
; Parameter(s)  : $hDevs    - A handle to a device information set, obtain the handle by using _SetupDiGetClassDevs function.
;       : $pSP_DEVINFO_DATA - A pointer to/or a SP_DEVICEINFO_DATA structure contains the device information from which the property information is retrieved.
;       : $iProperty    - A value indicates the property required, see SPDRP_* constants for a value.
; Return values : If success, returns the requested property. If failure, returns NULL and sets @error to a system error code, pass @error to FormatMessage for an explicit error message.
; Author    : Pusofalse
; =========================================================================
Func _SetupDiGetDeviceRegistryProperty($hDevs, $pSP_DEVINFO_DATA, $iProperty)
    Local $iResult, $pBuffer, $tBuffer, $sVal, $vVar, $iSysError
    If IsDllStruct($pSP_DEVINFO_DATA) Then
        $pSP_DEVINFO_DATA = DllStructGetPtr($pSP_DEVINFO_DATA)
    EndIf
    $iResult = DllCall($SETUPAPI_DllHandle, "int", "SetupDiGetDeviceRegistryProperty", _
            "ptr", $hDevs, "ptr", $pSP_DEVINFO_DATA, "dword", $iProperty, _
            "dword*", 0, "ptr", 0, "dword", 0, "dword*", 0)
    $pBuffer = _CM_Heap_Alloc($iResult[7])
    $iResult = DllCall($SETUPAPI_DllHandle, "int", "SetupDiGetDeviceRegistryProperty", _
            "ptr", $hDevs, "ptr", $pSP_DEVINFO_DATA, "dword", $iProperty, _
            "dword*", 0, "ptr", $pBuffer, "dword", $iResult[7], "dword*", 0)
    $iSysError = _CM_Get_Last_Error()
    Switch $iResult[4]
    Case 1, 2, 7
        $tBuffer = DllStructCreate($struct_align_prefix & "char Data[" & $iResult[7] & "]", $pBuffer)
    Case 4, 5
        $tBuffer = DllStructCreate($struct_align_prefix & "dword Data", $pBuffer)
    Case 6
        $tBuffer = DllStructCreate($struct_align_prefix & "wchar Data[" & $iResult[7] / 2 & "]", $pBuffer)
    Case Else
        $tBuffer = DllStructCreate($struct_align_prefix & "byte Data[" & $iResult[7] & "]", $pBuffer)
    EndSwitch
    If $iResult[4] <> 7 Then
        $vVar = DllStructGetData($tBuffer, "Data")
        _CM_Heap_Free($pBuffer)
        Return SetError($iSysError, _CM_Free_Variable($tBuffer) + $iResult[4], $vVar)
    EndIf
    For $i = 1 To $iResult[7]
        $sVal = DllStructGetData($tBuffer, "Data", $i)
        If $sVal = Chr(0) Then
            $vVar &= @LF
            ContinueLoop
        EndIf
        $vVar &= $sVal
    Next
    _CM_Heap_Free($pBuffer)
    Return SetError($iSysError, 7 + _CM_Free_Variable($tBuffer), $vVar)
EndFunc ;==>_SetupDiGetDeviceRegistryProperty

Func _CM_Get_Process_Heap()
    Local $iResult
    $iResult = DllCall($Kernel32_DllHandleA, "long", "GetProcessHeap")
    Return $iResult[0]
EndFunc ;==>_CM_Get_Process_Heap

Func _CM_Heap_Alloc($iLength, $iFlags = 8)
    If $iLength < 1 Then Return 0
    Local $pMem, $hHeap = _CM_Get_Process_Heap()
    $pMem = DllCall($Kernel32_DllHandleA, "ptr", "HeapAlloc", "hWnd", $hHeap, "dword", $iFlags, "dword", $iLength)
    Return $pMem[0]
EndFunc ;==>_CM_Heap_Alloc

Func _CM_Heap_Free(ByRef $pMem)
    If $pMem < 1 Then Return SetError(87, 0, False)
    Local $iResult, $hHeap = _CM_Get_Process_Heap()
    $iResult = DllCall($Kernel32_DllHandleA, "int", "HeapFree", "hWnd", $hHeap, "dword", 0, "ptr", $pMem)
    If $iResult[0] Then $pMem = Ptr(0)
    Return $iResult[0] <> 0
EndFunc ;==>_CM_Heap_Free

Func _CM_Heap_Size($pMem)
    If $pMem < 1 Then Return SetError(87, 0, 0)
    Local $iResult, $hHeap = _CM_Get_Process_Heap()
    $iResult = DllCall($Kernel32_DllHandleA, "long", "HeapSize", "hWnd", $hHeap, "dword", 0, "ptr", $pMem)
    Return $iResult[0]
EndFunc ;==>_CM_Heap_Size

Func _CM_Free_Variable(ByRef $vVariable)
    $vVariable = 0
EndFunc ;==>_CM_Free_Variable

; ##### FUNCTION ####
; =========================================================================
; Name  : _SetupDiSetClassInstallParams
; Description   : Sets the installation parameters for a device class.
; Parameter(s)  : $hDevs    - Supplies a handle to the device information set.
;       : $pSP_DEVINFO_DATA - A pointer to an SP_DEVINFO_DATA structure contains the device information set.
;       : $pSP_DEVINST_PARAMS   - A pointer to an SP_PROPCHANGE_PARAMS structure contains the data to be set.
;       : $iSizeInst    - Size of the $tSP_DEVINST_PARAMS.
; Return values : TRUE is returned if succeeds, FALSE otherwise, in which case, @error is set to the reason of the failure.
; Author    : Pusofalse
; =========================================================================
Func _SetupDiSetClassInstallParams($hDevs, $pSP_DEVINFO_DATA, $pSP_DEVINST_PARAMS, $iSizeInst)
    If IsDllStruct($pSP_DEVINFO_DATA) Then $pSP_DEVINFO_DATA = DllStructGetPtr($pSP_DEVINFO_DATA)
    If IsDllStruct($pSP_DEVINST_PARAMS) Then $pSP_DEVINST_PARAMS = DllStructGetPtr($pSP_DEVINST_PARAMS)
    Local $iResult = DllCall($SETUPAPI_DllHandle, "int", "SetupDiSetClassInstallParams", _
            "ptr", $hDevs, "ptr", $pSP_DEVINFO_DATA, _
            "ptr", $pSP_DEVINST_PARAMS, "dword", $iSizeInst)
    Return SetError(_CM_Get_Last_Error(), $iResult[0], $iResult[0])
EndFunc ;==>_SetupDiSetClassInstallParams

; #### FUNCTION ####
; =========================================================================
; Name  : _SetupDiCallClassInstaller
; Description   : The function calls the appropriate class installer, and any registered co-installers, with the specified installation request (DIF code).
; Parameter(s)  : $hDevs    - A handle to the device information set.
;       : $pSP_DEVINFO_DATA - A pointer (or a structure) to an SP_DEVINFO_DATA contains the device information element.
;       : $iDIFCode - The device installation request (DIF request) to pass to the co-installers and class installer.
; Return values : Returns TRUE if succeeds, FALSE otherwise, the error code is set to in @error.
; Author    : Pusofalse
; =========================================================================
Func _SetupDiCallClassInstaller($hDevs, $pSP_DEVINFO_DATA, $iDIFCode)
    If IsDllStruct($pSP_DEVINFO_DATA) Then $pSP_DEVINFO_DATA = DllStructGetPtr($pSP_DEVINFO_DATA)
    Local $iResult = DllCall($SETUPAPI_DllHandle, "int", "SetupDiCallClassInstaller", "dword", $iDifCode, "ptr", $hDevs, "ptr", $pSP_DEVINFO_DATA)
    Return SetError(_CM_Get_Last_Error(), $iResult[0], $iResult[0])
EndFunc ;==>_SetupDiCallClassInstaller

; #### FUNCTION ####
; =========================================================================
; Name  : _SetupDiDestroyDeviceInfoList
; Description   : Release a device information set.
; Parameter(s)  : $hDevs    - Supplies a handle to the device information set, typically obtained by the following functions:
;       :       _SetupDiCreateDeviceDevs
;       :       _SetupDiCreateDeviceDevsEx
;       :       _SetupDiCreateDeviceInfo
;       :       _SetupDiCreateDeviceInfoEx
;       :       _SetupDiGetClassDevs
;       :       _SetupDiGetClassDevsEx
; Return values : TRUE indicates success, FALSE indicates failure.
; Author    : Pusofalse
; =========================================================================
Func _SetupDiDestroyDeviceInfoList($hDevs)
    Local $iResult
    $iResult = DllCall($SETUPAPI_DllHandle, "int", "SetupDiDestroyDeviceInfoList", "hWnd", $hDevs)
    Return SetError(_CM_Get_Last_Error(), $iResult[0], $iResult[0])
EndFunc ;==>_SetupDiDestroyDeviceInfoList

Share this post


Link to post
Share on other sites



You can download the WDDK here:

Windows Driver Kit v7.1

Once you install it, the devcon files are here:

Binaries: C:\WinDDK\7600.16385.1\tools\devcon

Source: C:\WinDDK\7600.16385.1\src\setup\devcon

Includes: C:\WinDDK\7600.16385.1\inc\api

Here's me running devcon.exe on Windows 7 64-bit with an Intel i3 PC:

C:\WinDDK\7600.16385.1\tools\devcon\amd64>devcon status =net PCI*
PCI\VEN_8086&DEV_10EF&SUBSYS_304A103C&REV_05\3&21436425&0&C8
    Name: Intel(R) 82578DM Gigabit Network Connection
    Driver is running.
PCI\VEN_168C&DEV_0024&SUBSYS_3A701186&REV_01\4&3F76195&0&00E4
    Name: D-Link DWA-556 Xtreme N PCIe Desktop Adapter
    Device is disabled.
2 matching device(s) found.

C:\WinDDK\7600.16385.1\tools\devcon\amd64>devcon enable PCI\VEN_168C*
PCI\VEN_168C&DEV_0024&SUBSYS_3A701186&REV_01\4&3F76195&0&00E4: Enabled
1 device(s) are enabled.

C:\WinDDK\7600.16385.1\tools\devcon\amd64>

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0