Click to Rate and Give Feedback
MSDN
MSDN Library
System Services
PSAPI Reference
PSAPI Functions
 EnumDeviceDrivers Function
EnumDeviceDrivers Function

Retrieves the load address for each device driver in the system.

Syntax

BOOL WINAPI EnumDeviceDrivers(
  __out  LPVOID *lpImageBase,
  __in   DWORD cb,
  __out  LPDWORD lpcbNeeded
);

Parameters

lpImageBase [out]

An array that receives the list of load addresses for the device drivers.

cb [in]

The size of the lpImageBase array, in bytes. If the array is not large enough to store the load addresses, the lpcbNeeded parameter receives the required size of the array.

lpcbNeeded [out]

The number of bytes returned in the lpImageBase array.

Return Value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

To determine how many device drivers were enumerated by the call to EnumDeviceDrivers, divide the resulting value in the lpcbNeeded parameter by sizeof(LPVOID).

Examples

For an example, see Enumerating all Device Drivers in the System.

Requirements

Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderPsapi.h
LibraryPsapi.lib
DLLPsapi.dll

See Also

Device Driver Information
GetDeviceDriverBaseName
GetDeviceDriverFileName
PSAPI Functions


Send comments about this topic to Microsoft

Build date: 11/6/2008

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Example code for VB6      John Atkinson1 ... Noelle Mallory - MSFT   |   Edit   |  

A quick example of how to use these API's in VB6.

To start with, you'll need the following declares:

Private Declare Function EnumDeviceDrivers Lib "psapi.dll" (ByRef lpImageBase As Long, ByVal cb As Long, ByRef lpcbNeeded As Long) As Long
Private Declare Function GetDeviceDriverBaseName Lib "psapi.dll" Alias "GetDeviceDriverBaseNameA" (ByVal ImageBase As Long, ByVal lpBaseName As String, ByVal nSize As Long) As Long
Private Declare Function GetDeviceDriverFileName Lib "psapi.dll" Alias "GetDeviceDriverFileNameA" (ByVal ImageBase As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long

Then you can add the following sub (note that you can interchange the GetDriveDriveBaseName and GetDeviceDriverFileName lines as required):

Public Sub dumpDrivers()
Dim loadAddresses() As Long, bytesNeeded As Long, driverCount As Integer, outputBuffer As String, currentDriver As Integer
ReDim loadAddresses(0)
If EnumDeviceDrivers(loadAddresses(0), 4 * (UBound(loadAddresses) + 1), bytesNeeded) <> 0 Then
ReDim loadAddresses(0 To (bytesNeeded / 4) - 1)
EnumDeviceDrivers loadAddresses(0), 4 * (UBound(loadAddresses) + 1), bytesNeeded
driverCount = bytesNeeded / 4
MsgBox "Got " & driverCount & " Driver Load Addresses"

For currentDriver = 0 To driverCount - 1
outputBuffer = Space$(256)
'If GetDeviceDriverBaseName(loadAddresses(currentDriver), outputBuffer, Len(outputBuffer)) <> 0 Then
If GetDeviceDriverFileName(loadAddresses(currentDriver), outputBuffer, Len(outputBuffer)) <> 0 Then
Debug.Print currentDriver & vbTab & Trim$(outputBuffer)
End If
Next
End If
End Sub

Obviously you'll want to write your own code to do something useful with the data that you get back from the PSAPI but you can use my code as a starting point. For example, you might want to write a class (clsDrivers) and give it some public functions to add, remove, and enumerate drivers. You could then use that class for an array of different tasks - a setup program is the obvious thing that springs to mind but you could also use it in a startup / shutdown script on your network for updating out of date drivers across your enterprise.

Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker