473,472 Members | 2,264 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Get hard drive serial without API using VBA

tuxalot
200 New Member
Has anyone used this code to get the serial for a hard drive?

Expand|Select|Wrap|Line Numbers
  1. Function HDSerialNumber() As String
  2. Dim fsObj As Object
  3. Dim drv As Object
  4.     Set fsObj = CreateObject("Scripting.FileSystemObject")
  5.     Set drv = fsObj.Drives("C")
  6.     HDSerialNumber = Left(Hex(drv.SerialNumber), 4) _
  7.                      & "-" & Right(Hex(drv.SerialNumber), 4)
  8.     Debug.Print HDSerialNumber
  9.  
  10. End Function
Is this a reliable way to do it or is there a better way?
Dec 12 '11 #1
3 18093
Mihail
759 Contributor
The function seems to return all the time the same value for the same drive letter.
But, as far as I don't know how to check the drive serial using other method I can't say if your code is working.

The Drives() function do not accept a variable as argument as I expect.

This are values that I obtain running the function:

For "C" : 84E8-BE57
For "D" : F8CB-609F

For CD drives it seems to depend of CD (or DVD) but is all the time the same for a certain CD (DVD). I have two CD (DVD) drives attached to my PC and I make tests for both of them with the same results: same CD (or DVD) => same "serial".

Hope this information help you.
Any way I post here for subscribe purpose.
Dec 12 '11 #2
ADezii
8,834 Recognized Expert Expert
Here is another approach using the API:
  1. API Declaration:
    Expand|Select|Wrap|Line Numbers
    1. Public Declare Function GetVolumeInformation Lib "Kernel32" Alias "GetVolumeInformationA" _
    2.                          (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, _
    3.                          ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, _
    4.                          lpMaximumComponentLength As Long, lpFileSystemFlags As Long, _
    5.                          ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
  2. Call to Function:
    Expand|Select|Wrap|Line Numbers
    1. Dim strSerialNum As Long
    2. Dim strVName As String
    3. Dim strFSName As String
    4.  
    5. 'Get the Volume information
    6. GetVolumeInformation "C:\", strVName, 255, strSerialNum, 0, 0, strFSName, 255
    7.  
    8. Debug.Print "The Serial Number of Drive C:\ is: " & Trim(Str$(strSerialNum))
  3. OUTPUT:
    Expand|Select|Wrap|Line Numbers
    1. 'With Drive Substitution:
    2. The Serial Number of Drive C:\ is: 1755256066
    3. The Serial Number of Drive F:\ is: 861870070
Dec 12 '11 #3
tuxalot
200 New Member
Thanks for your input ADezii. I am not sure what number I am presented with when I run your code. With Hardware ID Extractor I find that the code I posted gives the partition ID (volume serial number) which unfortunately will change if the drive is reformatted.

Is there a way to verify that the code you provided gives the real serial of the hard drive?

DiskId32 from www(dot)winsim(dot)com/diskid32/diskid32(dot)html gives different information than both of the solutions posted here.

Now I'm confused.
Dec 13 '11 #4

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

Similar topics

10
by: 3A Web Hosting | last post by:
Hi Folks This is probably starring me in the face but how do I read the contents of a hard drive directory? I've been playing around with the opendir($dir) sample from php.net and can read from...
2
by: Job Lot | last post by:
How can I retrieve the Motherboard, hard drive, NIC Serial Number Using vb.net. thanx
2
by: Dan | last post by:
Does anyone know how to determine the physical hard drive serial number? I found a GetVolumeInformation function in C++ but wanted a comparable function in VB.net or C#. Thanks Dan Shanyfelt
3
by: Arne Beruldsen | last post by:
How do you read the serial number to a hard drive? Thanks...Arne
0
by: Ryan Liu | last post by:
How to read NIC card serial numbers or MAC address , Hard Drive serial numbers in Java or Delphi or C/C++ or C#? Thanks, Ryan
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...
7
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
2
by: =?Utf-8?B?Y29taXQy?= | last post by:
itried to install xp home edition . everything was loading ok untill eror message that os couldnot find hard disk drive. upon opening bios it shows my cd drive as primary and my dvd drive as...
4
by: Abhinay | last post by:
Hi, I wanted to check and disply total avilable hard drive space on my machine using C++ on windows. I search on google but did't get any help. Can any budy help me on this issue. Thanks...
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
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,...
1
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...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.