getting hdd serial number of windows 98/me in vb.net

ankush

Member
Joined
Nov 14, 2005
Messages
10
Programming Experience
Beginner
hey friends,

We developing an application in vb.net but the problem I am facing is that I don't know how to extract or get the serial number of HDD in windows 98,windows Me.


Does any one has the code for extracting hdd serial number from windows 98/Me in VB.net.
or anyone can tell where the serial number of hdd is stored in registry in windows 98/Me.

Thanks & Regards

Ankush grover
 
Having read your question i have to admit that i was interested in how to do this myself, so i decided to put down my work for a bit and have a go....

This is what i have come up with. Mostly from memory i'm afraid, but you can give it a try....

VB.NET:
Add a reference to system.management
Dim ObjReturn As Management.[URL="http://www.dotnet247.com/247reference/System/Management/ManagementObjectCollection.aspx"]ManagementObjectCollection[/URL]
Dim ObjSearch As Management.[URL="http://www.dotnet247.com/247reference/System/Management/ManagementObjectSearcher.aspx"]ManagementObjectSearcher[/URL]
Dim ObjManage As Management.[URL="http://www.dotnet247.com/247reference/System/Management/ManagementObject.aspx"]ManagementObject[/URL]
ObjSearch = New Management.[URL="http://www.dotnet247.com/247reference/System/Management/ManagementObjectSearcher.aspx"]ManagementObjectSearcher[/URL]("Select * from
Win32_LogicalDisk")
ObjReturn = ObjSearch.Get
For Each ObjManage In ObjReturn
Dim VolumeName As [URL="http://www.dotnet247.com/247reference/System/String.aspx"]String[/URL] = ObjManage("Name")
Dim SerialNumber As [URL="http://www.dotnet247.com/247reference/System/String.aspx"]String[/URL] = ObjManage("Volumeserialnumber")
Dim strOut As [URL="http://www.dotnet247.com/247reference/System/String.aspx"]String[/URL] = [URL="http://www.dotnet247.com/247reference/System/String.aspx"]String[/URL].Format("{0} - {1}", VolumeName, SerialNumber)
[URL="http://www.dotnet247.com/247reference/System/Diagnostics/Debug.aspx"]Debug[/URL].WriteLine(strOut)

Let me know if it works.
 
hey ,


I tried your code and it is returning the serial number of a:\ c:\ driver whereas I want the to extract the serial number of Hard Disk.

I am sorry If I was not clear about the things.

Anyway thanks for efforts.


Regards

Ankush Grover
 
System Information

Start > Programs > Accessories > System Tools > System Information

In System Information Program:
expand + Components
expand + Storage

Volume serial number is listed at the bottom for each drive.

Unfortunately, a search through the registry did not yeild any hits for that value. The serial number must not be stored in the registry. You could investigate where the system information program pulls the serial number from.


Hope that helps...
 
DaveT macktool, believe it or not we're still running win 98 at work in some dark places that time has forgot and on our system your method does not display the drive serial number. Would this be different on win98?

Anyway, ankush i have googled for this and have found a number of components that may do the job although they do seem pretty vague as to whether they will work on win 98. I'm almost sure that there must be a way of getting this info. If i come up with anthing i'll get back to you. But if i'm honest about this the guy to speak to would probably be Jmcilhinney he seems to have more knowledge about the inner workings of vb.net than anyone i know ( based on what i've seen in these forums)
 
hey friends,

thanks all of you for your spending your valuable time in giving me a solution.

Thanks & Regards

Ankush Grover
 
Please do not post duplicate threads. Post each question once only in the most appropriate forum. Your other thread has been deleted.

Also, you'll find that the serial number returned by the code provided is assigned by the OS and may change if you reformat the drive, and will definitely change if alter the aprtitions on the drive. If you want the actual manufacturer's serial number then you'll need to use other WMI classes. I do just that with three different classes: Win32_DiskDrive, Win32_PhysicalMedia, Win32_DiskDrivePhysicalMedia. It makes it much easier if you use the mgmtclassgen utility to generate .NET classes that correspond to the WMI classes. Once you've done that you can use code like this:
VB.NET:
        Private Sub GetHardDriveSerialNumbers()
            Dim driveMedia As New ManagementClass("Win32_DiskDrivePhysicalMedia")
            Dim driveMedium As DiskDrivePhysicalMedia
            Dim drive As DiskDrive
            Dim medium As PhysicalMedia
            Dim interfaceType As String
            Dim serialNumber As String

            For Each mo As ManagementObject In driveMedia.GetInstances()
                driveMedium = New DiskDrivePhysicalMedia(mo)
                drive = New DiskDrive(driveMedium.Dependent)
                medium = New PhysicalMedia(driveMedium.Antecedent)

                interfaceType = drive.InterfaceType
                serialNumber = medium.SerialNumber

                drive.Dispose()
                medium.Dispose()
                mo.Dispose()

                If (interfaceType = "IDE" OrElse interfaceType = "SCSI") AndAlso _
                   serialNumber <> Nothing Then
                    Me.m_HardDriveSerialNumbers.Add(serialNumber)
                End If
            Next mo

            driveMedia.Dispose()
        End Sub
If WMI is not available on 98/Me then I'm not sure what other method is available. I'd guess that it would require API functions.
 
hey,

WMI is not available on windows 98 for Windows XP I am already using WMI to extract the serial number.

Anyway thanks for your information.

Thanks & Regards

Ankush Grover
 
I think you'll find that you can access the same information provided by Win32_LogicalDisk using the GetVolumeInformation API function, although I couldn't be sure that it's supported on 98/Me either. Again though, it will give you the OS-assigned serial number rather than the manufacturers serial number.
 
hey,

but I want only the manufacturer's serial number not the logical volume serial number.

Anyway thanks.

Ankush Grover
 
Good example jmcilhinney, but Win32_PhysicalMedia WMI class was not available until Win XP. (also it supposedly got problems with SATA drives)

ankush, just a side comment, you can run WMI on win98 but you'll need from Microsoft Downloads “Windows Management Instrumentation (WMI) CORE 1.5 (Windows 95/98/NT 4.0).” and Windows Scripting Host (WSH 5.6).

I only find C++ codes for this in my search. http://www.winsim.com/diskid32/diskid32.html (both free compiled exe and source)
You could translate it... or use the provided console application and RedirectStandardOutput of ProcessStartInfo to capture the output, then parse out "Drive Serial Number" and info needed.
 
Back
Top