+ Reply to Thread
Results 1 to 9 of 9

Retrieve USB Disk Device ID

  1. #1
    Registered User
    Join Date
    11-04-2014
    Location
    India
    MS-Off Ver
    2007
    Posts
    85

    Retrieve USB Disk Device ID

    Hello!

    I found a wonderful article at http://www.myengineeringworld.net/20...n-vba-wmi.html that I modified to get ONLY the device ID of the connected USB disk.

    My question is :
    1. The code takes a while to execute because it finds all usb connections and I need to make it real quick. How can it be modified further to loop through only disk/storage devices as I do not want any other services like HidUsb, usbhub, mouhid or other info such as name, manufacturer, status etc.
    2. It prefixes additional info such as 'USB\VID_1058&PID_1023\'. How can I strip it off to get only the device ID?
    3. How to convert it in a function that will return the device ID - This function can be invoked on all onClick events of other buttons to check the usb drive is connected to the computer. Eg. If chkUsb = "0123456789" Then

    To conclude: I need to ensure that the USB drive is connected to the system at all times and if it is not, the other buttons in the vba program will not work.

    Thanks.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Retrieve USB Disk Device ID

    When you email the author of that code, post back his response in this thread, it will be useful information.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,997

    Re: Retrieve USB Disk Device ID

    If you know what the DeviceID property should end with (i.e. the last part of the string returned is the bit you want), you can use a function like this:
    Please Login or Register  to view this content.
    Everyone who confuses correlation and causation ends up dead.

  4. #4
    Registered User
    Join Date
    11-04-2014
    Location
    India
    MS-Off Ver
    2007
    Posts
    85

    Re: Retrieve USB Disk Device ID

    Quote Originally Posted by romperstomper View Post
    If you know what the DeviceID property should end with (i.e. the last part of the string returned is the bit you want), you can use a function like this:
    Thank you for your reply... Not sure if I have understood you correctly. This is what I tried. however, when I run the try sub routine, the function returns FALSE in both conditions
    Please Login or Register  to view this content.

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,997

    Re: Retrieve USB Disk Device ID

    It must be a different deviceID then. I will locate a USB stick, run the original code and see which property is equivalent if possible.

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,997

    Re: Retrieve USB Disk Device ID

    This seems to use the same DeviceID:
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    11-04-2014
    Location
    India
    MS-Off Ver
    2007
    Posts
    85

    Re: Retrieve USB Disk Device ID

    Hey... Super ! Thank you !!
    I am very keen to research more on how to make a particular vba code run only on a specified computer by validating the motherboard id, processor id etc. (again, not an efficient method as there is scope of cracking the code and removing validation. however, yes.. effective though!)

    While I was searching for the property you asked for, I stumbled upon few links which I thought was worthwhile. Following are few links I bookmarked that are worth a watch.
    http://blogs.technet.com/b/heyscript...-computer.aspx
    http://www.codeproject.com/Articles/...ID-MainBoard-I
    http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
    http://www.vbsedit.com/scripts/misc/wmi/scr_1332.asp
    http://www.vbsedit.com/scripts/misc/wmi/scr_1333.asp

    I thank you very very much for the kind assistance. God bless !

  8. #8
    Registered User
    Join Date
    11-04-2014
    Location
    India
    MS-Off Ver
    2007
    Posts
    85

    Re: Retrieve USB Disk Device ID

    Quote Originally Posted by JBeaucaire View Post
    When you email the author of that code, post back his response in this thread, it will be useful information.
    Yes! Indeed it will be useful... I haven't got a reply yet. I will post it once I get it. The issue is resolved though!

  9. #9
    Registered User
    Join Date
    11-04-2014
    Location
    India
    MS-Off Ver
    2007
    Posts
    85

    Re: Retrieve USB Disk Device ID

    Quote Originally Posted by JBeaucaire View Post
    When you email the author of that code, post back his response in this thread, it will be useful information.
    Here is a reply from the author:

    Option Explicit

    Please Login or Register  to view this content.
    Note that I haven’t test the function thoroughly.
    However, a quick test that I did with an external USB hard drive (WD My Passport 0748 USB Device) worked.
    So, in my test, I checked for the above device like this (in the immediate window of the VBA editor):
    ?IsUSBConnected("USBSTOR\DISK&VEN_WD&PROD_MY_PASSPORT_0748&REV_1016\575846314536324548525239&0")

    By the way, the function can work even with a partial device ID.
    Example:
    ?IsUSBConnected("PROD_MY_PASSPORT")

    I hope it helps!

    Best Regards,
    Christos

    PS: The function by @Rory (romperstomper) is also working....

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Cannot format usb disk drive because of i/o device error
    By 1tane1 in forum Microsoft Windows Help
    Replies: 2
    Last Post: 07-24-2014, 01:13 AM
  2. Replies: 1
    Last Post: 03-06-2014, 12:49 AM
  3. Replies: 1
    Last Post: 04-04-2006, 04:40 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1