Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 3rd, 2007, 11:25 PM
Registered User
 
Join Date: May 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Hard Disk Serial Number

Could anybody please help me with a piece of code to get hard disk's serial number using C#, not volume serial number, actual number that manufactures give to hard disks.


Thanks in Advance
Preetha


 
Old May 3rd, 2007, 11:37 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

You will need to query WMI for this. (From WMI you can get both the volume and manuf. serial number)

A simple google search on this should net you plenty of examples.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old May 10th, 2007, 07:58 AM
Authorized User
 
Join Date: May 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi , u can WMI query then u can get the resule.

Please chk in ; www.codeproject.com. there u can get lot idea for WMI ...


With Regards,
Muralidharan.D
 
Old June 20th, 2007, 06:44 PM
Registered User
 
Join Date: Mar 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi,

this can be done in three simple steps:

1. add refrence to System.Management
2. add
Code:
 using System.Management
at the top of your document
3. add the code

Code:
string[] HdSerialNumber;

            ManagementObjectSearcher mos = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");

            int countHD = 0;

            foreach (ManagementObject mo in mos.Get())
            {
                countHD += 1;
            }

            HdSerialNumber = new string[countHD];

            int i = 0;

            foreach (ManagementObject mo in mos.Get())
            {
                if (mo["SerialNumber"].ToString() != null)
                {
                    HdSerialNumber[i] = mo["SerialNumber"].ToString();
                }
                else
                {
                    HdSerialNumber[i] = "";
                }
                i += 1;
            }





Similar Threads
Thread Thread Starter Forum Replies Last Post
Hard Disk Serial Number Asmatullah VB.NET 2002/2003 Basics 1 December 18th, 2007 04:26 PM
Serial Number of the Hard Disk ivanlaw Assembly Language 0 July 15th, 2007 10:15 PM
how to get hard disk serial number in c# imran_mani .NET Framework 1.x 0 May 7th, 2007 03:45 AM
Hard disk serial number alexjiju VS.NET 2002/2003 1 February 3rd, 2007 02:50 PM
How to retreive Hard disk serial no gkrishn01 Java Espanol 0 December 10th, 2004 05:35 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.