Page 1 of 1 1
Topic Options
#92137 - 2003-06-11 07:52 PM Detecting USB/Parallel port devices
Ganiman Offline
Fresh Scripter

Registered: 2003-06-10
Posts: 23
Loc: Rhode Island
I'm trying to write a script that will find if a machine has any USB and/or parallel port devices attached to it. I'd like to get the devices name as it would be shown in device manager, but can't seem to figure this one out. I can find devices by having Kix look to see if a driver is installed, but I would have to write code for every possible driver I can think of; that would not be fun, or the "right" way, and I would not get a the model of every device. I'm trying to find things like PDAs, scanners, card scan machines and digital cameras. I'm aware that some of these devices may not always show up in device manager unless they are plugged in, which is fine. I've been trying to use WMIQuery to find them (in conjunction with what I find at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_classes.asp), but I am having a difficult time. I've even tried looking for a list of TWAIN devices... but no luck their either. There must be a way to do this if other software such as Omnipage Pro or Adobe Photoshop can find if a TWAIN device is installed. I've even searched kixtart.org and it appears to me that either I am the only one who can't do this on his own, or no one else has tried it yet. Any help is much appreciated.
_________________________
Ganiman

Top
#92138 - 2003-06-11 11:44 PM Re: Detecting USB/Parallel port devices
Stevie Offline
Starting to like KiXtart
*****

Registered: 2002-01-09
Posts: 199
Haven't done it myself. A possible avenue of exploration is the Win32_USBControllerDevice object. One of its return values is a CIM_LogicalDevice object which should be a pointer to a USB device.
_________________________
Stevie

Top
#92139 - 2003-06-12 01:43 AM Re: Detecting USB/Parallel port devices
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
try driveenum() UDF and look for removable drives.
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#92140 - 2003-06-12 03:30 PM Re: Detecting USB/Parallel port devices
Ganiman Offline
Fresh Scripter

Registered: 2003-06-10
Posts: 23
Loc: Rhode Island
I've looked at the Win32_USBControllerDevice and haven't had too much success in using it to tell me what USB devices are plugged in. Maybe I'm just using it wrong? What about parallel devices? There must be some way to retrieve devices in the same way that device manager lists them. I've looked in the registry, but can't come up with anything there. I could just be looking the wrong way though. Device manager is just another application that collects information, but from where?
_________________________
Ganiman

Top
#92141 - 2003-06-12 03:47 PM Re: Detecting USB/Parallel port devices
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\DeviceClasses

HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices

but neither one is pretty...
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#92142 - 2003-06-12 03:51 PM Re: Detecting USB/Parallel port devices
Ganiman Offline
Fresh Scripter

Registered: 2003-06-10
Posts: 23
Loc: Rhode Island
[after looking at those keys] Yuck, yuck a more yuck. [Embarrassed] Perhaps there is some small third party piece of software that will return some nice values?? I hate using stuff like that, but it might make this a lot easier.
_________________________
Ganiman

Top
#92143 - 2003-06-12 04:19 PM Re: Detecting USB/Parallel port devices
Ganiman Offline
Fresh Scripter

Registered: 2003-06-10
Posts: 23
Loc: Rhode Island
Well, after doing some more fiddling around with this.. I decided to try something like this (in use with WMIQuery)

code:
$oldArray = WMIQuery("Name","Win32_PnPEntity")
$index = 0
For Each $temp In $oldArray
? $oldArray[$index]
$index = $index + 1
Next

It pretty much gives a listing of every device you might find in device manager (or something close to it). It gave me way more than just USB and Parallel port devices. But, it did include those devices. I could write some kind of filter on this to find pull out what I need. Try it out, it is fuuuuuuuuuuuuuuuuun.
_________________________
Ganiman

Top
#92144 - 2003-06-12 04:44 PM Re: Detecting USB/Parallel port devices
Ganiman Offline
Fresh Scripter

Registered: 2003-06-10
Posts: 23
Loc: Rhode Island
{starting to feel like I'm the only paying any more attention to this thread} [Roll Eyes]

I've really come up with something good here. I've found a way to find all USB devices attached to a machine! Next, onto Parallel devices.

code:
$myArray = WMIQuery("PNPDeviceID","Win32_PnPEntity")
$oldArray = WMIQuery("Description","Win32_PnPEntity")
$index = 0
For Each $temp In $oldArray
If (InStr($myArray[$index], "USB"))
? $oldArray[$index]
;? $myArray[$index]
EndIf
$index = $index + 1
Next

If you uncomment the
code:
;? $myArray[$index]

it will print out to the screen the actual device ID as well. Not needed in my case, but was used for testing purposes. Now I should turn this into a nice function and post it in the UDF.
_________________________
Ganiman

Top
#92145 - 2003-06-12 04:49 PM Re: Detecting USB/Parallel port devices
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
I don't know if the WMI enumerator can handle wildcards in the 'sql statement' but you can try:

$myArray = WMIQuery("PNPDeviceID","Win32_PnPEntity",,"Description","*USB*")

[ 12. June 2003, 16:50: Message edited by: Radimus ]
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#92146 - 2003-06-12 05:27 PM Re: Detecting USB/Parallel port devices
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
i've modified WMIQuery a little, to apply a filter to the result. but it isn't compatable to old version. So a made a new UDF
code:
$myArray = WMIQueryfilter("Description","Win32_PnPEntity",,"USB")
for each $device in $myArray
? $device
next




;****************************************************************************************************
FUNCTION WMIQueryfilter($what,$from,optional $computer,optional $where)
dim $strQuery, $objEnumerator, $value, $item, $ubound
dim $temp[0]

$strQuery = "Select " + $what + " From "+ $from
if not $computer $computer="@WKSTA" endif

$SystemSet = GetObject("winmgmts:{impersonationLevel=impersonate}!//$computer")
$objEnumerator = $SystemSet.ExecQuery($strQuery)
if @error exit 1 return endif

For Each $objInstance in $objEnumerator
If @Error = 0 and $objInstance <> ""
$=execute("$$value = $$objInstance.$what")
Select
case VarType($value) & 8192
for each $item in $value
$ubound = ubound($temp)
if instr($item,$where)
if $temp[$ubound] >' '
$ubound = $ubound +1
redim preserve $temp[$ubound]
endif
$temp[$ubound] = $item
endif
next
case 1
$ubound = ubound($temp)
if instr($value,$where)
if $temp[$ubound] >' '
$ubound = $ubound +1
redim preserve $temp[$ubound]
endif
$temp[$ubound] = $value
endif
EndSelect
EndIf
Next
$WMIQueryfilter = $temp
ENDFUNCTION

_________________________
How to ask questions the smart way <-----------> Before you ask

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 781 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.056 seconds in which 0.021 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org