Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Harddisk serial number 2

Status
Not open for further replies.

vbSun

Programmer
Dec 9, 2002
504
US
I just wanted to ask a quick doubt.. i use the GetVolumeInformation to read the serial number. My doubt is whether it is constant through out the life of the harddisk? I am trying to create a serial number from this information. Can the user use this to install this on that particular machine all the time?

This is my harddisk serial 605617218 (nine numerals). Is this nine numerals for all of you out there?

Thanks
Sunil

------------------------------------------
The faulty interface lies between the chair and the keyboard.
 
Does anyone "Search" before posting? See Thread222-674278 for a discussion of this.

If you choose to battle wits with the witless be prepared to lose.

[cheers]
 
>Does anyone "Search"

Increasingly the answer to this seems to be 'no'
 
Apologies.

No i didnt search.

------------------------------------------
The faulty interface lies between the chair and the keyboard.
 
I am not looking to find a definite id to identify a particular computer. I am looking for information on GetVolumeInformation API.

I just want to know whether the value returned by this API is nine numerals or not.

------------------------------------------
The faulty interface lies between the chair and the keyboard.
 
vbSun,
I was not taking a shot at you, it just seems that the past two days, this question has been asked about three or four times. I get a return of 10 numerals.

If you choose to battle wits with the witless be prepared to lose.

[cheers]
 
vbSun, it is not a matter of nine or ten numerals. The serial number you get from the API is in pure numerical form and you can get it to the desired format by converting into hex. In the same way, the serial number of your hard disk turns out to be 2418-FC42.

When I do a GetVolumeInformation on my C:\ drive, it gives me a serial number of 675225351. When I convert it into hex and put a '-' in it, I get 283F-1F07 which is the same that I see in a DOS box when I do a dir command.

See this code.
___
[tt]
Option Explicit
Private Declare Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long

Private Sub Form_Load()
Dim SerialNumber As Long, S As String

'get the serial number
SerialNumber = GetSerialNumber("C:\")

'serial number in raw numerical form
MsgBox SerialNumber

'now format the serial number in its hexadecimal form


'convert to hex
S = Hex$(SerialNumber)

'pad zeroes to the left
S = Right$("00000000" & S, 8)

'put a "-" in the middle
S = Left$(S, 4) & "-" & Right$(S, 4)

'serial number in generic hexadecimal form
MsgBox S

Unload Me

End Sub

Function GetSerialNumber(RootPath As String) As Long
GetVolumeInformation RootPath, vbNullString, 0, GetSerialNumber, ByVal 0&, ByVal 0&, vbNullString, 0
End Function[tt]
 
I got a single hard disk partitioned in two and each "virtual drive" has different volume label. For some of you this might seem pretty obvious but until now I thought the volume number was stored physically in the hard disk and therefore it was not created anew for every partition.
 
>For some of you this might seem pretty obvious

Not necessarily obvious, but certianly commented on a lot in this forum...
 
Foada > I know the irritation of trying to answer the same question four times in a couple of days. Dont worry, all can express themselves in a forum like tek-tips. I am not an expert programmer by any means, i need help from y'all to do the best at job. Thanks for providing me with help every time i wanted some.

Hypetia > Thanks a lot for the demonstration. The thread helped me know that the GetVolumeInformation doesnt necessarily return a 9 digit length numeral and Hypetia's post helped me format it the way i needed.

Thankyou Hypetia!

------------------------------------------
The faulty interface lies between the chair and the keyboard.
 
Here's the short way:

Debug.Print Format(Hex(CreateObject("scripting.filesystemobject").GetDrive("c").SerialNumber), "@@@@-@@@@")
 
fischadler said:
I got a single hard disk partitioned in two and each "virtual drive" has different volume label.

That's why the API is called GetVolumeInformation, and not GetDriveInformation -- the volume serial number is stored in the volume header, not the boot sector of the drive.

If you're curious, open the boot.ini in the root of a Windows NT/2k/XP machine. You'll see at least one line that looks like this:
Code:
default=multi(0)disk(0)rdisk(0)partition(1)\WINNT
which tells the OS loaded where to find the Windows directory (on multi 0, disk 0, rdisk 0, partition 1, for my machine). Since all the numbers are zero-based, this tells me that I have a partition 0 somewhere (it's the "sleep" or "suspend" partition).

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
strongm said:
Here's the short way:

Debug.Print Format(Hex(CreateObject("scripting.filesystemobject").GetDrive("c").SerialNumber), "@@@@-@@@@")

Showing off again? ;-)

Have Fun, Be Young... Code BASIC
-Josh

cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top