Results 1 to 14 of 14

Thread: [RESOLVED] [2005] : How to get CD Serial No ?

  1. #1

    Thread Starter
    Hyperactive Member Coool's Avatar
    Join Date
    Feb 2006
    Location
    System.Coool
    Posts
    333

    Resolved [RESOLVED] [2005] : How to get CD Serial No ?

    Hello guys,

    Im just working on the project where i need a unique CD Serial No. Is that possible using .NET 2005 class library ?

    please help me

    thanks

  2. #2
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: [2005] : How to get CD Serial No ?

    I'm more of vb6, but doesn't .net have the filesystemobject?

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: [2005] : How to get CD Serial No ?

    Unless you want to define your own algorithm to generate a serial number you would use the Guid structure, which represents a Globally Unique Identifier. GUIDs are used in many places throughout Windows and you would have seen them before even if you didn't know what they were.
    VB Code:
    1. Dim serialNumber As Guid = Guid.NewGuid()
    2.  
    3. MessageBox.Show(serialNumber.ToString())
    Because the Guid is a randomly-generated 128-bit number the chances of it being all zeroes or the same as any other Guid are negligible, although those situations are not impossible. It is the improbability of these events that provides an effective guarantee that all generated Guids will be unique.

  4. #4

    Thread Starter
    Hyperactive Member Coool's Avatar
    Join Date
    Feb 2006
    Location
    System.Coool
    Posts
    333

    Re: [2005] : How to get CD Serial No ?

    Is FileSystemObject availble in .NET 2005 class library ? or it's third party component ?

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: [2005] : How to get CD Serial No ?

    Have I misunderstood what you're trying to do?

    The My.Computer.FileSystem object exposes much of the functionality of the FileSystemObject. If that doesn't provide what you need then you'd have to add a reference to the Windows Scripting Host Object Model from the COM tab and use an actual FileSystemObject.

  6. #6

    Thread Starter
    Hyperactive Member Coool's Avatar
    Join Date
    Feb 2006
    Location
    System.Coool
    Posts
    333

    Re: [2005] : How to get CD Serial No ?

    Ok, here is the short discription ..

    I am working on Project Named "CD Library" and I am storing the stucture of the CD. I need a Serial Number of the CD .. So that I can uniquely identify the peritcular CD from Bunch.

    Any suggestion regarding to the project are most well come..

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: [2005] : How to get CD Serial No ?

    So you're talking about music CDs and/or CD-ROMs, yeah? That's good information to include in your initial post. Remember that we know nothing about your project so if you don't supply enough information we'll make assumptions, and possibly waste our time researching a solution as a result.

  8. #8

    Thread Starter
    Hyperactive Member Coool's Avatar
    Join Date
    Feb 2006
    Location
    System.Coool
    Posts
    333

    Re: [2005] : How to get CD Serial No ?

    Thanks dude ..

    But, I don't want to move from my porblem : plz send the code for fetching the CD Serial No yaar...

    Pleaseeeeeeeeeeeeeeeeee

  9. #9

    Thread Starter
    Hyperactive Member Coool's Avatar
    Join Date
    Feb 2006
    Location
    System.Coool
    Posts
    333

    Exclamation Re: [2005] : Little bit Help for CD SerialNumber

    Ok,

    i got the following useful links but can't solve problem i hope i mayhelp u


    http://www.devcity.net/Articles/144/2/article.aspx

    http://msdn.microsoft.com/library/de...oarddevice.asp

    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Dim myObjectSearcher As System.Management.ManagementObjectSearcher
    3.         Dim myCollection As System.Management.ManagementObjectCollection
    4.         Dim myManagementScope As New System.Management.ManagementScope()
    5.         Dim myObject As System.Management.ManagementObject
    6.         myObjectSearcher = New System.Management.ManagementObjectSearcher( _
    7.         myManagementScope.Path.ToString, "Select * From Win32_CDROMDrive")
    8.         myCollection = myObjectSearcher.Get()
    9.  
    10.         For Each myObject In myCollection
    11.             MsgBox(myObject.GetPropertyValue("FileSystemFlagsEx"))
    12.             [COLOR=DarkRed][B]'MsgBox(myObject.GetPropertyValue("SerialNumber"))[/B] // How to get SerialNumber[/COLOR]        Next
    13.  
    14.     End Sub


    plz help

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: [2005] : How to get CD Serial No ?

    The help for the Win32_CDROMDrive class specifies that the SerialNumber property is not available on pretty much any Windows version you're likely to use. Try the SerialNumber property of the Win32_PhysicalMedia class instead. You'll have to test the MediaType property too to make sure it corresponds to a type of CD, because if you get all Win32_PhysicalMedia objects it will include hard drives, floppy drives, other removeable drives, etc.

    http://msdn.microsoft.com/library/de...sicalmedia.asp

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: [2005] : How to get CD Serial No ?

    Also, here's some slightly cleaner code:
    VB Code:
    1. Dim physicalMedia As New ManagementClass("Win32_PhysicalMedia")
    2. Dim mediaType As UShort
    3. Dim serialNumber As String
    4.  
    5. For Each physicalMedium As ManagementObject In physicalMedia.GetInstances()
    6.     mediaType = DirectCast(physicalMedium("MediaType"), UShort)
    7.  
    8.     Select Case mediaType
    9.         Case 16 To 19 'CD
    10.             serialNumber = CStr(physicalMedium("SerialNumber"))
    11.         Case 22 To 26 'DVD
    12.             serialNumber = CStr(physicalMedium("SerialNumber"))
    13.     End Case
    14.  
    15.     physicalMedium.Dispose()
    16. Next physicalMedium
    17.  
    18. physicalMedia.Dispose()

  12. #12

    Thread Starter
    Hyperactive Member Coool's Avatar
    Join Date
    Feb 2006
    Location
    System.Coool
    Posts
    333

    Re: [2005] : How to get CD Serial No ?

    Sorry dude it only return the SerialNumber of Media (CD Drive/ DVD Drive) not a CD.
    Last edited by Coool; May 18th, 2006 at 10:18 AM. Reason: Sorry I made mistake

  13. #13

    Thread Starter
    Hyperactive Member Coool's Avatar
    Join Date
    Feb 2006
    Location
    System.Coool
    Posts
    333

    Resolved Re: [2005] : How to get CD Serial No ?

    Ok..Finally I got the code ..

    VB Code:
    1. Function GetDriveSerialNumber(ByVal driveLetter As Char) As String
    2.         Dim driveFilter As String = "Win32_LogicalDisk='" & driveLetter.ToString & ":'"
    3.         Dim drive As New System.Management.ManagementObject(driveFilter)
    4.         Return drive("VolumeSerialNumber")
    5.     End Function

    Thanks to all people who has helped a lot

  14. #14
    Addicted Member mynameishide's Avatar
    Join Date
    Apr 2010
    Posts
    136

    Re: [2005] : How to get CD Serial No ?

    Quote Originally Posted by jmcilhinney View Post
    Also, here's some slightly cleaner code:
    VB Code:
    1. Dim physicalMedia As New ManagementClass("Win32_PhysicalMedia")
    2. Dim mediaType As UShort
    3. Dim serialNumber As String
    4.  
    5. For Each physicalMedium As ManagementObject In physicalMedia.GetInstances()
    6.     mediaType = DirectCast(physicalMedium("MediaType"), UShort)
    7.  
    8.     Select Case mediaType
    9.         Case 16 To 19 'CD
    10.             serialNumber = CStr(physicalMedium("SerialNumber"))
    11.         Case 22 To 26 'DVD
    12.             serialNumber = CStr(physicalMedium("SerialNumber"))
    13.     End Case
    14.  
    15.     physicalMedium.Dispose()
    16. Next physicalMedium
    17.  
    18. physicalMedia.Dispose()
    i imports System.Management
    but ManagementClass("Win32_PhysicalMedia")..?? say not define

    is any other classes need to imports..??

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