473,585 Members | 2,552 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

programmaticall y obtain the hard disk's serial number from VBA?


Discovered this interesting comment on MSDN:

"To programmaticall y obtain the hard disk's serial number that the
manufacturer assigns, use the Windows Management Instrumentation (WMI)
Win32_PhysicalM edia (a class) property SerialNumber."

I'm sorry to admit it bit I am really undereducated on how to
incorporate some of the Windows SDK stuff into VBA apps. Anyone know
of some sample code that will allow us to read the C drive hardware
serial number? I'm NOT talking about the serial number assigned to a
drive by the OS, I'm talking about the serial number given by the HD
manufacturer and encoded on the drive's ROM chip.

The WHY of this question is too complicated to go into right now.

Any help or advice will be much appreciated.

Thanks folks,

-- LW
Mar 7 '06 #1
14 28107
Lauren Wilson wrote:
Discovered this interesting comment on MSDN:

"To programmaticall y obtain the hard disk's serial number that the
manufacturer assigns, use the Windows Management Instrumentation (WMI)
Win32_PhysicalM edia (a class) property SerialNumber."

I'm sorry to admit it bit I am really undereducated on how to
incorporate some of the Windows SDK stuff into VBA apps. Anyone know
of some sample code that will allow us to read the C drive hardware
serial number? I'm NOT talking about the serial number assigned to a
drive by the OS, I'm talking about the serial number given by the HD
manufacturer and encoded on the drive's ROM chip.

The WHY of this question is too complicated to go into right now.

Any help or advice will be much appreciated.

Thanks folks,

-- LW


Try:

http://groups.google.com/group/micro...bb45fdfed9d31f

Note: I know that there are ways for customers to get around the use of
the MAC Address of a network card for registering software. There may
be ways to get around the HD info as well.

James A. Fortune
CD********@Fort uneJames.com

Mar 7 '06 #2

Thanks. Unfortunately, the "GetVolumeSeria lNumber" function returns
the OS generated drive id, not the manufacturers's product serial
number that is stored on the drive's on-board ROM.

The OS drive ID WILL change if the user re-format's his HD. The Mfg
Drive serial number will not. What I need is VBA compatible code
that will make use of the Win32_PhysicalM edia.SerialNumb er funtion to
read and return the HARDWARE serial number of a selected drive.
Of course, the user COULD remove and replace any drive, but that
happens FAR less often than a re-format.
On 6 Mar 2006 18:30:21 -0800, CD********@Fort uneJames.com wrote:
Lauren Wilson wrote:
Discovered this interesting comment on MSDN:

"To programmaticall y obtain the hard disk's serial number that the
manufacturer assigns, use the Windows Management Instrumentation (WMI)
Win32_PhysicalM edia (a class) property SerialNumber."

I'm sorry to admit it bit I am really undereducated on how to
incorporate some of the Windows SDK stuff into VBA apps. Anyone know
of some sample code that will allow us to read the C drive hardware
serial number? I'm NOT talking about the serial number assigned to a
drive by the OS, I'm talking about the serial number given by the HD
manufacturer and encoded on the drive's ROM chip.

The WHY of this question is too complicated to go into right now.

Any help or advice will be much appreciated.

Thanks folks,

-- LW


Try:

http://groups.google.com/group/micro...bb45fdfed9d31f

Note: I know that there are ways for customers to get around the use of
the MAC Address of a network card for registering software. There may
be ways to get around the HD info as well.

James A. Fortune
CD********@For tuneJames.com

Mar 7 '06 #3
Air Code: (be careful of news client created line breaks)

Expand|Select|Wrap|Line Numbers
  1. Function DiskZeroName() As String
  2. Dim Buffer As String
  3. Dim PathTxt As String
  4. Dim FileNumber As Integer
  5. On Error Resume Next
  6. Kill "DiskZeroName*.*"
  7. On Error GoTo 0
  8. PathTxt = "DiskZeroName" & Format(Now(), "dddmmmddyyyyhhnnss\.\t\x\t")
  9. Shell "RegEdit /E " & PathTxt & "
  10. HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\Scsi\", vbHide
  11. FileNumber = FreeFile
  12. Open PathTxt For Binary As #FileNumber
  13. Buffer = String(LOF(FileNumber), vbNullChar)
  14. Get #FileNumber, , Buffer
  15. Close #FileNumber
  16. Buffer = StrConv(Buffer, vbFromUnicode)
  17. DiskZeroName = Mid$(Buffer, InStr(Buffer, "Identifier") + 13)
  18. DiskZeroName = Left$(DiskZeroName, InStr(DiskZeroName, Chr(34)) - 1)
  19. End Function
