Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > Visual C++
|
Visual C++ Questions specific to Microsoft's Visual C++. For questions not specific to this Microsoft version, use the C++ Programming forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual C++ 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 September 14th, 2010, 12:42 AM
Registered User
 
Join Date: Sep 2010
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Smile Help me, help me(Read information from hard disk)

Could you please help me how to read information from hard disk. E.g: name, byte /sector, sector/cluster, serial, capacity, ...

Thank you very much!
 
Old September 15th, 2010, 02:37 AM
Registered User
 
Join Date: May 2008
Posts: 8
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via AIM to samdoss Send a message via Yahoo to samdoss
Default Reading from Hard disk - Model, Type, Serial No

Its C# code.

using System;
using System.Collections;
using System.Management;

namespace HardDriveDetails
{
class HardDrive
{
private string model = null;
private string type = null;
private string serialNo = null;
public string Model
{
get {return model;}
set {model = value;}
}

public string Type
{
get {return type;}
set {type = value;}
}

public string SerialNo
{
get {return serialNo;}
set {serialNo = value;}
}
}

class TestProgram
{
[STAThread]
static void Main(string[] args)
{
ArrayList hdCollection = new ArrayList();
ManagementObjectSearcher searcher = new
ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");
foreach(ManagementObject wmi_HD in searcher.Get())
{
HardDrive hd = new HardDrive();
hdCollection.Add(hd);
}
searcher = new
ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
int i = 0;
foreach(ManagementObject wmi_HD in searcher.Get())
{
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;
}

foreach(HardDrive hd in hdCollection)
{
Console.WriteLine("Model\t\t: " + hd.Model);
Console.WriteLine("Type\t\t: " + hd.Type);
Console.WriteLine("Serial No.\t: " + hd.SerialNo);
Console.WriteLine();
}

Console.WriteLine("Press [Enter] to exit...");
Console.ReadLine();
}
}
}
The Following User Says Thank You to samdoss For This Useful Post:
motnaichuoichin (September 15th, 2010)
 
Old September 15th, 2010, 06:00 AM
Registered User
 
Join Date: Sep 2010
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Smile

Thank you very much,

But I'm a student and I'm learning VC++ with MFC, I don't know about C# yet, Can you help me a code in VC++, I need it, thanks.





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
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 read Hard Disk sequence number by Java? Edward King J2EE 1 September 19th, 2005 03:29 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.