Results 1 to 8 of 8
  1. #1
    Join Date
    Oct 2002
    Posts
    61

    Unanswered: Hard Drive Serial Number

    Does anyone have a procedure that will read the serial number of the hard drive?

  2. #2
    Join Date
    Mar 2003
    Location
    Atlanta, GA
    Posts
    191

    try this....

    I think this will work...(haven't actually tried it myself. But, this code is basically verbatim right out of the Microsoft VBScript guide... with me just adding in the serial number property...

    You should browse through it sometime...

    Function ShowDriveList
    Dim fso, d, dc, s, n
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set dc = fso.Drives
    For Each d in dc
    n = ""
    s = s & d.DriveLetter & " - "
    If d.IsReady Then
    n = Hex(d.SerialNUmber)
    End If
    s = s & n & "<BR>"
    Next
    ShowDriveList = s
    End Function
    Tim

  3. #3
    Join Date
    May 2002
    Location
    Atlanta, GA
    Posts
    117
    Hey MrWizard,
    Thats pretty cool. It works great.

    Kal

  4. #4
    Join Date
    Mar 2003
    Posts
    17

    Thumbs down Re: try this....

    I get an Error: "Unterminated string constant" when I run this, at the line: ShowDriveList = s
    Thanks for your help, Mitch

  5. #5
    Join Date
    Mar 2003
    Location
    Atlanta, GA
    Posts
    191

    try again...

    OK... I guess I was just a bit hasty to get my answer posted, and get on to other things....

    In VB, one can create a form, put a button on it, and call the following function from the click event..... (or just put the code in the click event itself)

    Sub ShowDriveList()
    Dim fso, d, dc, s, n
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set dc = fso.Drives
    For Each d In dc
    n = ""
    s = s & d.DriveLetter & " - "
    If d.IsReady Then
    n = Hex(d.SerialNUmber)
    End If
    s = s & n & vbCrLf
    Next
    Set Fso=Nothing
    MsgBox s
    End Sub

    On the WEB, with just a slightly different approach,
    create an asp file with the contents as follows...
    <%
    response.write "<html><head></head><body>"
    Dim fso, d, dc, s, n
    Set fso = Server.CreateObject("Scripting.FileSystemObject")
    SN = fso.Drives("C").SerialNumber
    Set fso=Nothing
    response.write "<p>" & SN & "</p>"
    response.write "</body></html>"
    %>

    Upload it to your server, and call it up in your browser.

    Remember though... what your getting is the SN of the SERVER...

    I think the unterminated string constant error must have been from trying to display the previous code result in a browser using HTML... that's the only way I could get a similar error.

    Have fun...
    Tim

  6. #6
    Join Date
    May 2002
    Location
    Atlanta, GA
    Posts
    117
    Hey MrWizard,
    Can you extract other data besides the serial number with specific keywords? Like the label, or size?

    Kal

  7. #7
    Join Date
    Oct 2002
    Posts
    61

    Re: try again...

    Thanks Mr. Wizard! I have added this proc to my library file. I also wrote a VBA executable using your code. It is attached to this reply.

    Attached Files Attached Files

  8. #8
    Join Date
    Mar 2003
    Location
    Atlanta, GA
    Posts
    191
    I've attached an excerpt right out of the Microsoft VBScript Language Reference that tells all about the FileSystemObject and what you can do with it.

    Have fun!

    Tim
    Attached Files Attached Files
    Tim

Posting Permissions

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