Results 1 to 19 of 19

Thread: [RESOLVED] Get The Hard Drive Serial Number

  1. #1

    Thread Starter
    Frenzied Member Pc_Not_Mac's Avatar
    Join Date
    Oct 2009
    Location
    localhost
    Posts
    1,206

    Resolved [RESOLVED] Get The Hard Drive Serial Number

    Hello, How can i get the hard drive Serial Number.
    The Physical one only
    I spent 1 hour on google the only examples i found all had errors
    My Codebank:
    Windows Vista & 7 Glass Effect & Limit the amount of times your application could be opened.
    Pause Your Code & Check the OS name

    The question of whether computers can think is like the question of whether submarines can swim.

    Currently learning: Java

    Coding can be a learning experience or

  2. #2
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: Get The Hard Drive Serial Number

    Have a look here:
    http://www.vbforums.com/showthread.php?t=605589

    The post i give references for the hd serial and modify the first post code to your needs.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  3. #3
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Get The Hard Drive Serial Number

    WMI is probably the easiest. You can use Microsoft's WMI creator.

    Also, if you tried and example and it didn't work, don't you think you should post it and the errors you're referring to?

    That's much better than waiting for someone to give you the code.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  4. #4

    Thread Starter
    Frenzied Member Pc_Not_Mac's Avatar
    Join Date
    Oct 2009
    Location
    localhost
    Posts
    1,206

    Re: Get The Hard Drive Serial Number

    Code:
    Dim objMan As New Management.ManagementClass("Win32_PhysicalMedia")
    
            Dim objCol As Management.ManagementObjectCollection = objMan.GetInstances
    
            Dim objItem As Management.ManagementObject
    
            For Each objItem In objCol
    
                Dim pi As Management.PropertyDataCollection = objItem.Properties
    
                Console.WriteLine("SerialNumber: " & CType(pi.Item("SerialNumber").Value, String))
    
    
    
    
                Console.WriteLine("Tag: " & CType(pi.Item("Tag").Value, String))
    I get errors like

    107 Type 'Management.ManagementObjectCollection' is not defined. C:\Users\User\Documents\app\Form1.vb 4852 23 app
    Thank you in advance
    My Codebank:
    Windows Vista & 7 Glass Effect & Limit the amount of times your application could be opened.
    Pause Your Code & Check the OS name

    The question of whether computers can think is like the question of whether submarines can swim.

    Currently learning: Java

    Coding can be a learning experience or

  5. #5
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: Get The Hard Drive Serial Number

    Yes you must import system.management
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  6. #6
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: Get The Hard Drive Serial Number

    add reference and import
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  7. #7
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Get The Hard Drive Serial Number

    Follow my directions in post 6 of this thread.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  8. #8

    Thread Starter
    Frenzied Member Pc_Not_Mac's Avatar
    Join Date
    Oct 2009
    Location
    localhost
    Posts
    1,206

    Re: Get The Hard Drive Serial Number

    The errors are gone but the serial number looks like this.
    I just have a bad feeling that this is not a serial number.
    Attached Images Attached Images  
    Last edited by Pc_Not_Mac; Mar 6th, 2010 at 09:19 PM.
    My Codebank:
    Windows Vista & 7 Glass Effect & Limit the amount of times your application could be opened.
    Pause Your Code & Check the OS name

    The question of whether computers can think is like the question of whether submarines can swim.

    Currently learning: Java

    Coding can be a learning experience or

  9. #9
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Get The Hard Drive Serial Number

    Um... I've read about this before.

    If I'm not mistaken, it is correct. Your serial number is just in a hexadecimal format. You'll need to convert it to a string. Google that and I'm sure you'l come up with what you need.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  10. #10

    Thread Starter
    Frenzied Member Pc_Not_Mac's Avatar
    Join Date
    Oct 2009
    Location
    localhost
    Posts
    1,206

    Re: Get The Hard Drive Serial Number

    Thank you for the reply weirddemon
    This might be a stupid question.
    How unique is this Serial Number do you know?
    My Codebank:
    Windows Vista & 7 Glass Effect & Limit the amount of times your application could be opened.
    Pause Your Code & Check the OS name

    The question of whether computers can think is like the question of whether submarines can swim.

    Currently learning: Java

    Coding can be a learning experience or

  11. #11
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: Get The Hard Drive Serial Number

    Hi.
    Just to make sure it's the correct serial here is an API function so you can compare them...

    Code:
    Imports System.Runtime.InteropServices
    Imports System.Text
    
    
    Public Class Form1
        Inherits System.Windows.Forms.Form
    
        <DllImport("kernel32.dll")> _
     Private Shared Function GetVolumeInformation(ByVal PathName As String, ByVal VolumeNameBuffer As StringBuilder, ByVal VolumeNameSize As Int32, ByRef VolumeSerialNumber As Int32, ByRef MaximumComponentLength As Int32, ByRef FileSystemFlags As Int32, ByVal FileSystemNameBuffer As StringBuilder, ByVal FileSystemNameSize As Int32) As Long
        End Function
    Friend Function GetVolumeSerial(ByVal strDriveLetter As String) As String
    
    Dim serNum As System.Int32 = 0
    Dim maxCompLen As System.Int32 = 0
    Dim VolLabel As StringBuilder = New StringBuilder(256)
    Dim VolFlags As Int32 = New Int32
    Dim FSName As StringBuilder = New StringBuilder(256)
    strDriveLetter += ":\"
    Dim Ret As Long = GetVolumeInformation(strDriveLetter, VolLabel, CType(VolLabel.Capacity, Int32), serNum, maxCompLen, VolFlags, FSName, CType(FSName.Capacity, Int32))
    Return Convert.ToString(serNum)
    End Function
    
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    'disk volume
    GetVolumeSerial("c")
    End Sub
    End Class
    Last edited by sapator; Mar 6th, 2010 at 09:57 PM.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  12. #12
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: Get The Hard Drive Serial Number

    Sorry i live in the stone age here (xp).
    So if you have vista and above here is how you get the exact serial without modifications.

    Code:
     Private Function ff()
    
    
            Dim MOS As ManagementObjectSearcher
            Dim MOC As Management.ManagementObjectCollection
            Dim MO As Management.ManagementObject
    
            MOS = New ManagementObjectSearcher("Select * From Win32_DiskDrive")
            MOC = MOS.Get
            Dim s As String
            For Each MO In MOC
                s = MO("Model")
                s = MO("Name")
                s = MO("SerialNumber")
            Next
    
        End Function
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  13. #13
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: Get The Hard Drive Serial Number

    What you posted is just going to assign "SerialNumber' to s in each iteration...
    Code:
            For Each MO In MOC
                s = MO("Model")
                s = MO("Name")
                s = MO("SerialNumber")
            Next
    Did you intend on concatenating the Model, Name and Serial?

  14. #14

    Thread Starter
    Frenzied Member Pc_Not_Mac's Avatar
    Join Date
    Oct 2009
    Location
    localhost
    Posts
    1,206

    Re: Get The Hard Drive Serial Number

    How unique is this Serial Number do you know?


    Code:
    Dim objMan As New Management.ManagementClass("Win32_PhysicalMedia")
    
            Dim objCol As Management.ManagementObjectCollection = objMan.GetInstances
    
            Dim objItem As Management.ManagementObject
    
            For Each objItem In objCol
    
                Dim pi As Management.PropertyDataCollection = objItem.Properties
    
                Console.WriteLine("SerialNumber: " & CType(pi.Item("SerialNumber").Value, String))
    
    
    
    
                Console.WriteLine("Tag: " & CType(pi.Item("Tag").Value, String))
    My Codebank:
    Windows Vista & 7 Glass Effect & Limit the amount of times your application could be opened.
    Pause Your Code & Check the OS name

    The question of whether computers can think is like the question of whether submarines can swim.

    Currently learning: Java

    Coding can be a learning experience or

  15. #15
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: Get The Hard Drive Serial Number

    Bruce Fox that was just an example so Pc_Not_Mac can see if that's the values he wants.
    Also i think serial no is 1 in every model since many software houses use HD serial to lock programs.
    If you want more security use it with something else.
    P.E. HD and MAC address.Combine the values or each in it's own check.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  16. #16

    Thread Starter
    Frenzied Member Pc_Not_Mac's Avatar
    Join Date
    Oct 2009
    Location
    localhost
    Posts
    1,206

    Re: Get The Hard Drive Serial Number

    Thank for the help sapator
    I just wanted to know how unique is this Serial Number
    and thank you for the answer
    My Codebank:
    Windows Vista & 7 Glass Effect & Limit the amount of times your application could be opened.
    Pause Your Code & Check the OS name

    The question of whether computers can think is like the question of whether submarines can swim.

    Currently learning: Java

    Coding can be a learning experience or

  17. #17
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: [RESOLVED] Get The Hard Drive Serial Number

    No problem
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  18. #18

    Re: [RESOLVED] Get The Hard Drive Serial Number

    You can use HardDriveInfo.DLL to read the real serial number of hard disk easily. HardDriveInfo.DLL does not depend on the "support" libraries to get or fetch the details. Each Hard Disks have Unique Serial Number, some time it is necessary to get the hard disk serial number. So HardDriveInfo.DLL helps us to get the Hard disk serial number easily and efficiently, you can use this serial number to create an machine id or encrypt number.


    Hard Drive

  19. #19
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: [RESOLVED] Get The Hard Drive Serial Number

    First of all, i'm against of "feeding" the programmer with stuff that he/she can create easily by himself.
    Second please provide the page of this dll and a usable example because i think you're just spamming.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

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