Solved

Volume Serial Number

Posted on 1999-01-05
10
300 Views
Last Modified: 2008-03-10
I know how to retrieve it.  My question is:
Where does it come from?  Is it randomly generated?  What are the odds on it being duplicated (ie re-occurring)?
0
Comment
Question by:clifABB
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 14

Expert Comment

by:waty
Comment Utility
Type BY_HANDLE_FILE_INFORMATION
   dwFileAttributes As Long
   ftCreationTime As FILETIME
   ftLastAccessTime As FILETIME
   ftLastWriteTime As FILETIME
   dwVolumeSerialNumber As Long
   nFileSizeHigh As Long
   nFileSizeLow As Long
   nNumberOfLinks As Long
   nFileIndexHigh As Long
   nFileIndexLow As Long
End Type

Private Type PictDesc
   cbSizeofStruct As Long
   picType        As Long
   hImage         As Long
   xExt           As Long
   yExt           As Long
End Type

Private Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long
Private Declare Function GetFileInformationByHandle Lib "kernel32" (ByVal hFile As Long, lpFileInformation As BY_HANDLE_FILE_INFORMATION) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Private Declare Function GetVolumeInformation& Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal pVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long)

Public Function GetSerialNumber(sDrive As String) As Long
   ' *** Retrieve a disks serial number
   ' *** Whenever a disk is formatted, the operating system writes a serial number onto it.
   ' *** This number is not guaranteed to be unique, but as it is a 32 bit integer
   ' *** it is unlikely to find a duplicate!
   ' *** The number is often used as part of a copy protection system.

   Dim nSerial       As Long
   Dim sTmp          As String * 256
   Dim sTmp2         As String * 256
   Dim nI            As Long
   Dim nJ            As Long

   sTmp = String$(255, Chr$(0))
   sTmp2 = String$(255, Chr$(0))
   Call GetVolumeInformation(sDrive + ":\" & Chr$(0), sTmp, 256, nSerial, nI, nJ, sTmp2, 256)
   GetSerialNumber = nSerial

End Function

Public Function GetSerialNumber2() As String
   '
   '  Returns a volume's serial number
   '
   Dim lpReOpenBuff       As OFSTRUCT
   Dim FileHandle         As Long
   Dim FileInfo           As BY_HANDLE_FILE_INFORMATION
   Dim ret As Long

   FileHandle = OpenFile("c:\autoexec.bat", lpReOpenBuff, OF_READ)
   ret = GetFileInformationByHandle(FileHandle, FileInfo)
   GetSerialNumber2 = CStr(FileInfo.dwVolumeSerialNumber)
   ret = CloseHandle(FileHandle)

End Function


0
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
I just knew somebody was going to answer this with a function to retrieve it.
0
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
Understanding Disk Volume Tracking in Windows 95
Last reviewed: May 16, 1996
Article ID: Q150582  
The information in this article applies to:
Microsoft Win32 Application Programming Interface included with: Microsoft Windows 95 version 4.0


SUMMARY
When users insert a disk in a floppy disk drive, Windows 95 tracks the disk to prevent the user from opening a file, removing the disk, and inadvertently inserting a different disk. Through this behavior, Windows 95 helps users guard against corrupting the data on their disks. This article explains how Windows 95 tracks disks and discusses instances where software developers can consider overriding the default mechanism Windows 95 uses to perform this task.



MORE INFORMATION


Volume Tracking Overview
One part of the Windows 95 disk system is a driver called the Volume Tracking Driver. Its purpose is to uniquely identify disks and ensure that the correct disk is in the floppy disk drive when data is written to a file. The Volume Tracking Driver intercepts all writes to the floppy disk drive and, when it detects an invalid write operation, displays a text- mode blue screen prompting users to either insert the original disk or cancel the invalid write operation. There is no way to prevent Windows 95 from displaying this blue screen because it serves as a warning to users that an error has been made that could result in data loss.

The Volume Tracking Driver uniquely identifies disks by writing a volume tracking serial number in the OEM ID field (offsets 0x3-0xB) of the boot record, which is stored in the boot sector of the disk. This serial number is different than the volume serial number created when the disk is formatted and is used solely by the Volume Tracking Driver. The Volume Tracking Driver assigns a volume tracking serial number the first time a disk is inserted since Windows was last started. That number identifies that particular disk until Windows 95 is restarted.



How to Override the Default Volume Tracking Method
There are times when the Volume Tracking Driver cannot or should not be allowed to overwrite the OEM ID field of the boot record of a disk. For example, write-protected disks physically prevent the Volume Tracking Driver from overwriting the OEM ID field. Also, some software programs, such as backups, rely on the OEM ID field to determine whether the disk contains valid data. For instance, if a utility program stores a name in the OEM ID field and the Volume Tracking Driver overwrites this information, the disk becomes useless if the backup software checks for the name.

When the Volume Tracking Drive is prevented from overwriting the OEM ID field on a disk, it stores the disk's volume serial number and label in memory and uses the combination of these to identify the disk. Although this method does not modify the disk, it is slower than storing a unique ID on the disk itself.

Although the Volume Tracking Driver cannot be disabled, it can be prevented from modifying the OEM ID field of specific types of disks if the following value is created for the registry key:


   HKEY_LOCAL_MACHINE\System\CurrentControlSet\control\
      FileSystem\NoVolTrack

The values in this key form a table of patterns and offsets that the Volume Tracking Driver uses to determine which disks should not be modified. When a new disk is inserted, the Volume Tracking Driver scans this table looking for each pattern at its corresponding offset in the disk's boot sector. If it finds a pattern, it does not update the OEM ID field in the disk's boot record, but rather identifies the disk by its volume serial number and label.
Each value of the NoVolTrack key is binary data formatted as a two-byte offset in little-endian order followed by an arbitrarily long sequence of bytes that make up a pattern. The Volume Tracking Driver ignores the label of each value, but the labels are used to aid human readers in understanding the type of disk to which the value refers. An example table of values looks like the following:


   NoVolTrack
      Label    Offset   Pattern
      -------  ------   --------------------
      MyDisk   0050h    MyDisk
      COOL     0100h    COOL

In the Registry Editor, this table looks like the following:

      MyDisk   50 00 4D 79 44 69 73 6B
      COOL     00 01 43 4F 4F 4C

If your software relies on the OEM ID in the boot record of disks it uses, you need to register your "disk type" by adding it to the table of values in the NoVolTrack registry key.  

0
 
LVL 6

Author Comment

by:clifABB
Comment Utility
I'm sorry but I must reject your answer.
As noted in my question, I already know how to retrieve the volume serial number.  I was asking technical information about it which Mirkwood did supply.

Mirkwood:
Thank you, that's what I was looking for.
Please post your answer for points.
0
 
LVL 3

Expert Comment

by:cognition
Comment Utility
Does this apply to hard disks ?
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 6

Author Comment

by:clifABB
Comment Utility
Yes.
0
 
LVL 13

Accepted Solution

by:
Mirkwood earned 50 total points
Comment Utility
See comments below
0
 
LVL 14

Expert Comment

by:waty
Comment Utility
Oops, sorry, I didn't reply correctly to your answer.
0
 
LVL 3

Expert Comment

by:vikiing
Comment Utility
Volume serial number is derived from the current time at the moment the disk if formatted.

Watch out !!!, Int 13 (direct disk access) lets you change disk numbers to put whatever you want !!!

0
 
LVL 6

Author Comment

by:clifABB
Comment Utility
Again, thanks.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now