2
Answers

not getting hard drive serial number

i have tried using the code 
searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
int i = 0;
foreach (ManagementObject wmi_HD in searcher.Get())
{
// get the hard drive from collection
// using index
HardDrive hd = (HardDrive)hdCollection[i];
// get the hardware serial no.
if (wmi_HD["SerialNumber"] == null)
hd.SerialNo = "None";
else
hd.SerialNo = wmi_HD["SerialNumber"].ToString();
++i;
}
 
 but this is not working for windows 8 and higher versions..
Answers (2)
1
Suthish Nair

Suthish Nair

NA 31.7k 4.6m 8y
Interesting...
 
I never got a chance to work on such a project. I need to try it out.
 
Sharing some links, hopes it helps you...
 
http://stackoverflow.com/questions/3502311/how-to-play-a-sound-in-c-net
http://stackoverflow.com/questions/21331412/best-way-to-use-the-system-media-soundplayer-class
 
Here suggesting not to use SoundPlayer due to memory issue...
http://stackoverflow.com/questions/4107886/soundplayer-causing-memory-leaks 
http://www.codeproject.com/Articles/13909/SoundPlayer-bug-Calling-unmanaged-APIs 
 
0
Stefan B

Stefan B

NA 3 376 8y
Hi, thanks a lot,
 
some of those links were  realy heplful! Even though I am still not sure why such a problem might even arise, I guess loading from a file seems to solve it, which is enough for the moment ;)
 
One last question, since this "problem" got me a little hyper nervous regarding memory leaks...

If I have 2 picture resources Pic1 and Pic2 and an ImageButton-Object, which is just some object inherited from UserControl and with a changed OnPaint:
01protected override void OnPaint(PaintEventArgs e)
02 {
03 base.OnPaint(e);
04 //stuff
05 if (this.keyStatus))
06 { this.imageButton.DefaultImage = Resource1.Pic1; }
07 else
08 { this.imageButton.DefaultImage = Resource1.Pic2; }
09 e.Graphics.DrawImage(this.defaultImage, this.ClientRectangle);
10 }

Beside OnPaint not being a good place for assigning DefaultImage (its just here to show you what I mean in a short piece of code), I am just assinging a reference to my precompiled resource here, am I? I am not creating a copy as I would if I would call it with "new Bitmap(Resource1.Pic1)".
So if I change keyStatus every 5 seconds, I would have a very annoying picture on my screen with a lot of chaning, but no problems that the picture changing leaks memory. Correct?


Again, thanks a lot!

Cheers Stefan