forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


USB

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
Dr. Dread
Professional Member
Professional Member


Joined: 03 Aug 2001
Posts: 1065
Location: Copenhagen, Denmark

PostPosted: Sat Jul 18, 2009 12:25 pm    Post subject: USB Reply with quote

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
View user's profile Send private message
Aslan
Valued Contributor
Valued Contributor


Joined: 31 May 2001
Posts: 589
Location: Memphis, TN USA

PostPosted: Sat Jul 18, 2009 3:30 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
vtol
Valued Contributor
Valued Contributor


Joined: 05 Feb 2004
Posts: 622
Location: Indiana

PostPosted: Mon Aug 03, 2009 1:34 am    Post subject: Reply with quote

A VDS DLL named Disk&Mem might help, not sure.
Back to top
View user's profile Send private message Visit poster's website AIM Address
Dr. Dread
Professional Member
Professional Member


Joined: 03 Aug 2001
Posts: 1065
Location: Copenhagen, Denmark

PostPosted: Tue Aug 11, 2009 8:44 am    Post subject: Reply with quote

Hi there!

I was away for holiday so this is slow feedback Cool

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
View user's profile Send private message
Dr. Dread
Professional Member
Professional Member


Joined: 03 Aug 2001
Posts: 1065
Location: Copenhagen, Denmark

PostPosted: Sat Aug 15, 2009 7:44 am    Post subject: Reply with quote

Sorted this one out myself Razz
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
View user's profile Send private message
Aslan
Valued Contributor
Valued Contributor


Joined: 31 May 2001
Posts: 589
Location: Memphis, TN USA

PostPosted: Sat Aug 15, 2009 11:54 pm    Post subject: Reply with quote

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 Question Wink
Back to top
View user's profile Send private message Send e-mail
vdsalchemist
Admin Team


Joined: 23 Oct 2001
Posts: 1448
Location: Florida, USA

PostPosted: Sun Aug 16, 2009 1:57 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
DaveR
Valued Contributor
Valued Contributor


Joined: 03 Sep 2005
Posts: 413
Location: Australia

PostPosted: Sun Aug 16, 2009 8:07 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
vdsalchemist
Admin Team


Joined: 23 Oct 2001
Posts: 1448
Location: Florida, USA

PostPosted: Mon Aug 17, 2009 1:54 pm    Post subject: Reply with quote

Sorry I forgot the quotes didn't I? Wink 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
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Aslan
Valued Contributor
Valued Contributor


Joined: 31 May 2001
Posts: 589
Location: Memphis, TN USA

PostPosted: Mon Aug 17, 2009 11:37 pm    Post subject: Reply with quote

GadgetX customer plug Wink

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 Smile
Back to top
View user's profile Send private message Send e-mail
vdsalchemist
Admin Team


Joined: 23 Oct 2001
Posts: 1448
Location: Florida, USA

PostPosted: Tue Aug 18, 2009 3:10 pm    Post subject: Reply with quote

yep a shameless plug Laughing Razz
_________________
Home of

Give VDS a new purpose!
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Dr. Dread
Professional Member
Professional Member


Joined: 03 Aug 2001
Posts: 1065
Location: Copenhagen, Denmark

PostPosted: Wed Aug 19, 2009 6:28 am    Post subject: Reply with quote

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
View user's profile Send private message
briguy
Contributor
Contributor


Joined: 09 Aug 2007
Posts: 79

PostPosted: Wed Aug 19, 2009 3:35 pm    Post subject: Reply with quote

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
View user's profile Send private message
briguy
Contributor
Contributor


Joined: 09 Aug 2007
Posts: 79

PostPosted: Wed Aug 19, 2009 3:36 pm    Post subject: Reply with quote

Oh I should have read the first post Embarassed
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help All times are GMT
Page 1 of 1

 
Jump to:  
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

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group