{"id":67723,"date":"2006-03-20T17:58:00","date_gmt":"2006-03-20T17:58:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2006\/03\/20\/how-can-i-get-a-list-of-installed-device-drivers\/"},"modified":"2006-03-20T17:58:00","modified_gmt":"2006-03-20T17:58:00","slug":"how-can-i-get-a-list-of-installed-device-drivers","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-get-a-list-of-installed-device-drivers\/","title":{"rendered":"How Can I Get a List of Installed Device Drivers?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"> \n<P>Hey, Scripting Guy! How can I get a list of installed device drivers, their version number, and their date?<BR><BR>&#8212; SH<\/P><IMG border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/A> \n<P>Hey, SH. You know, as we\u2019re writing this column the first round of the NCAA men\u2019s basketball tournament is in full swing. But don\u2019t worry: despite the fact that this year\u2019s 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.<\/P>\n<P>Oh, come on, ref: you\u2019ve got a whistle, you might as well use it!<\/P>\n<P>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? <I>Some<\/I> of us are trying to work here.<\/P>\n<P>Can you believe the nerve of some people? Watching college basketball while at work; for <I>shame<\/I>.<\/P>\n<P>Now, let\u2019s see, we were talking about the 28 points Brandon Roy (the <I>real<\/I> 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:<\/P><PRE class=\"codeSample\">strComputer = &#8220;.&#8221;\nSet objWMIService = GetObject(&#8220;winmgmts:\\\\&#8221; &amp; strComputer &amp; &#8220;\\root\\cimv2&#8221;)<\/p>\n<p>Set colItems = objWMIService.ExecQuery(&#8220;Select * from Win32_PnPSignedDriver&#8221;)<\/p>\n<p>For Each objItem in colItems\n    Wscript.Echo &#8220;Device ID: &#8221; &amp; objItem.DeviceID\n    Wscript.Echo &#8220;Device Name: &#8221; &amp; objItem.DeviceName\n    dtmWMIDate = objItem.DriverDate\n    strReturn = WMIDateStringToDate(dtmWMIDate)\n    Wscript.Echo &#8220;Driver Date: &#8221; &amp; strReturn\n    Wscript.Echo &#8220;Driver Version: &#8221; &amp; objItem.DriverVersion\n    Wscript.Echo &#8220;Is Signed: &#8221; &amp; objItem.IsSigned\n    Wscript.Echo\nNext<\/p>\n<p>Function WMIDateStringToDate(dtmWMIDate)\n    If Not IsNull(dtmWMIDate) Then\n        WMIDateStringToDate = CDate(Mid(dtmWMIDate, 5, 2) &amp; &#8220;\/&#8221; &amp; _\n            Mid(dtmWMIDate, 7, 2) &amp; &#8220;\/&#8221; &amp; Left(dtmWMIDate, 4) _\n                &amp; &#8221; &#8221; &amp; Mid (dtmWMIDate, 9, 2) &amp; &#8220;:&#8221; &amp; _\n                    Mid(dtmWMIDate, 11, 2) &amp; &#8220;:&#8221; &amp; Mid(dtmWMIDate,13, 2))\n    End If\nEnd Function\n<\/PRE>\n<P>Don\u2019t let the code deter you here. This script looks a little frightening (especially towards the end), but that\u2019s because of the goofy little function we have to use to convert WMI\u2019s UTC date-time values (like 20010701000000.******+***) to somewhat more-readable date-time values (like 7\/1\/2001). We aren\u2019t going to describe the workings of this function in any detail today; if you\u2019d like to know more about what we\u2019re doing here (and how we go about doing it) take a look at <A href=\"http:\/\/null\/technet\/scriptcenter\/guide\/sas_wmi_yakv.mspx\" target=\"_blank\"><B>this section<\/B><\/A> of the <I>Microsoft Windows 2000 Scripting Guide<\/I>. We should also note that this function is required if you\u2019re running Windows 2000 or an earlier version of Windows. If you\u2019re running Windows XP or Windows Server 2003, there\u2019s 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.<\/P>\n<P>Oh, my gosh! Come on, you have <I>got<\/I> to make that shot!<\/P>\n<P>Um, we\u2019ll close the door so that CD player won\u2019t bother us anymore. <\/P>\n<P>And, yes, that is a kind of unusual song he\u2019s listening to. Must be some kind of rap\/hip-hop thing.<\/P>\n<P>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 &#8211; and let\u2019s all say it together &#8211; 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:<\/P><PRE class=\"codeSample\">Set colItems = objWMIService.ExecQuery(&#8220;Select * from Win32_PnPSignedDriver&#8221;)\n<\/PRE>\n<P>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 <B>DeviceName<\/B> and <B>DriverVersion<\/B>. The one tricky part (which really isn\u2019t all that tricky) occurs when we encounter the <B>DriverDate<\/B> property. If we just echoed back the DriverDate we\u2019d get one of those ugly UTC date-time values. Therefore, instead of echoing back the value of DriverDate we do this:<\/P><PRE class=\"codeSample\">dtmWMIDate = objItem.DriverDate\nstrReturn = WMIDateStringToDate(dtmWMIDate)\nWscript.Echo &#8220;Driver Date: &#8221; &amp; strReturn\n<\/PRE>\n<P>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\u2019s the value of the <I>variable<\/I> (rather than the actual property value) that we end up echoing back.<\/P>\n<P><BR>Whoa: he traveled on that play. Come on: doesn\u2019t it look like he\u2019s traveling every time he gets the ball?<\/P>\n<P>By which we mean, gee, doesn\u2019t it look like this is a very easy way to get back device driver information? <\/P>\n<P>At any rate, we have to go now; it\u2019s time to watch Arizona get beat by Wisconsin. <\/P>\n<P>By which we mean, gee, it must be time to do even <I>more<\/I> work than we usually do \u2026.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I get a list of installed device drivers, their version number, and their date?&#8212; SH Hey, SH. You know, as we\u2019re writing this column the first round of the NCAA men\u2019s basketball tournament is in full swing. But don\u2019t worry: despite the fact that this year\u2019s opening round games are [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[34,35,3,5],"class_list":["post-67723","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-hardware","tag-peripherals-and-devices","tag-scripting-guy","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I get a list of installed device drivers, their version number, and their date?&#8212; SH Hey, SH. You know, as we\u2019re writing this column the first round of the NCAA men\u2019s basketball tournament is in full swing. But don\u2019t worry: despite the fact that this year\u2019s opening round games are [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/67723","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=67723"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/67723\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=67723"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=67723"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=67723"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}