View previous topic :: View next topic |
Author |
Message |
Dr. Dread Professional Member
Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Sat Jul 18, 2009 12:25 pm Post subject: USB |
|
|
Hi there!
Does anyone know if there is a way of uniquely identifying a USB drive?
There's a serial, but that one can be changed faírly easily, I think.
PNPDeviceID is not available from all USB sticks.
Greetz
Dread _________________ ~~ Alcohol and calculus don't mix... Don't drink and derive! ~~
String.DLL * advanced string processing |
|
Back to top |
|
|
Aslan Valued Contributor
Joined: 31 May 2001 Posts: 589 Location: Memphis, TN USA
|
Posted: Sat Jul 18, 2009 3:30 pm Post subject: |
|
|
You should always get a unique value for either PNPDeviceID or DeviceID or both are the same. If you do not, then the manufacturer of the device has improperly coded it and could be considered suspicious.
Dr. Dread wrote: | There's a serial, but that one can be changed faírly easily, I think.
| I don't think this can be changed.
On my network of over 1200 machines we have almost 50% of them using external USB devices (not including mice and keyboards). All of these devices have a UID which are queried from either PNPDeviceID or DeviceID. The only exception was a couple of USB floppy drives from the same manufacturer which are disallowed and blocked from use on our network.
On a side note, it seems that a lot of flash drives show as CD-ROM under "Description". This is encoded at the manufacturer and not determined by the OS. Just a guess, but maybe in the past they needed to encode them that way for the BIOS to consider them bootable. |
|
Back to top |
|
|
vtol Valued Contributor
Joined: 05 Feb 2004 Posts: 642 Location: Eastern Indiana
|
Posted: Mon Aug 03, 2009 1:34 am Post subject: |
|
|
A VDS DLL named Disk&Mem might help, not sure. |
|
Back to top |
|
|
Dr. Dread Professional Member
Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Tue Aug 11, 2009 8:44 am Post subject: |
|
|
Hi there!
I was away for holiday so this is slow feedback
Thanks for the input.
DiskNMem is my own DLL and it doesn't deal with this.
Disk serial is readily available through @volinfo but it's changeable - I believe that there's a small
Sysinternals util which will do that easily.
I can obtain a DevideID through WMI but it gives me some trouble. I have to enumerate all devices and
then pick out the USB ones. But if more devices are connected it's tricky to map each device to a drive letter
to find out which one is the correct drive.
If anyone has got some clue here, I'd be grateful.
Greetz
Dread _________________ ~~ Alcohol and calculus don't mix... Don't drink and derive! ~~
String.DLL * advanced string processing |
|
Back to top |
|
|
Dr. Dread Professional Member
Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Sat Aug 15, 2009 7:44 am Post subject: |
|
|
Sorted this one out myself
Got it working - in a Delphi DLL though. Tricky stuff.
Greetz
Dread _________________ ~~ Alcohol and calculus don't mix... Don't drink and derive! ~~
String.DLL * advanced string processing |
|
Back to top |
|
|
Aslan Valued Contributor
Joined: 31 May 2001 Posts: 589 Location: Memphis, TN USA
|
Posted: Sat Aug 15, 2009 11:54 pm Post subject: |
|
|
Not sure why you are enumerating all USB devices. Just USBSTOR devices should be sufficeint.
This WMI query will only give you a list of USB Storage devices ie. USB stick, ext HD, iPod, etc...
Code: | strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"Select * From CIM_LogicalDevice Where PNPDeviceID like 'USBSTOR%'")
For Each objItem in colItems
Wscript.Echo "-----------------------------------"
Wscript.Echo "CIM_LogicalDevice instance"
Wscript.Echo "-----------------------------------"
Wscript.Echo "Caption: " & objItem.Caption
Wscript.Echo "Description: " & objItem.Description
Wscript.Echo "DeviceID: " & objItem.DeviceID
Wscript.Echo "Name: " & objItem.Name
Wscript.Echo "PNPDeviceID: " & objItem.PNPDeviceID
Next |
Care to share your Delphi solution |
|
Back to top |
|
|
vdsalchemist Admin Team
Joined: 23 Oct 2001 Posts: 1448 Location: Florida, USA
|
Posted: Sun Aug 16, 2009 1:57 am Post subject: |
|
|
I am sure the Delphi is not much different. WMI is WMI regardless of the language. Below is the GadgetX code to do this.
Code: |
#-----------------------------------------------------------------------------#
# #
# This is an example of using WMI to place the list of Devices and their #
# paths in a VDS TABLE element. #
# #
# Author: Johnny Kinsey #
# #
#-----------------------------------------------------------------------------#
Title Device List VIA WMI
If @Greater(@Name(@SYSINFO(DSVER)),4)
External GadgetX.dll,@SYSINFO(DSVER)
# GadgetX Commands
#DEFINE COMMAND,GadgetX,DEFINE,OLE,Set
# GadgetX Functions
#DEFINE FUNCTION,GadgetX,OLE,Get
Else
Warn This Example uses VDS 5 or above syntax.
Stop
End
# Objects needed to get the device list
Define variable,Object,objWMI
Define variable,Object,objDevices
Define variable,Object,objDevice
# A collection that will hold the list of devices
Define variable,Collection,colDevices
# Initialize Ole
Ole Init
# Get the local WMI object
Set objWMI,@Ole(GetObject,NULL,"winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
# Create our dialog
DIALOG CREATE,Get Device List VIA WMI,-1,0,381,243
REM *** Modified by Dialog Designer on 3/6/2007 - 09:48 ***
DIALOG ADD,BUTTON,getbtn,204,82,64,24,Devices
DIALOG ADD,BUTTON,QUIT,205,250,64,24,Quit
DIALOG ADD,TEXT,TEXT1,19,41,80,13,Installed devices
DIALOG ADD,TABLE,TABLE1,34,39,310,161,Name[120]|Path
DIALOG SHOW
:evloop
Repeat
wait event
%E = @event()
If %E
gosub %E
End
Until @equal(%E,CLOSE)@equal(%E,QUITBUTTON)
Exit
:QUITBUTTON
:CLOSE
Ole Free,Object,objWMI
Ole UnInit
Exit
:GETBTNBUTTON
List clear,TABLE1
# Query for the logical devices
Set objDevices,@Ole(Call,objWMI,^o,"ExecQuery(^B)","Select * From CIM_LogicalDevice Where PNPDeviceID like 'USBSTOR%'")
# get the device collection
Set colDevices,@Ole(BeginCollection,objDevices)
# Walk through the collection
While @Ole(Next,objDevice,In,colDevices)
# Get the name of the device
%%Name = @Ole(Get,objDevice,"^B",Name)
# Get the PNPDevice path
%%DeviceID = @Ole(Get,objDevice,"^B",PNPDeviceID)
# Add the Name and Path to our table.
List Add,TABLE1,%%Name@Tab()%%DeviceID
Wend
# Free the collection
Ole Free,Collection,colDevices
# Free the objDevices object
Ole Free,Object,objDevices
# All done so go back to the event loop
Exit
|
Also if you have a USB stick that is not PNP compatible I would suggest you throw it away and by a new one that is. IMHO It's the PNP that makes a USB stick really useful. _________________ Home of
Give VDS a new purpose!
Last edited by vdsalchemist on Mon Aug 17, 2009 2:09 pm; edited 1 time in total |
|
Back to top |
|
|
DaveR Valued Contributor
Joined: 03 Sep 2005 Posts: 413 Location: Australia
|
Posted: Sun Aug 16, 2009 8:07 am Post subject: |
|
|
dragonsphere wrote: | Code: |
# Query for the logical devices
Set objDevices,@Ole(Call,objWMI,^o,"ExecQuery(^B)",Select * From CIM_LogicalDevice Where PNPDeviceID like 'USBSTOR%') |
|
Is the "Select * From CIM_LogicalDevice Where PNPDeviceID like 'USBSTOR%')" line supposed to be a comment, or a hint as to what needs to be put in there?
EDIT Never mind, I just enclosed it in double quotes and it worked without error. Though I have no idea that line means. Code: |
# Query for the logical devices
Set objDevices,@Ole(Call,objWMI,^o,"ExecQuery(^B)","Select * From CIM_LogicalDevice Where PNPDeviceID like 'USBSTOR%'") |
_________________ cheers
Dave |
|
Back to top |
|
|
vdsalchemist Admin Team
Joined: 23 Oct 2001 Posts: 1448 Location: Florida, USA
|
Posted: Mon Aug 17, 2009 1:54 pm Post subject: |
|
|
Sorry I forgot the quotes didn't I? I fixed my post above and added the double quotes.
What this does is query WMI for all the logical devices where the PNPDeviceID property has the word USBSTOR as part of it. The % is a wildcard. It then saves the results of that query into a collection of objects that represent each Device with the word USBSTOR as a GadgetX variable called objDevices. The loop below that walks each object in the collection and pulls out the requested information and adds that information to the VDS table in the dialog. _________________ Home of
Give VDS a new purpose!
|
|
Back to top |
|
|
Aslan Valued Contributor
Joined: 31 May 2001 Posts: 589 Location: Memphis, TN USA
|
Posted: Mon Aug 17, 2009 11:37 pm Post subject: |
|
|
GadgetX customer plug
As far as PNP devices go, GadgetX is also capable of receiving WMI notifications when a device is inserted.
In my case this has proven more efficient than using API and easier to code.
I still would like to see the Delphi code for my own education |
|
Back to top |
|
|
vdsalchemist Admin Team
Joined: 23 Oct 2001 Posts: 1448 Location: Florida, USA
|
Posted: Tue Aug 18, 2009 3:10 pm Post subject: |
|
|
yep a shameless plug _________________ Home of
Give VDS a new purpose!
|
|
Back to top |
|
|
Dr. Dread Professional Member
Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Wed Aug 19, 2009 6:28 am Post subject: |
|
|
Yeah, I used WMI in Delphi also to do the job. The hard part was not WMI as such but obtaining
the device ID only from a specific drive letter. As far as I have been able to tell there is no direct
way of retrieving that info. Had to do it in a series of 3 WCI queries.
Win32_LogicalDiskToPartition->
Win32_DiskDriveToDiskPartition ->
Win32_DiskDrive
Greetz
Dread _________________ ~~ Alcohol and calculus don't mix... Don't drink and derive! ~~
String.DLL * advanced string processing |
|
Back to top |
|
|
briguy Contributor
Joined: 09 Aug 2007 Posts: 79
|
Posted: Wed Aug 19, 2009 3:35 pm Post subject: |
|
|
A very raw and maybe somewhat flawed piece of code but take a look. If you have a usb drive or thumb drive inserted it will retreave the serial number. Is that what everyone is trying to do..
Code: |
DIALOG CREATE,Device Change2,-1,0,379,269
DIALOG ADD,LIST,LIST1,7,8,358,249
dialog SHOW
#this section will find all Fixed, CD-ROM, Removable and RAM drives on system
%%drive = 64
repeat
%%drive = @sum(%%Drive,1)
%%driveletter = @chr(%%Drive)
if @equal(Fixed,@VOLINFO(%%driveletter,T))@equal(CD-ROM,@VOLINFO(%%driveletter,T))@equal(Removable,@VOLINFO(%%driveletter,T))@equal(RAM,@VOLINFO(%%driveletter,T))
%%f = 1
%%volinfo = @VOLINFO(%%driveletter,TNSFYZ)
PARSE "%%T;%%N;%%S;%%F;%%Y;%%Z", %%volinfo
list add,list1, @chr(%%Drive) - %%volinfo
If @null(%%S)
info null @chr(%%Drive) - %%volinfo
else
info do some thing like scan @chr(%%Drive) - %%volinfo
end
end
until @equal(%%Drive,90)
wait 10
|
|
|
Back to top |
|
|
briguy Contributor
Joined: 09 Aug 2007 Posts: 79
|
Posted: Wed Aug 19, 2009 3:36 pm Post subject: |
|
|
Oh I should have read the first post |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|