On my laptop this returns
HITACHI_DK23FA-80.

I don't know if this is the number you want.
I don't know if it will work on other machines or other operating
systems.
Mar 7 '06 #4
Lauren Wilson wrote:
Thanks. Unfortunately, the "GetVolumeSeria lNumber" function returns
the OS generated drive id, not the manufacturers's product serial
number that is stored on the drive's on-board ROM.

The OS drive ID WILL change if the user re-format's his HD. The Mfg
Drive serial number will not. What I need is VBA compatible code
that will make use of the Win32_PhysicalM edia.SerialNumb er funtion to
read and return the HARDWARE serial number of a selected drive.
Of course, the user COULD remove and replace any drive, but that
happens FAR less often than a re-format.


Lauren,

Sorry I wasn't able to help. If you find a solution to this problem
please post it. I am also interested in other's comments about the
usage of this manufacturer HD ID as a "dongle."

Thanks,

James A. Fortune
CD********@Fort uneJames.com

Mar 7 '06 #5
On Mon, 06 Mar 2006 19:05:12 -0600, Lauren Wilson <no****@nospam. com> wrote:

Discovered this interesting comment on MSDN:

"To programmaticall y obtain the hard disk's serial number that the
manufacturer assigns, use the Windows Management Instrumentation (WMI)
Win32_Physical Media (a class) property SerialNumber."

I'm sorry to admit it bit I am really undereducated on how to
incorporate some of the Windows SDK stuff into VBA apps. Anyone know
of some sample code that will allow us to read the C drive hardware
serial number? I'm NOT talking about the serial number assigned to a
drive by the OS, I'm talking about the serial number given by the HD
manufacturer and encoded on the drive's ROM chip.

The WHY of this question is too complicated to go into right now.

Any help or advice will be much appreciated.

Thanks folks,

-- LW


Some of the earlier hacks no longer work and WMI is the way to use on current systems.

Easy in script if this is enabled and can be run in admin mode, for example create a file sn.vbs:
(Scott McNairy)

Expand|Select|Wrap|Line Numbers
  1. set svc = getobject ("winmgmts:root\cimv2")
  2. set objEnum = svc.execQuery ("select * from win32_physicalMedia")
  3. for each obj in objEnum
  4. wscript.echo obj.GetObjectText_
  5. next
and run this run in command mode (you can shell out to this) for example

cscript sn.vbs >result.txt

For VB code you will have to read the documentation yourself probably, or be more successful in
searching. WMI will work in VB but all the examples are in C++.

above script ref
http://groups.google.com.au/group/mi...2363a8ea2debab

general refs
http://msdn.microsoft.com/library/de...sicalmedia.asp
http://msdn.microsoft.com/library/de...r_hardware.asp
and go up and down the tree.

Oh, I see that there are some WMI routines for disk info in Randy Birch's site VBnet (note this is
VB, not VB.net) but on cursory inspection these also seem to use scripting.
Mar 8 '06 #6
Thanks p. person. This is a cool way to retrieve what the OS THINKS
is the actual Mfg SN for drive 0. Since the value is retrieved from
the Registry, then, by definition, it can be wiped out by a
reformat/reinstall.

Please, someone correct me if I'm wrong: The "Win32_Physical Media"
class of the WMI library, actually reads and returns the drive
manufacturer's SN FROM the hardware ROM on a specified drive device.
This would be the serial number/identifier that was burned onto the
ROM when the drive was made. If so, THAT is what we need. Anything
less, is no better than what we have now -- and what we have now is
not adequate.

Can anyone point me in the right direction on this?

Thanks again for your help.

-- LW
On Wed, 08 Mar 2006 13:35:07 GMT, polite person <si*****@ease.c om>
wrote:
On Mon, 06 Mar 2006 19:05:12 -0600, Lauren Wilson <no****@nospam. com> wrote:

Discovered this interesting comment on MSDN:

