howto get harddisk serial number

  • Thread starter Thread starter tom
  • Start date Start date
T

tom

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
 
You need to use WMI (System.Management) to query Win32_PhysicalDisk. Some
hard disks will not
give you a serial number (it might be null, so be prepared for that).
-mike
MVP
 
Is there than a better way that allows me to uniquely
identify the pc where my software is running on that will
work always on any computer?

thanx,
t
 
I have not found any Win32_PhysicalDisk.
I have found Win32_DiskDrive, but I do not find a property that returns the
physical drive serial number.
The DeviceID property returns values such as \\.\PHYSICALDRIVE2
Is there an example of how to get the physica drive serial number?
 
An install guid identifies the source of my software not
the pc's it is running on. Neither does the
SystemInformation class provide me with a unique identity
of the pc. And since Michael pointed out that the hd
serial number is not always present I would like to know
a way that does identify the destination system and which
will work in every situation.

What I want to achieve is the following:
I want to distribute my software on cd. Through the
combination of the serial number of the cd and a unique
identifier of the system the software is installed on I
will be able to manage the licenses.
I was thinking that on my website I let users register
themselves (ie. enter cd sn and system identifier) where
they will get an encrypted key back of the combination of
cd sn and system identifier. The user would then get a
month after install to enter this encrypted key and if it
does not match the original values than my software would
not run..
 
Use a combination of IDs


tom said:
An install guid identifies the source of my software not
the pc's it is running on. Neither does the
SystemInformation class provide me with a unique identity
of the pc. And since Michael pointed out that the hd
serial number is not always present I would like to know
a way that does identify the destination system and which
will work in every situation.

What I want to achieve is the following:
I want to distribute my software on cd. Through the
combination of the serial number of the cd and a unique
identifier of the system the software is installed on I
will be able to manage the licenses.
I was thinking that on my website I let users register
themselves (ie. enter cd sn and system identifier) where
they will get an encrypted key back of the combination of
cd sn and system identifier. The user would then get a
month after install to enter this encrypted key and if it
does not match the original values than my software would
not run..
 
Users dont like being tied to hardware. I know I dont, i hated that in the
unix world of CPU keying.
 
I might have been off. Search for WMI Schema (or if you've found the docs
for Win32_DiskDrive, navigate up from there). Win32_BaseBoard has a serial
number. In other products, I use a combination of different IDs and then
hash them (so there's no identifying information). Some components have a
Tag or "OtherIdentifyingInfo" property. On my machine (Intel MB with P4
HT), all these were null except the baseboard (motherboard) serial.
-mike
MVP
 
DeviceID is not the serial number. Look in the WMI schema to find other
things. As I said before, many devices might not report a serial. On my
Intel MB, it does report a serial (Win32_BaseBoard). Sometimes, there will
be asset tags and more. Of couse, this is always subject to change, and
nothing forces a vendor to put a unique serial on their hardware.

As for the Windows Media SDK, I don't know the details, but I see
SDMI-compliant. I think SDMI is one of those lame DRM protection schemes
that failed miserably. At any rate, all the devices would need to be
"compliant", and I'm sure many aren't (I think it was aimed at portable
storage?).

-mike
MVP
 
In Win32_DiskDrive, the following does not give the disk serial number:

DeviceID
Data type: string
Access type: Read-only
Qualifiers: Key

Unique identifier of the disk drive with other devices on the system. This
property is inherited from CIM_LogicalDevice

A bit over 2 years ago, I found an article in the Windows Media Format SDK
that might return the desired info.
I do not have a URL for the article.

The article states:
"Microsoft® Windows MediaT Device Manager uses a common way to retrieve the
serial number of a storage medium. For Windows NT, an SDMI-compliant reader
or adapter must respond to the following
IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER code, and return the data structure
MEDIA_SERIAL_NUMBER_DATA."



The example was given in C and I rarely use C, so I did not trey to convert
to VB.
 
The obligatory question , what if I change my hardware.

A change in hardware could easily be a new computer. How is the software
suposed to know? The key is for the licensing to offer a little
flexibility in how many times or how often a given CD key can be used to
install the software.

In this model a web connection handles all the details. All the user has
to do is run a quick wizard once per install (or per major hardware
change). If they don't have the web then they can call in for a code.

As far as the implementation it's all about web services. Just create a
web service that takes a machine config, and returns a code. As far as
what to use for "machine config" I'm not entirely sure. Others seem to
have given good answers for that.


Windows XP licensing seems to work well. It is tied to the hardware. It
let's you change your hardware a little before you need to reactivate. In
either case, you can change the hardware all you want and still not have to
pay for it again. I 'think' the break point is that you can only reinstall
to a new set of hardware once every 6 months before a red flag is raised.
However it still installs and activates.

Michael Lang, MCSD
 
I did not ask for other things.

I was just pointing out things that I had found that might provide the
"serial number".

Obviously, there must be some way to do this as there are programs from disk
drive vendors that report the info on their own, and often other, drives.

So somewhere, such an interface is provided.

I just do not know where it is "documented".
 
Well, if you find one of those programs, open it up in a dissassembler and
see what calls it makes. Also be aware that they might use device-specific
APIs.
-mike
MVP
 
Back
Top