Results 1 to 1 of 1

Thread: Get Harddrive Serial Easy.

  1. #1

    Thread Starter
    Fanatic Member BenJones's Avatar
    Join Date
    Mar 2010
    Location
    Wales UK
    Posts
    629

    Get Harddrive Serial Easy.

    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
    Last edited by BenJones; Feb 1st, 2013 at 06:49 PM. Reason: Bug Fix

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width