Hard Disk Manufacturer Serial Number Vb6 String

17 Feb 2004CPOL
Hard
  1. 'thanks but i want hard disk serial number your code is for drive serial number or volume number. I need code for Hard disk serial number which is not changed after format hard disk. HDD serial number is displayed in cmos setup also.
  2. For get the serial number of all hard drives in my computer, I use: wmic diskdrive get serialnumber But, I want to get the serial number of the hard drive where I am working.
  3. 'thanks but i want hard disk serial number your code is for drive serial number or volume number. I need code for Hard disk serial number which is not changed after format hard disk. HDD serial number is displayed in cmos setup also.
  4. Private Function GetDiskSerialNumber() As String Static serial_number As Long Dim volume_name As String Dim max_component_length As Long Dim file_system_flags As Long Dim file_system_name As String If serial_number = 0 Then ' Get the disk serial number.

Retrieving Hard Drive Serial Number via WMIC. This is a because the diskdrive serial number has been inserted by the manufacturer as a hexadecimal string and WMIC is just returning the hex as a string type (with no formatting or modifications to convert from LSB first to MSB first). So, depending on the manufacturer and how they insert.

Shows you how to obtain the hardware serial number set by the manufacturer and not the Volume Serial Number that changes after you format a hard drive.

Introduction

Making sure your software is used by legal buyers is a concern for programmers around the world. My professor once said that we shouldn’t give 100% of our code to the users because there are people out there that are smart enough to decompile our programs and find the various verification algorithms used. He suggested that we give users 99% of our software, but keep the remaining 1% to ourselves. This 1% is the verification algorithm to confirm only valid users can use the program; this is commonly known as “activation.”

Activation is good, but it means our software users will need to have Internet access and that means small programmers like us have to set up a server that can validate users. Of course, only big companies with big clients can afford to do this. For the rest of us, we have to think of other ways.

One method programmers have used since the DOS era was to bind their software to the Hard Drive Volume Serial Number. This is not a good choice, as later we all find out that every time we format the same hard drive, a new Volume Serial Number is generated.

Background

A better solution is to get the Hard Drive Serial Number given by the Manufacturer. This value won't change even if you format your Hard Drive. Of course, if people buy new hard drive, we have a problem. But at least we keep the regular hard-drive formatters happy!

The Code

First, let's create a class to store information about a hard drive:

Next, add a reference to your project. Scroll down to System.Management under ComponentName. This reference is not provided by default, so you need to add it.

Add a 'using System.Management;' at the top of your source code. System.Management allows us to access WMI objects. Put simply, WMI contains a lot information about your hardware.

Now there's a problem: the hard drive model is found in the Win32_DiskDrive class and the serial number is found in the Win32_PhysicalMedia class. Thus, we need to query twice and integrate the information into our HardDrive class.

Let's first create an ArrayList to store our HardDrive objects: ArrayList hdCollection = new ArrayList();. Next, we query the Win32_DiskDrive class:

Now we need to extract the serial number from the Win32_PhysicalMedia class:

Luckily, the WMI objects from Win32_DiskDrive are in the same order as from Win32_PhysicalMedia, so the simple code above works. Otherwise, we will have to match them using their unique DeviceID. Start a thread in this article if you think Win32_DiskDrive objects are not the same order as Win32_PhysicalMedia objects returned.

Find Hard Disk Serial Number

We are done! Now we display our hard drive's information:

Conclusion

If a user has more than one hard drive, I suggest you display the available hard drives to the user. Ask him which hard drive he's not planning to upgrade soon, then use that hard drive serial number to generate a license key. This will prevent your user from nagging for a new license key in short time.

If your user finally decides to upgrade hard drive, you may give this article's demo application to the user and ask him what the serial number is. Alternatively, you can create a much more user-friendly GUI one. :)

Hope you find this useful.

Serial Number Idm Gratis

Expert100+
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 volume/serial number of hard disk C: etc, You can use Microsoft Scripting Runtime (in VB):
Dim ff As New Scripting.FileSystemObject
Dim drv As Drive
Set drv = ff.GetDrive('C')
SerialNumber = drv.SerialNumber
MsgBox 'Serial/Volume number of C: is ' + Trim(Str(SerialNumber))
But, I need manufacturer serial number of hard disk drive, because, after formatting hard disk You'll get another volume/serial number, and that is very bad if my program should check that parameter, if he can't recognize that this HDD is the same one but only formatted (and after formatting there is set another volume/serial number).
How I see, many people swap meaning of volume and serial number of some drive.
Thx to all.
Hi there,
Kindly refer to below attached code segment, hope it helps. Good luck & take care.
API declaration
  1. Option Explicit
  2. Private Declare Function GetVolumeInformation& Lib 'kernel32' _
  3. Alias 'GetVolumeInformationA' (ByVal lpRootPathName _
  4. As String, ByVal pVolumeNameBuffer As String, ByVal _
  5. nVolumeNameSize As Long, lpVolumeSerialNumber As Long, _
  6. lpMaximumComponentLength As Long, lpFileSystemFlags As _
  7. Long, ByVal lpFileSystemNameBuffer As String, ByVal _
  8. nFileSystemNameSize As Long)
  9. Const MAX_FILENAME_LEN = 256
Form code
  1. Option Explicit
  2. Private Sub Command1_Click()
  3. Label1.Caption = SerNum('C') 'C is the standard harddisk
  4. End Sub
  5. Public Function SerNum(Drive$) As Long
  6. Dim No&, s As String * MAX_FILENAME_LEN
  7. Call GetVolumeInformation(Drive + ':', s, MAX_FILENAME_LEN, _
  8. No, 0&, 0&, s, MAX_FILENAME_LEN)
  9. SerNum = No
  10. End Function