Hard Disk Manufacturer Serial Number Vb6 String

  1. Serial Number Lookup
  2. Aircraft Manufacturer Serial Number Lookup
  3. Hard Disk Manufacturer Serial Number Vb6 String Contains

RE: How to get Hard disk information from vb6 genomon (Programmer) 9 Jul 08 16:15 You can add an 'about box' control to your project, and shamelessly steal the API code that Microsoft was kind enough to provide.

17 Feb 2004CPOL
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.
  1. Could somebody please help me with a sample code to read the hard disk manufacturer's serial number. Not the one that changes every time you format a hard disk partitian. I need to read the serial number of the hard disk provided by the manufacturer, which always remain unique to every hard disk Thanks in advance.
  2. RE: How to get Hard Drive Serial Number by Manufacturer with VBA IDS (Civil/Environmental) 19 Nov 10 17:34 Clyde - your file works on my computer with no problems (Excel 2010 and Windows7), after enabling macros.

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.

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.

Vb6

Serial Number Lookup

Active4 years, 10 months ago

Am trying to get the manufacturer serial number (not volume number) of usb external harddrives or disk?

[EDIT]i don't know or have any code yet on how to do this. the previous method i tried only returned the volume serial number

dsolimano
7,6173 gold badges41 silver badges57 bronze badges
SmithSmith
3,12315 gold badges84 silver badges141 bronze badges

1 Answer

You can use WMI to retrieve this information. Hard drive serial numbers are in Win32_PhysicalMedia. I'm not going to take the time to write the code here; if you have any experience querying WMI in VB 6, you should be able to do it without much trouble. Otherwise, search for sample code online. You won't find much of anything specifically about hard drive serial numbers, but you'll find lots of WMI examples.

Manufacturer

Be weary of the fact that you won't always get the serial number in the format you're expecting. For example, comments to this article indicate you might get something like:

Aircraft Manufacturer Serial Number Lookup

Disk

Serial No. : 4a3532544e464137202020202020202020202020

in which case, you will have to decode the serial number:

  1. By converting to hexdecimal bytes, we get the following (0x20 is blank character and is trimmed out):

  2. Swapping the odd and even bytes gets the following:

  3. The above ASCII codes are equal to the serial number string:

I'm also not positive that all external/removable hard drives provide this information. Your mileage may vary, but the suggested method does work fine on internal hard drives.


Alternatively, it appears that you can do this using low-level Windows APIs like DeviceIOControl. You'll need to add declarations for the necessary functions to a module in your VB 6 app. This article on Code Project should help get you started; the code is written in native C++ and it's geared for consumption by .NET languages like C#, but I see no difficulty in adapting the code to VB 6.

Hard Disk Manufacturer Serial Number Vb6 String Contains

Cody GrayCody Gray
200k38 gold badges403 silver badges487 bronze badges
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.

Not the answer you're looking for? Browse other questions tagged vb6usb-driveserial-number or ask your own question.