RE: CD/DVD Media SerialNumber

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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.
>
>
.



Relevant Pages

  • Re: Burning Jpeg folders to CDVDBurn
    ... I generated the ISO image and saved it to somewhere temporary. ... The Hard drive was flashing and eventually the CD/DVD drive. ... I wanna check first before trying to write another disc. ... Im using CDVDBurn. ...
    (comp.sys.acorn.apps)
  • Re: Whats your favorite all-purpose lens? Hey KW Hart
    ... started in with this story of repairing a CD/DVD with tape. ... floppy disc, and presented as proof, and swore blind the "Tru TV" ... But the police station where they were interragating this guy didn't happen to have a microwave oven handy. ...
    (rec.photo.equipment.35mm)
  • Re: OT-- program to play AVI files??
    ... If you created the CD/DVD by just copying individual *.avi files to the ... disc, you will need to create a new CD/DVD with these files that will have a ... You may have to burn a new second disc with this feature. ...
    (alt.sys.pc-clone.dell)
  • Re: Whats your favorite all-purpose lens? Hey KW Hart
    ... smashing an HD disc with a hammer. ... this story of repairing a CD/DVD with tape. ... then said he meant to say it had been a floppy disc, ...
    (rec.photo.equipment.35mm)
  • Re: Whats your favorite all-purpose lens? Hey KW Hart
    ... shredder, or smashing an HD disc with a hammer. ... started in with this story of repairing a CD/DVD with tape. ... floppy disc, and presented as proof, and swore blind the "Tru TV" ...
    (rec.photo.equipment.35mm)