"To programmaticall y obtain the hard disk's serial number that the
manufacture r assigns, use the Windows Management Instrumentation (WMI)
Win32_Physica lMedia (a class) property SerialNumber."

I'm sorry to admit it bit I am really undereducated on how to
incorporate some of the Windows SDK stuff into VBA apps. Anyone know
of some sample code that will allow us to read the C drive hardware
serial number? I'm NOT talking about the serial number assigned to a
drive by the OS, I'm talking about the serial number given by the HD
manufacture r and encoded on the drive's ROM chip.

The WHY of this question is too complicated to go into right now.

Any help or advice will be much appreciated.

Thanks folks,

-- LW


Some of the earlier hacks no longer work and WMI is the way to use on current systems.

Easy in script if this is enabled and can be run in admin mode, for example create a file sn.vbs:
(Scott McNairy)

Expand|Select|Wrap|Line Numbers
  1. set svc = getobject ("winmgmts:root\cimv2")
  2. set objEnum = svc.execQuery ("select * from win32_physicalMedia")
  3. for each obj in objEnum
  4.     wscript.echo obj.GetObjectText_
  5. next
  6.  

and run this run in command mode (you can shell out to this) for example

cscript sn.vbs >result.txt

For VB code you will have to read the documentation yourself probably, or be more successful in
searching. WMI will work in VB but all the examples are in C++.

above script ref
http://groups.google.com.au/group/mi...2363a8ea2debab

general refs
http://msdn.microsoft.com/library/de...sicalmedia.asp
http://msdn.microsoft.com/library/de...r_hardware.asp
and go up and down the tree.

Oh, I see that there are some WMI routines for disk info in Randy Birch's site VBnet (note this is
VB, not VB.net) but on cursory inspection these also seem to use scripting.

Mar 8 '06 #7
On Wed, 08 Mar 2006 13:25:32 -0600, Lauren Wilson <no****@nospam. com> wrote:

Thanks p. person. This is a cool way to retrieve what the OS THINKS
is the actual Mfg SN for drive 0. Since the value is retrieved from
the Registry, then, by definition, it can be wiped out by a
reformat/reinstall.

Please, someone correct me if I'm wrong: The "Win32_Physical Media"
class of the WMI library, actually reads and returns the drive
manufacturer 's SN FROM the hardware ROM on a specified drive device.
This would be the serial number/identifier that was burned onto the
ROM when the drive was made. If so, THAT is what we need. Anything
less, is no better than what we have now -- and what we have now is
not adequate.

Can anyone point me in the right direction on this?

Thanks again for your help.

-- LW

I would post the question in microsoft.publi c.win32.program mer.wmi

I would have expected that all WMI objects are actually precalculated, to read the actual number you
would need to be in a driver or with similar privileges. However by analogy with the MAC address, if
it has been spoofed there is an entry which can tell you this or reset it I forget which.
Mar 9 '06 #8
In MSDOS it was easy to retrieve standard HD information,
but in Windows, hardware is virtualised, and you can't get
at it.
Windows does now provide a path to an interface for HD
serial numbers, but it is the SMART drive interface and
I don't know what you will get if SMART is turned off,
or if you have SCSI disks, or if you have Serial ATA disks,
etc.

http://vbnet.mvps.org/index.html?code/disk/smartide.htm
manufacturer assigns, use the WMI Win32_PhysicalM edia
property SerialNumber."
I've never seen that work, but go ahead and try it:
Expand|Select|Wrap|Line Numbers
  1. '----------
  2. Sub GetPhysicalSerial()
  3.  
  4. Dim obj As Object
  5. Dim WMI As Object
  6.  
  7. Set WMI = GetObject("WinMgmts:")
  8.  
  9. For Each obj In WMI.InstancesOf("Win32_PhysicalMedia")
  10. Debug.Print "SN: " & obj.SerialNumber
  11. Next
  12.  
  13. End Sub
  14. '-----------
  15.  
(david)

"Lauren Wilson" <no****@nospam. com> wrote in message
news:rm******** *************** *********@4ax.c om...
Discovered this interesting comment on MSDN:

"To programmaticall y obtain the hard disk's serial number that the
manufacturer assigns, use the Windows Management Instrumentation (WMI)
Win32_PhysicalM edia (a class) property SerialNumber."

