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.