Hey, Scripting Guy! How Can I Tell If a Computer Has a SmartCard Reader Attached?

Hey, Scripting Guy! Question


Hey, Scripting Guy! How can I tell if a computer has a SmartCard reader attached?

— TE

SpacerHey, Scripting Guy! AnswerScript Center

Hey, TE. Um, we hate to be rude, TE, but we’re closed today; we only answer questions Monday through Friday. We’d be happy to help you out, but you’re going to have to come back on – what’s that? It is Monday? Wow. Guess that explains why the Scripting Guys are back in Redmond, and back at work to boot.







Note. 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’s not back at work; instead, she’s taking the week off. The Scripting Guy who writes this column was going to complain to his manager about this, except his manager’s taking the week off, too.


If only all Microsoft employees were as devoted to their jobs as the Scripting Guy who writes this column.



But that’s probably just as well. After all, the Scripting Guy who writes this column has never complained about anything before. Why start now?


At any rate, jet lag or no jet lag, today is Monday. And that can mean only one thing: Monday Night Football.


Then again, seeing as how the game won’t 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:

strComputer = “.”

Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2”)

Set colItems = objWMIService.ExecQuery(“Select * From Win32_PnPEntity”)

For Each objItem in colItems
If InStr(LCase(objItem.Description), “smartcard”) Then
Wscript.Echo “Description: ” & objItem.Description
Wscript.Echo “Manufacturer: ” & objItem.Manufacturer
Wscript.Echo “Name: ” & objItem.Name
Wscript.Echo “PNP Device ID: ” & objItem.PNPDeviceID
End If
Next


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 – all together now – “assign the name of that remote computer to the variable strComputer.”


You know, like this:

strComputer = “atl-fs-001”

After connecting to the WMI service, we next use the ExecQuery method and the following line of code to return a collection of all the Plug and Play devices installed on the computer:

Set colItems = objWMIService.ExecQuery(“Select * From Win32_PnPEntity”)

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.


And what exactly are we looking for? That’s easy: we’re looking to see if the Description property contains the string value smartcard. If somewhere along the line we locate a device that has a Description containing the string smartcard then we’re going to assume that the computer has a SmartCard reader attached. If we don’t find such a device then we’ll assume that the computer doesn’t have a SmartCard reader attached.


So how do we carry out this little inspection? Like this:

If InStr(LCase(objItem.Description), “smartcard”) Then

It’s really pretty simple: we’re just using the InStr function to determine whether the string value smartcard appears anywhere in the device Description. To avoid potential confusion between values like SmartCard and smartcard, we also use the LCase function to convert all the characters in the Description to their lowercase equivalent.


If we don’t find the value smartcard 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 is found, then we use this block of code to echo back some of the relevant properties of that device:

Wscript.Echo “Description: ” & objItem.Description
Wscript.Echo “Manufacturer: ” & objItem.Manufacturer
Wscript.Echo “Name: ” & objItem.Name
Wscript.Echo “PNP Device ID: ” & objItem.PNPDeviceID

In turn, that’s going to give us output similar to this:

Description: Texas Instruments PCI GemCore based SmartCard controller
Manufacturer: Texas Instruments
Name: Texas Instruments PCI GemCore based SmartCard controller
PNP Device ID: PCI\VEN_104C&DEV_8035&SUBSYS_308B103C&REV_00\4&1C88B56&0&25A4

We can’t guarantee that this script will be 100% accurate; that’s because we can’t guarantee that 100% of all SmartCard readers include the value smartcard somewhere in their Description. But it’s definitely worth a try.


By the way, you might also find this script handy; it returns information about any SmartCard device drivers installed on the computer:

On Error Resume Next

strComputer = “.”

Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2”)

Set colItems = objWMIService.ExecQuery _
(“Select * From Win32_PnPSignedDriver Where DeviceClass = ‘SMARTCARDREADER'”)

For Each objItem in colItems
Wscript.Echo “Device ID: ” & objItem.DeviceID
Wscript.Echo “Device Name: ” & objItem.DeviceName
Wscript.Echo “Driver Provider Name: ” & objItem.DriverProviderName
Wscript.Echo “Driver Version: ” & objItem.DriverVersion
Wscript.Echo “Hardware ID: ” & objItem.HardWareID
Wscript.Echo “INF Name: ” & objItem.InfName
Wscript.Echo “Manufacturer: ” & objItem.Manufacturer
Wscript.Echo “PDO: ” & objItem.PDO
Wscript.Echo “Signer: ” & objItem.Signer
Next


That script results in output similar to this:

Device ID: PCI\VEN_104C&DEV_8035&SUBSYS_308B103C&REV_00\4&1C88B56&0&25A4
Device Name: Texas Instruments PCI GemCore based SmartCard controller
Driver Provider Name: Gemplus
Driver Version: 1.0.1.15
Hardware ID: PCI\VEN_104C&DEV_8035&SUBSYS_308B103C&REV_00
INF Name: oem19.inf
Manufacturer: Texas Instruments
PDO: \Device\NTPNP_PCI0023
Signer: Microsoft Windows Hardware Compatibility Publisher

As for the Scripting Guy who writes this column, both the jet lag and the wear-and-tear of a busy week at TechE IT Forum are beginning to catch up to him. We’ll see everyone tomorrow.







Note. OK, so maybe he’s not all that jet lagged and not the least bit tired. But this is Monday, remember? You know, Monday Night Football? Need we say any more?


See you tomorrow. Well, assuming anyone besides the Scripting Guy who writes this column is working this week.