473,408 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Get USB serial number

pentahari
It is very URGENT.

How to get the USB serial no using VB6.
Jul 19 '08 #1
5 7632
Solution :

Expand|Select|Wrap|Line Numbers
  1. Function GetUSBSerialNo(ByVal DriveLetter As String)
  2.     Dim PnPID As String
  3.     PnPID = USBSerialNo(DriveLetter)
  4.  
  5.     If Not Trim(PnPID) = "" Then
  6.         GetUSBSerialNo = formatSerialNo(PnPID)
  7.     Else
  8.         GetUSBSerialNo = ""
  9.    End If
  10.  
  11. End Function
  12.  
  13.  
  14. Function USBSerialNo(ByVal DriveLetter As String)
  15.  
  16. Dim objFSO
  17. Dim objFolder
  18. Dim Directory
  19. Const OverwriteExisting = True
  20.  
  21. Dim SerialNo As String
  22.  
  23. Dim ComputerName
  24. ComputerName = "."
  25. Dim wmiServices, wmiDiskDrives, wmiDiskDrive, query, wmiDiskPartitions, wmiDiskPartition, wmiLogicalDisks, wmiLogicalDisk
  26.  
  27. Set wmiServices = GetObject( _
  28.     "winmgmts:{impersonationLevel=Impersonate}!//" _
  29.     & ComputerName)
  30.  
  31. Set wmiDiskDrives = wmiServices.ExecQuery("SELECT Caption, DeviceID,PNPDeviceID FROM Win32_DiskDrive")
  32.  
  33. For Each wmiDiskDrive In wmiDiskDrives
  34.  
  35.     SerialNo = wmiDiskDrive.PNPDeviceID '1
  36.  
  37.  query = "ASSOCIATORS OF {Win32_DiskDrive.DeviceID='" _
  38.         & wmiDiskDrive.deviceid & "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition"
  39.     Set wmiDiskPartitions = wmiServices.ExecQuery(query)
  40.  
  41.     For Each wmiDiskPartition In wmiDiskPartitions
  42.         Set wmiLogicalDisks = wmiServices.ExecQuery _
  43.             ("ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" _
  44.              & wmiDiskPartition.deviceid & "'} WHERE AssocClass = Win32_LogicalDiskToPartition")
  45.  
  46.         For Each wmiLogicalDisk In wmiLogicalDisks
  47.  
  48.         If (wmiLogicalDisk.deviceid = DriveLetter) And (wmiLogicalDisk.DriveType = 2) Then '2
  49.             USBSerialNo = SerialNo
  50.             Exit Function
  51.         End If
  52.  
  53.         Next
  54.     Next
  55. Next
  56. End Function
  57.  
  58.  
  59. Function formatSerialNo(ByVal PnPID As String)
  60.     Dim arrSerialNo
  61.     Dim arrSerialNo1
  62.     arrSerialNo = Split(PnPID, "\")
  63.     Dim i
  64.     arrSerialNo1 = Split(arrSerialNo(UBound(arrSerialNo)), "&")
  65.  
  66.     If UBound(arrSerialNo1) > 0 Then
  67.         formatSerialNo = arrSerialNo1(UBound(arrSerialNo1) - 1)
  68.     Else
  69.         formatSerialNo = arrSerialNo1(UBound(arrSerialNo1))
  70.     End If
  71.  
  72. End Function
  73.  
Jul 30 '08 #2
9815402440
180 100+
hi
i also tried the code but it is giving an automation error on following line

Set wmiServices = GetObject("winmgmts:{impersonationLevel=Impersonat e}!//" & ComputerName)

can you please tell if there are any references that must be added to run this code.

thanks
regards
manpreet singh dhillon hoshiarpur
Aug 2 '08 #3
hi
i also tried the code but it is giving an automation error on following line

Set wmiServices = GetObject("winmgmts:{impersonationLevel=Impersonat e}!//" & ComputerName)

can you please tell if there are any references that must be added to run this code.

thanks
regards
manpreet singh dhillon hoshiarpur
what OS are you use?

Easy to get the USB serial no in .Net
Please follow the below URL.

http://home.hot.rr.com/graye/Article...ialNumbers.htm
Aug 9 '08 #4
9815402440
180 100+
hi
thanx for the reply
i am using vb6 and operating system is WinXP
i tried the link suggested by you. but that is for .net.
please help why the specified line gives run time error
regards
manpreet singh dhillon hoshiarpur
Aug 11 '08 #5
hi
thanx for the reply
i am using vb6 and operating system is WinXP
i tried the link suggested by you. but that is for .net.
please help why the specified line gives run time error
regards
manpreet singh dhillon hoshiarpur
I don't know, i have given references:
Visual basic for applications
Visual basic runtime objects and procedures
Visual basic objects and procedures
OLE Automation
Microsoft ActiveX Data objects 2.0 Library

my friend say:
Have you checked whether or not WMI is permitted on the machine?
Aug 11 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: Gavin | last post by:
Hi, I'm a newbie to programming of any kind. I have posted this to other groups in a hope to get a response from anyone. Can any one tell me how to make my VB program read the Bios serial number...
15
by: tom | last post by:
Hi, How do I get the serial number of the harddisk in .NET? I want this to be the same number even if the user has reformatted, so I do not want the volume serial number. Thanx, t
5
by: | last post by:
Hi, Do memory sticks have serial numbers like harddrives? If so how can I get this, I want to uniquely identify a memory stick (removable drive) for authentication. Thanks
79
by: Klaus Bonadt | last post by:
In order to protect software from being copied without licence, I would like to use something like a key, which fits only to the current system. The serial number of the CPU or the current...
1
by: Darren DeCoste | last post by:
I am trying to create an application in Access that I will be able to print bar code labels. A stumbling block that I have hit is the Serial Number on the bar code. I would like to be able to read...
3
by: Stewart Allen | last post by:
Hi there I'm trying to find part serial numbers between 2 numbers. The user selects a part number from a combo box and then enters a range of serial numbers into 2 text boxes and the resulting...
3
by: Mark Harris | last post by:
I have an installer which uses a Customer Information page in it, is there an easy way to pass the serial number entered to a custom action? If not, where would i find the serial number in the...
14
by: Lauren Wilson | last post by:
Discovered this interesting comment on MSDN: "To programmatically obtain the hard disk's serial number that the manufacturer assigns, use the Windows Management Instrumentation (WMI)...
9
by: Nebojsa4 | last post by:
Hi. First, sorry on my weak English to all. Qusetion: How to read (in VB) Manufacturer serial number of Hard disk drive? Not volume/serial number of C:, D:, etc. partitons. For reading...
6
by: Paul Bromley | last post by:
Ok - I have given up on trying to find the active IP address for a given PC. For licensing purposes I need to retrive a unique identifier from the PC that the program is installed on. The Hard disk...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.