Hi just put this together it a small piece of code to get your main drive serial number. it uses dos to get the number
Hope it maybe useful comments and suggestions welcome.
Code:
Option Explicit On
Public Class frmmain
Private Function CaptureDos(ByVal Filename As String, Optional ByVal Parms As String = vbNullString) As String
Dim Exec As New System.Diagnostics.Process()
Dim Buffer As String = vbNullString
Try
With Exec
.StartInfo.RedirectStandardOutput = True
.StartInfo.UseShellExecute = False
.StartInfo.CreateNoWindow = True
.StartInfo.FileName = Filename
.StartInfo.Arguments = Parms
.Start()
'Read in output.
Buffer = .StandardOutput.ReadToEnd()
'Wait for exit.
Exec.WaitForExit()
'Return string.
Return Buffer
End With
Catch ex As Exception
Return vbNullString
End Try
End Function
Private Function GetHdSerial() As String
Dim Serial As String = vbNullString
Dim Line As String = CaptureDos("cmd.exe", "/c vol")
Dim idx As Integer = 0
'Loop backwards until we find a space.
For Count As Integer = Line.Length - 1 To 0 Step -1
'Exit if space is found.
If Line(Count).Equals(" "c) Then
idx = Count
Exit For
End If
Next Count
If (idx <> 0) Then
Return Line.Substring(idx + 1)
End If
Return vbNullString
End Function
Private Sub cmdSerial_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSerial.Click
MessageBox.Show("Hard Drive Serial: " & GetHdSerial(), "Hard Drive Serial",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub