How Can I Get a List of Installed Device Drivers?

How Can I Get a List of Installed Device Drivers?

  • Comments 2
  • Likes
Hey, Scripting Guy! Question

Hey, Scripting Guy! How can I get a list of installed device drivers, their version number, and their date?

-- SH

SpacerHey, Scripting Guy! AnswerScript Center

Hey, SH. You know, as we’re writing this column the first round of the NCAA men’s basketball tournament is in full swing. But don’t worry: despite the fact that this year’s opening round games are all being broadcast live over the Internet you can rest assured that the Scripting Guys are hard at work, giving your question their undivided attention.

Oh, come on, ref: you’ve got a whistle, you might as well use it!

Sorry. The, uh, person across the hall seems to have their CD player turned up a bit loud. Say, could you keep it down a little? Some of us are trying to work here.

Can you believe the nerve of some people? Watching college basketball while at work; for shame.

Now, let’s see, we were talking about the 28 points Brandon Roy (the real player of the year this season) scored last night as the Washington Huskies defeated Utah State. And as Brandon noted in his post-game press conference, yes, SH, you can use a script to get a list of installed device drivers, their version number, and their date. In fact, you can use a script very much like this one to get back that information:

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * from Win32_PnPSignedDriver")

For Each objItem in colItems
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "Device Name: " & objItem.DeviceName
    dtmWMIDate = objItem.DriverDate
    strReturn = WMIDateStringToDate(dtmWMIDate)
    Wscript.Echo "Driver Date: " & strReturn
    Wscript.Echo "Driver Version: " & objItem.DriverVersion
    Wscript.Echo "Is Signed: " & objItem.IsSigned
    Wscript.Echo
Next
 
Function WMIDateStringToDate(dtmWMIDate)
    If Not IsNull(dtmWMIDate) Then
        WMIDateStringToDate = CDate(Mid(dtmWMIDate, 5, 2) & "/" & _
            Mid(dtmWMIDate, 7, 2) & "/" & Left(dtmWMIDate, 4) _
                & " " & Mid (dtmWMIDate, 9, 2) & ":" & _
                    Mid(dtmWMIDate, 11, 2) & ":" & Mid(dtmWMIDate,13, 2))
    End If
End Function

Don’t let the code deter you here. This script looks a little frightening (especially towards the end), but that’s because of the goofy little function we have to use to convert WMI’s UTC date-time values (like 20010701000000.******+***) to somewhat more-readable date-time values (like 7/1/2001). We aren’t going to describe the workings of this function in any detail today; if you’d like to know more about what we’re doing here (and how we go about doing it) take a look at this section of the Microsoft Windows 2000 Scripting Guide. We should also note that this function is required if you’re running Windows 2000 or an earlier version of Windows. If you’re running Windows XP or Windows Server 2003, there’s a slightly easier way to convert UTC dates to real dates. We opted to use the goofy function because it works on any version of Windows.

Oh, my gosh! Come on, you have got to make that shot!

Um, we’ll close the door so that CD player won’t bother us anymore.

And, yes, that is a kind of unusual song he’s listening to. Must be some kind of rap/hip-hop thing.

Other than the goofy date-time converter the remainder of the script is pretty straightforward. We begin by connecting to the WMI service on the local computer; of course - and let’s all say it together - we could also run this script against a remote machine. (How? Just assign the name of the remote computer to the variable strComputer.) We then use this line of code to retrieve a collection of all the plug-and-play device drivers installed on the computer:

Set colItems = objWMIService.ExecQuery("Select * from Win32_PnPSignedDriver")

From there we simply set up a For Each loop to walk through the collection of device drivers, echoing back the values of properties such as DeviceName and DriverVersion. The one tricky part (which really isn’t all that tricky) occurs when we encounter the DriverDate property. If we just echoed back the DriverDate we’d get one of those ugly UTC date-time values. Therefore, instead of echoing back the value of DriverDate we do this:

dtmWMIDate = objItem.DriverDate
strReturn = WMIDateStringToDate(dtmWMIDate)
Wscript.Echo "Driver Date: " & strReturn

As you can see, we grab the value of DriverDate and store it in a variable named dtmWMIDate. We then call the function WMIDateStringToDate (cute name, huh?), passing the variable dtmWMIDate as the function parameter. The function converts the date for us and then stores the converted value in a variable named strReturn. And then it’s the value of the variable (rather than the actual property value) that we end up echoing back.


Whoa: he traveled on that play. Come on: doesn’t it look like he’s traveling every time he gets the ball?

By which we mean, gee, doesn’t it look like this is a very easy way to get back device driver information?

At any rate, we have to go now; it’s time to watch Arizona get beat by Wisconsin.

By which we mean, gee, it must be time to do even more work than we usually do ….

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • we need a script that will first find out the computer name on which we are running,then pass that as a parameter to the function, which will reach the rows from excel sheet and extracts LANID or Device Name,then we can pass that DeviceName to the msi command line....

    How can I do that, Can you Please help me on this .... ?

  • This script returns only drivers of devices currently connected to a system.

    You will not see installed driver, if device disconnected.

    Looking for solution. :(