I'm sorry to admit it bit I am really undereducated on how to
incorporate some of the Windows SDK stuff into VBA apps. Anyone know
of some sample code that will allow us to read the C drive hardware
serial number? I'm NOT talking about the serial number assigned to a
drive by the OS, I'm talking about the serial number given by the HD
manufacturer and encoded on the drive's ROM chip.

The WHY of this question is too complicated to go into right now.

Any help or advice will be much appreciated.

Thanks folks,

-- LW
Mar 13 '06 #9
Hi David! Thanks for your response.

This works perfectly. However, it naturally returns SNs for ALL of
the HDs on my system. I need a way to return JUST the primary drive
SN (Drive 0). I tried inserting Debug.Print "SN: " & obj.name & ": "
& obj.SerialNumbe r, but the Name property returned only empty
strings.
Is there a way to limit the output to only the SN for Drive 0?

Thanks again.

-- LW.


On Mon, 13 Mar 2006 16:38:48 +1100, "david epsom dot com dot au"
<david@epsomdot comdotau> wrote:
In MSDOS it was easy to retrieve standard HD information,
but in Windows, hardware is virtualised, and you can't get
at it.
Windows does now provide a path to an interface for HD
serial numbers, but it is the SMART drive interface and
I don't know what you will get if SMART is turned off,
or if you have SCSI disks, or if you have Serial ATA disks,
etc.

http://vbnet.mvps.org/index.html?code/disk/smartide.htm
manufacturer assigns, use the WMI Win32_PhysicalM edia
property SerialNumber."


I've never seen that work, but go ahead and try it:

'----------
Sub GetPhysicalSeri al()

Dim obj As Object
Dim WMI As Object

Set WMI = GetObject("WinM gmts:")

For Each obj In WMI.InstancesOf ("Win32_Physica lMedia")
Debug.Print "SN: " & obj.SerialNumbe r
Next

End Sub
'-----------

(david)

"Lauren Wilson" <no****@nospam. com> wrote in message
news:rm******* *************** **********@4ax. com...

Discovered this interesting comment on MSDN:

"To programmaticall y obtain the hard disk's serial number that the
manufacturer assigns, use the Windows Management Instrumentation (WMI)
Win32_PhysicalM edia (a class) property SerialNumber."

I'm sorry to admit it bit I am really undereducated on how to
incorporate some of the Windows SDK stuff into VBA apps. Anyone know
of some sample code that will allow us to read the C drive hardware
serial number? I'm NOT talking about the serial number assigned to a
drive by the OS, I'm talking about the serial number given by the HD
manufacturer and encoded on the drive's ROM chip.

The WHY of this question is too complicated to go into right now.

Any help or advice will be much appreciated.

Thanks folks,

-- LW

Mar 13 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
43009
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 (or would HDD be better, or both?) and put that info into VB prog so the program won't work on another computer. My program uses an MSAccess table....
15
9663
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
2
3565
by: Job Lot | last post by:
How can I retrieve the Motherboard, hard drive, NIC Serial Number Using vb.net. thanx
9
20687
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 volume/serial number of hard disk C: etc, You can use Microsoft Scripting Runtime (in VB):
6
30698
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 serial number would do fine, but on Googling it seems that some of the sample code will now laways work on W2K, and not without administrator...
7
1734
by: Adele le Roux | last post by:
Hi All, How can I get the hard disk serial number of a remote computer's C:? The drive will NOT be mapped as a network drive. Thanks, Adele
0
1721
by: preethaAjayan | last post by:
Could anybody please help me with a piece of code to get hard disk's serial number using C#, not volume serial number, actual number that manufactures give to hard disks.
6
10478
by: Matthew Connor | last post by:
Hi all! I'm sure many of you rolled your eyes at the subject trying to recall how many times youv'e heard this question. :) But bear with because I THINK my question is at least slightly different from the typical post. I would like to obtain the manufactuer's embedded serial number (NOT the volume serial that changes with each format) of...
0
4779
Airslash
by: Airslash | last post by:
Hello, I've written a class that resembles a hard drive. I'm already able using the Windows API to get information such as the remaining free bytes, the sectors and clusters,a nd it all works fine. The last step that I need is to obtain the serial number of the harddrive in question. From what I can understand in the MSDN library you need to...
0
7908
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7836
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8199
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8336
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7950
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8212
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5389
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1447
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1175
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.