Hard Disk Serial Number

  • Thread starter Thread starter Adele le Roux
  • Start date Start date
A

Adele le Roux

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
 
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.


I believe you can fetch that information through WMI if you have the proper
permissions.
 
Adele said:
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

Here's a Function I developed a while ago for this purpose. You need to
add Exception Handling of course (watch for line wrapping) -

Imports System.Management

Public Function GetDriveSerialNumber(ByVal sDriveLetter As String) As String

If Len(sDriveLetter) = 1 Then
sDriveLetter &= ":"
Else
sDriveLetter = Strings.Left(Environment.SystemDirectory, 2)
End If

Dim HardDiskInfo As New
ManagementObject(String.Format("Win32_LogicalDisk.DeviceID=""{0}""",
sDriveLetter))
Dim HardDiskProperty As PropertyData =
HardDiskInfo.Properties("VolumeSerialNumber")
Return HardDiskProperty.Value.ToString

End Function


Usage:- MsgBox(GetDriveSerialNumber("C"))

Hope this helps.

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
Note that this "VolumeSerialNumber" is a number that Windows assigns it
might change after a reformat / repartitioning of the harddrive
the true harrdware serial number does not do that
 
Thanks for the info, but my question is how to get the hard drive serial
number on a REMOTE computer. I can get it on the local computer, but how to
specify I want to get (for example) the server's hard disk serial number?
 
Adele said:
Thanks for the info, but my question is how to get the hard drive serial
number on a REMOTE computer. I can get it on the local computer, but how to
specify I want to get (for example) the server's hard disk serial number?

Sorry, I should learn to read the questions more carefully!!

The following will do what you require (watch for line wrapping) -


Dim sbString As System.Text.StringBuilder = New System.Text.StringBuilder
Dim strServerName As String = "RemoteComputerNameHere!!"
Dim oObjQuery As ObjectQuery = New ObjectQuery("select * from
Win32_Logicaldisk")
Dim mScope As ManagementScope = New ManagementScope("\\" + strServerName
+ "\root\cimv2")
mScope.Connect()
Dim mObjSearch As ManagementObjectSearcher = New
ManagementObjectSearcher(mScope, oObjQuery)
For Each mObj As ManagementObject In mObjSearch.Get
sbString.AppendFormat("Desc={0}, ID={1}, Volname={2}, Serial#={3}" _
, mObj("Description"), mObj("Deviceid"), mObj("VolumeName"),
mObj("VolumeSerialNumber"))
sbString.AppendFormat("" & Microsoft.VisualBasic.Chr(10) & "")
Next
MessageBox.Show(sbString.ToString)


Hope this helps.

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
ShaneO said:
Sorry, I should learn to read the questions more carefully!!

The following will do what you require (watch for line wrapping) -


Dim sbString As System.Text.StringBuilder = New System.Text.StringBuilder
Dim strServerName As String = "RemoteComputerNameHere!!"
Dim oObjQuery As ObjectQuery = New ObjectQuery("select * from
Win32_Logicaldisk")
Dim mScope As ManagementScope = New ManagementScope("\\" + strServerName
+ "\root\cimv2")
mScope.Connect()
Dim mObjSearch As ManagementObjectSearcher = New
ManagementObjectSearcher(mScope, oObjQuery)
For Each mObj As ManagementObject In mObjSearch.Get
sbString.AppendFormat("Desc={0}, ID={1}, Volname={2}, Serial#={3}" _
, mObj("Description"), mObj("Deviceid"), mObj("VolumeName"),
mObj("VolumeSerialNumber"))
sbString.AppendFormat("" & Microsoft.VisualBasic.Chr(10) & "")
Next
MessageBox.Show(sbString.ToString)


Hope this helps.

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.

Oh, and by the way, the following link will help you with any other
parameters you might be seeking -

http://msdn2.microsoft.com/en-us/library/aa394173.aspx


ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
Thanks a stack Shane. I will check it out a bit later and let you know if it
works. Thanks again!
 
Back
Top