-
May 18th, 2006, 12:07 AM
#1
Thread Starter
Hyperactive Member
[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
-
May 18th, 2006, 12:14 AM
#2
Re: [2005] : How to get CD Serial No ?
I'm more of vb6, but doesn't .net have the filesystemobject?
-
May 18th, 2006, 12:15 AM
#3
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:
Dim serialNumber As Guid = Guid.NewGuid()
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.
-
May 18th, 2006, 12:38 AM
#4
Thread Starter
Hyperactive Member
Re: [2005] : How to get CD Serial No ?
Is FileSystemObject availble in .NET 2005 class library ? or it's third party component ?
-
May 18th, 2006, 12:54 AM
#5
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.
-
May 18th, 2006, 01:44 AM
#6
Thread Starter
Hyperactive Member
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..
-
May 18th, 2006, 01:53 AM
#7
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.
-
May 18th, 2006, 02:09 AM
#8
Thread Starter
Hyperactive Member
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
-
May 18th, 2006, 04:10 AM
#9
Thread Starter
Hyperactive Member
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:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myObjectSearcher As System.Management.ManagementObjectSearcher
Dim myCollection As System.Management.ManagementObjectCollection
Dim myManagementScope As New System.Management.ManagementScope()
Dim myObject As System.Management.ManagementObject
myObjectSearcher = New System.Management.ManagementObjectSearcher( _
myManagementScope.Path.ToString, "Select * From Win32_CDROMDrive")
myCollection = myObjectSearcher.Get()
For Each myObject In myCollection
MsgBox(myObject.GetPropertyValue("FileSystemFlagsEx"))
[COLOR=DarkRed][B]'MsgBox(myObject.GetPropertyValue("SerialNumber"))[/B] // How to get SerialNumber[/COLOR] Next
End Sub
plz help
-
May 18th, 2006, 04:50 AM
#10
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
-
May 18th, 2006, 05:16 AM
#11
Re: [2005] : How to get CD Serial No ?
Also, here's some slightly cleaner code:
VB Code:
Dim physicalMedia As New ManagementClass("Win32_PhysicalMedia")
Dim mediaType As UShort
Dim serialNumber As String
For Each physicalMedium As ManagementObject In physicalMedia.GetInstances()
mediaType = DirectCast(physicalMedium("MediaType"), UShort)
Select Case mediaType
Case 16 To 19 'CD
serialNumber = CStr(physicalMedium("SerialNumber"))
Case 22 To 26 'DVD
serialNumber = CStr(physicalMedium("SerialNumber"))
End Case
physicalMedium.Dispose()
Next physicalMedium
physicalMedia.Dispose()
-
May 18th, 2006, 06:42 AM
#12
Thread Starter
Hyperactive Member
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
-
May 18th, 2006, 10:40 AM
#13
Thread Starter
Hyperactive Member
Re: [2005] : How to get CD Serial No ?
Ok..Finally I got the code ..
VB Code:
Function GetDriveSerialNumber(ByVal driveLetter As Char) As String
Dim driveFilter As String = "Win32_LogicalDisk='" & driveLetter.ToString & ":'"
Dim drive As New System.Management.ManagementObject(driveFilter)
Return drive("VolumeSerialNumber")
End Function
Thanks to all people who has helped a lot
-
May 5th, 2010, 10:11 AM
#14
Addicted Member
Re: [2005] : How to get CD Serial No ?
Originally Posted by jmcilhinney
Also, here's some slightly cleaner code:
VB Code:
Dim physicalMedia As New ManagementClass("Win32_PhysicalMedia")
Dim mediaType As UShort
Dim serialNumber As String
For Each physicalMedium As ManagementObject In physicalMedia.GetInstances()
mediaType = DirectCast(physicalMedium("MediaType"), UShort)
Select Case mediaType
Case 16 To 19 'CD
serialNumber = CStr(physicalMedium("SerialNumber"))
Case 22 To 26 'DVD
serialNumber = CStr(physicalMedium("SerialNumber"))
End Case
physicalMedium.Dispose()
Next physicalMedium
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|