.NET Framework Developer Center >
.NET Development Forums
>
.NET Base Class Library
>
get serial no. not a model no.?
get serial no. not a model no.?
- Hi,
I am trying to get my hard disk serial no, only serial no, actually i got many view but those all ware about model no.
Please any one who has some idea about it, please guide me.
thanks
bye
regards Rajat
Rajat Solanki makes I M P.
Answers
- Hi,
have a look at this link
http://www.codeproject.com/KB/mcpp/DriveInfoEx.aspx?display=PrintAll
Best Regards, C.Gnanadurai ----------------------- Please mark the post as answer if it is helpfull to you- Marked As Answer bymySilverSir Wednesday, November 04, 2009 8:01 AM
All Replies
- Hi,
You can use Win32DiskDrive wmi class to query this information.
Here is a sample.
ManagementObjectSearcher mos = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive"); foreach (ManagementObject mo in mos.Get()) { Console.WriteLine("Caption:" + mo["Caption"].ToString() + ", Serial Number:" + mo["SerialNumber"].ToString()); } - Hi,
Thanks for early reply, but sorry to say, here we can get only model number not serial no.
because I have tried it.
for serial no, is null.
Thanks
bye
regards Rajat.
Rajat Solanki makes I M P. - Hi,
you need to search the Win32_PhysicalMedia for that.
try { ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_PhysicalMedia"); foreach (ManagementObject queryObj in searcher.Get()) { Console.WriteLine("-----------------------------------"); Console.WriteLine("Win32_PhysicalMedia instance"); Console.WriteLine("-----------------------------------"); Console.WriteLine("SerialNumber: {0}", queryObj["SerialNumber"]); } } catch (ManagementException e) { MessageBox.Show("An error occurred while querying for WMI data: " + e.Message); }
If you have got questions about this, just ask.
Mark the thread as answered if the answer helps you. This helps others who have the same problem !
C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/ - Hi,
have a look at this link
http://www.codeproject.com/KB/mcpp/DriveInfoEx.aspx?display=PrintAll
Best Regards, C.Gnanadurai ----------------------- Please mark the post as answer if it is helpfull to you- Marked As Answer bymySilverSir Wednesday, November 04, 2009 8:01 AM
- Both of them provides same result for me.
And for my wd and Fujitsu disks it provides correct serial number. - Hi,
only as addition, the SerialNumber Property of the Win32DiskDrive WMI Class is not avaible for Windows Server 2003, Windows XP, Windows 2000, and Windows NT 4.0 See: http://msdn.microsoft.com/en-us/library/aa394132(VS.85).aspx
So i guess the op isn`t using Vista or Win 7
If you have got questions about this, just ask.
Mark the thread as answered if the answer helps you. This helps others who have the same problem !
C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/ - Hi Heslacher Thanks for your good efforts, but sorry to say, it is not working. still I can get model no. but not serial no. The given example does not give serial no. Please give any other way, any refer dll file or else. Thanks bye Regards Rajat.
Rajat Solanki makes I M P. - Thanks for reply and solve my problem.
Rajat
Rajat Solanki makes I M P. - Hi again,
so i would suggest take a look at Gnanadurai post. Its seems to be a good solution.
If you have got questions about this, just ask.
Mark the thread as answered if the answer helps you. This helps others who have the same problem !
C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/


