{"id":63553,"date":"2007-11-19T03:50:00","date_gmt":"2007-11-19T03:50:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2007\/11\/19\/hey-scripting-guy-how-can-i-tell-if-a-computer-has-a-smartcard-reader-attached\/"},"modified":"2007-11-19T03:50:00","modified_gmt":"2007-11-19T03:50:00","slug":"hey-scripting-guy-how-can-i-tell-if-a-computer-has-a-smartcard-reader-attached","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-how-can-i-tell-if-a-computer-has-a-smartcard-reader-attached\/","title":{"rendered":"Hey, Scripting Guy! How Can I Tell If a Computer Has a SmartCard Reader Attached?"},"content":{"rendered":"<p><H2><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\"> <\/H2>\n<P>Hey, Scripting Guy! How can I tell if a computer has a SmartCard reader attached?<BR><BR>&#8212; TE<\/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, TE. Um, we hate to be rude, TE, but we\u2019re closed today; we only answer questions Monday through Friday. We\u2019d be happy to help you out, but you\u2019re going to have to come back on \u2013 what\u2019s that? It <I>is<\/I> Monday? Wow. Guess that explains why the Scripting Guys are back in Redmond, and back at work to boot. <\/P>\n<TABLE id=\"E6C\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P><B>Note<\/B>. Well, it explains why the Scripting Guy who writes this column is back in Redmond and back at work. Scripting Guy Jean Ross is back in Redmond, too but she\u2019s <I>not<\/I> back at work; instead, <I>she\u2019s<\/I> taking the week off. The Scripting Guy who writes this column was going to complain to his manager about this, except his manager\u2019s taking the week off, too.<\/P>\n<P>If only <I>all<\/I> Microsoft employees were as devoted to their jobs as the Scripting Guy who writes this column.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>But that\u2019s probably just as well. After all, the Scripting Guy who writes this column has never complained about anything before. Why start now?<\/P>\n<P>At any rate, jet lag or no jet lag, today <I>is<\/I> Monday. And that can mean only one thing: Monday Night Football.<\/P>\n<P>Then again, seeing as how the game won\u2019t start for a few more hours, we might as well see if we can put together a script that will tell you whether or not a computer has a SmartCard reader attached:<\/P><PRE class=\"codeSample\">strComputer = &#8220;.&#8221;<\/p>\n<p>Set objWMIService = GetObject(&#8220;winmgmts:\\\\&#8221; &amp; strComputer &amp; &#8220;\\root\\cimv2&#8221;)<\/p>\n<p>Set colItems = objWMIService.ExecQuery(&#8220;Select * From Win32_PnPEntity&#8221;)<\/p>\n<p>For Each objItem in colItems\n    If InStr(LCase(objItem.Description), &#8220;smartcard&#8221;) Then\n        Wscript.Echo &#8220;Description: &#8221; &amp; objItem.Description\n        Wscript.Echo &#8220;Manufacturer: &#8221; &amp; objItem.Manufacturer\n        Wscript.Echo &#8220;Name: &#8221; &amp; objItem.Name\n        Wscript.Echo &#8220;PNP Device ID: &#8221; &amp; objItem.PNPDeviceID\n    End If\nNext\n<\/PRE>\n<P>We start things out by connecting to the WMI service on the local computer. Can you use this same script to determine whether a SmartCard reader is installed on a remote computer? You bet you can; all you have to do is \u2013 all together now \u2013 \u201cassign the name of that remote computer to the variable strComputer.\u201d<\/P>\n<P>You know, like this:<\/P><PRE class=\"codeSample\">strComputer = &#8220;atl-fs-001&#8221;\n<\/PRE>\n<P>After connecting to the WMI service, we next use the <B>ExecQuery<\/B> method and the following line of code to return a collection of all the Plug and Play devices installed on the computer:<\/P><PRE class=\"codeSample\">Set colItems = objWMIService.ExecQuery(&#8220;Select * From Win32_PnPEntity&#8221;)\n<\/PRE>\n<P>From there we set up a For Each loop to loop through all the items in the collection, giving us an opportunity to take a closer look at each of these devices.<\/P>\n<P>And what exactly are we looking for? That\u2019s easy: we\u2019re looking to see if the <B>Description<\/B> property contains the string value <I>smartcard<\/I>. If somewhere along the line we locate a device that has a Description containing the string <I>smartcard<\/I> then we\u2019re going to assume that the computer has a SmartCard reader attached. If we <I>don\u2019t<\/I> find such a device then we\u2019ll assume that the computer <I>doesn\u2019t<\/I> have a SmartCard reader attached.<\/P>\n<P>So how do we carry out this little inspection? Like this:<\/P><PRE class=\"codeSample\">If InStr(LCase(objItem.Description), &#8220;smartcard&#8221;) Then\n<\/PRE>\n<P>It\u2019s really pretty simple: we\u2019re just using the <B>InStr<\/B> function to determine whether the string value <I>smartcard<\/I> appears anywhere in the device Description. To avoid potential confusion between values like <I>SmartCard<\/I> and <I>smartcard<\/I>, we also use the <B>LCase<\/B> function to convert all the characters in the Description to their lowercase equivalent.<\/P>\n<P>If we don\u2019t find the value <I>smartcard<\/I> then we simply zip back to the beginning of the loop and repeat the process with the next device in the collection. If the value <I>is<\/I> found, then we use this block of code to echo back some of the relevant properties of that device:<\/P><PRE class=\"codeSample\">Wscript.Echo &#8220;Description: &#8221; &amp; objItem.Description\nWscript.Echo &#8220;Manufacturer: &#8221; &amp; objItem.Manufacturer\nWscript.Echo &#8220;Name: &#8221; &amp; objItem.Name\nWscript.Echo &#8220;PNP Device ID: &#8221; &amp; objItem.PNPDeviceID\n<\/PRE>\n<P>In turn, that\u2019s going to give us output similar to this:<\/P><PRE class=\"codeSample\">Description: Texas Instruments PCI GemCore based SmartCard controller\nManufacturer: Texas Instruments\nName: Texas Instruments PCI GemCore based SmartCard controller\nPNP Device ID: PCI\\VEN_104C&amp;DEV_8035&amp;SUBSYS_308B103C&amp;REV_00\\4&amp;1C88B56&amp;0&amp;25A4\n<\/PRE>\n<P>We can\u2019t guarantee that this script will be 100% accurate; that\u2019s because we can\u2019t guarantee that 100% of all SmartCard readers include the value <I>smartcard<\/I> somewhere in their Description. But it\u2019s definitely worth a try.<\/P>\n<P>By the way, you might also find this script handy; it returns information about any SmartCard device drivers installed on the computer:<\/P><PRE class=\"codeSample\">On Error Resume Next<\/p>\n<p>strComputer = &#8220;.&#8221;<\/p>\n<p>Set objWMIService = GetObject(&#8220;winmgmts:\\\\&#8221; &amp; strComputer &amp; &#8220;\\root\\cimv2&#8221;)<\/p>\n<p>Set colItems = objWMIService.ExecQuery _\n    (&#8220;Select * From Win32_PnPSignedDriver Where DeviceClass = &#8216;SMARTCARDREADER'&#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    Wscript.Echo &#8220;Driver Provider Name: &#8221; &amp; objItem.DriverProviderName\n    Wscript.Echo &#8220;Driver Version: &#8221; &amp; objItem.DriverVersion\n    Wscript.Echo &#8220;Hardware ID: &#8221; &amp; objItem.HardWareID\n    Wscript.Echo &#8220;INF Name: &#8221; &amp; objItem.InfName\n    Wscript.Echo &#8220;Manufacturer: &#8221; &amp; objItem.Manufacturer\n    Wscript.Echo &#8220;PDO: &#8221; &amp; objItem.PDO\n    Wscript.Echo &#8220;Signer: &#8221; &amp; objItem.Signer\n Next\n<\/PRE>\n<P>That script results in output similar to this:<\/P><PRE class=\"codeSample\">Device ID: PCI\\VEN_104C&amp;DEV_8035&amp;SUBSYS_308B103C&amp;REV_00\\4&amp;1C88B56&amp;0&amp;25A4\nDevice Name: Texas Instruments PCI GemCore based SmartCard controller\nDriver Provider Name: Gemplus\nDriver Version: 1.0.1.15\nHardware ID: PCI\\VEN_104C&amp;DEV_8035&amp;SUBSYS_308B103C&amp;REV_00\nINF Name: oem19.inf\nManufacturer: Texas Instruments\nPDO: \\Device\\NTPNP_PCI0023\nSigner: Microsoft Windows Hardware Compatibility Publisher\n<\/PRE>\n<P>As for the Scripting Guy who writes this column, both the jet lag and the wear-and-tear of a busy week at <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/topics\/teched07\/eu.mspx\"><B>TechE IT Forum<\/B><\/A> are beginning to catch up to him. We\u2019ll see everyone tomorrow.<\/P>\n<TABLE id=\"EHG\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P><B>Note<\/B>. OK, so maybe he\u2019s not all <I>that<\/I> jet lagged and not the least bit tired. But this is Monday, remember? You know, Monday Night Football? Need we say any more?<\/P>\n<P>See you tomorrow. Well, assuming anyone besides the Scripting Guy who writes this column is working this week.<\/P><\/TD><\/TR><\/TBODY><\/TABLE><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I tell if a computer has a SmartCard reader attached?&#8212; TE Hey, TE. Um, we hate to be rude, TE, but we\u2019re closed today; we only answer questions Monday through Friday. We\u2019d be happy to help you out, but you\u2019re going to have to come back on \u2013 what\u2019s that? [&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-63553","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 tell if a computer has a SmartCard reader attached?&#8212; TE Hey, TE. Um, we hate to be rude, TE, but we\u2019re closed today; we only answer questions Monday through Friday. We\u2019d be happy to help you out, but you\u2019re going to have to come back on \u2013 what\u2019s that? [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/63553","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=63553"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/63553\/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=63553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=63553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=63553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}