| || |
detecting if USB smart card reader is present
I am trying to detect whether a usb smart card reader is connected to my pc (assume I can't just look). Within a vbs file this is easy, however when I try to adapt the code to run within SQAbasic I come across a problem. VBS can handle a 'for each' loop, SQAbasic apparently can't. I could use a script, but I would rather not as it would be a messy business to return the result of the enquiry to Robot.
The following code works up until I try to assign the first colDevice to objDevice (runtime error 440). According to MSDN, swbemobjectsets do have a itemindex property. I haven't included declarations, but pretty much everything is declared as an object (unless its a string).
<font class="small">Code:</font><hr /><pre>
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colDevices = objWMIService.ExecQuery("Select * From Win32_USBControllerDevice")
dim iTot as long
iTot = coldevices.count
For i = 0 to iTot
'error occurs here
set objdevice = colDevices.itemIndex(i)
strDeviceName = objdevice.dependent
strQuotes = Chr(34)
strDeviceName = FINDandReplace(strDeviceName, strQuotes, "")
Set colUSBDevices = objWMIService.ExecQuery("Select * From Win32_PnPEntity Where DeviceID = '" & strDeviceName & "'")
For ii = 0 to colUSBDevices.count
set objUSBdevice = colUSBDevices.item(ii)
if lcase(objUSBdevice.description) = "usb smart card reader" then
status = 0
The other approach would be to try and combine the two SQL queries into one, then use the coldevices.count to determine if anything had been returned, but I can't get my head around that at the moment.
any help would be much appreciated.
Re: detecting if USB smart card reader is present
Normally, you a get a 440 error when the COM Dll is not registered. That cannot be the case here.
Did you check that the variable objdevice is declared as Object in a separate statement. If you declare two vaiables as objects in the following way...
obj1, obj2 as Object
...the first variable will be treated as a variant.
Also, check if colDevices.itemIndex(i) is indeed an object.
It\'s really not hard to return a result from a vbs
in the vbscript, end with the function
Where Iresult is an integer value.
then call the script from SQABasic like this
<font class="small">Code:</font><hr /><pre> Const WaitOnReturn as integer = True
Dim objShell As Object
Set objShell = CreateObject("wscript.shell")
Iresult = objShell.run(VBSciptPath,,WaitOnReturn )</pre><hr />
Re: It\'s really not hard to return a result from a vbs