RE: CD/DVD Media SerialNumber
- From: Gary Bond <GaryB@xxxxxxxxxxxxxxxx>
- Date: Mon, 5 Dec 2005 06:50:03 -0800
Hi Gary,
Many thanks for that - and sorry for the delay in coming back to you.
(*real* life got in the way...ho ho)
Tried the code and re-arranged it a bit for a small test app, below, and it
works fine.
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("Select VolumeSerialNumber,
VolumeName, Size, MediaLoaded from Win32_CDROMDrive");
foreach (ManagementObject wmi_CD in searcher.Get())
{
textBox1.Clear();
if (Convert.ToBoolean(wmi_CD["MediaLoaded"]))
{
if (wmi_CD["VolumeName"] == null)
textBox1.AppendText("No name" + "\r\n");
else
textBox1.AppendText("volume name = " +
wmi_CD["VolumeName"].ToString() + "\r\n");
if (wmi_CD["Size"] == null)
textBox1.AppendText("No size" + "\r\n");
else
textBox1.AppendText("Size = " +
wmi_CD["Size"].ToString() + "\r\n");
if (wmi_CD["VolumeSerialNumber"] == null)
textBox1.AppendText("no VolumeSerialNumber" +
"\r\n");
else
textBox1.AppendText("Serial Number = " +
(wmi_CD["VolumeSerialNumber"].ToString()));
}
else
{
textBox1.Clear();
textBox1.AppendText("No disc in drive");
}
}
However, sometimes the "MediaLoaded" property comes back false, even when
there is a disc in the drive. (Its a CD-RW disc in XP-Prof...don't know if
that makes a difference). This is not too much of a problem, but would be
interested in your comments.
Also, since the VolumeSerialNumber sometimes comes back blank, can you
suggest some set of properties I could get hold of from inserted CD/DVD media
that would enable me to say if my app had seen this particular disc before.
(The plan is to check each disc as it comes in and only index it if we have
not done so before). I would like to do this in an automatic manner rather
than ask the user every time if possible.
Anyhow, thanks again for any help, and there is no rush for any help btw,
this is a 'hobby' app, not a 'work, why isn't it finished' app <grin>
cheers,
Gary.
""Gary Chang[MSFT]"" wrote:
> Hi Gary,
>
> >But I can't work out how to get at it via the Win32_PhysicalMedia
> >and Win32_CDROMDrive classes. How do I match the results
> >from the test code below to the Win32_CDROMDrive classes?
>
> If you want to retrieve the CD/DVD Disk's Serial Number, you need to query
> the Win32_CDRomDrive class, not the Win32_PhysicalMedia class, the
> Win32_PhysicalMedia instance will provide your computer's hard disk drive's
> info, not the CD/DVD Disk info.
>
> For a CD/DVD disk's Serial Number, the corresponding property is
> Win32_CDRomDrive class's VolumeSerialNumber property, e.g.
>
> ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT *
> FROM from Win32_CDROMDrive");
> foreach (ManagementObject wmi_CD in searcher.Get())
> {
> if (wmi_CD["SerialNumber"] == null)
> Console.WriteLine("None");
> else
> //Console.WriteLine(wmi_CD["Name"].ToString());
> //Console.WriteLine(wmi_CD["Drive"].ToString());
> Console.WriteLine(wmi_CD["VolumeSerialNumber"].ToString());
> }
>
> and if you also want to match the query results to your CD/DVD drives, I
> suggest you can check its Name and Drive property as the above comment out
> code.
>
> By the way, some CD/DVD disks don't have the serial numbers, the
> VolumeSerialNumber will be empty on those disks.
>
>
> Thanks!
>
> Best regards,
>
> Gary Chang
> Microsoft Community Support
> --------------------
> Get Secure! ¡§C www.microsoft.com/security
> Register to Access MSDN Managed Newsgroups!
> http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.asp
> &SD=msdn
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
.
- Follow-Ups:
- RE: CD/DVD Media SerialNumber
- From: "Gary Chang[MSFT]"
- RE: CD/DVD Media SerialNumber
- References:
- RE: CD/DVD Media SerialNumber
- From: "Gary Chang[MSFT]"
- RE: CD/DVD Media SerialNumber
- Prev by Date: RE: December EntLib and Configuration Block
- Next by Date: Re: December EntLib and Configuration Block
- Previous by thread: RE: CD/DVD Media SerialNumber
- Next by thread: RE: CD/DVD Media SerialNumber
- Index(es):
Relevant Pages
|