For getting information about Hard disk follow step:
1) Add reference "System.Management"
(For showing how to add reference click here)
2) Add name space
using System.Management;
///////////////// CODE /////////////////////
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Management;
namespace HaardDiskInfoCSharp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// Getting information about hard disk;
ManagementObjectSearcher mosDisks = new ManagementObjectSearcher("Select * from Win32_DiskDrive");
foreach (ManagementObject moDisk in mosDisks.Get())
{
cmbHDD.Items.Add(moDisk["Model"].ToString());
}
}
private void cmbHDD_SelectedIndexChanged_1(object sender, EventArgs e)
{
lblType.Text = "-";
lblModel.Text = "-";
lblSerial.Text = "-";
lblInterface.Text = "-";
lblCapacity.Text = "-";
lblPartitions.Text = "-";
lblSignature.Text = "-";
lblFirmware.Text = "-";
lblCylinders.Text = "-";
lblSectors.Text = "-";
lblHeads.Text = "-";
lblTracks.Text = "-";
lblBytesPerSector.Text = "-";
lblSectorPerTrack.Text = "-";
lblTracksPerCylinder.Text = "-";
ManagementObjectSearcher mosDisk = new ManagementObjectSearcher("Select * From Win32_DiskDrive Where Model='" + cmbHDD.SelectedItem + "'");
foreach (ManagementObject moDisk in mosDisk.Get())
{
try
{
lblType.Text = moDisk["Name"].ToString();
}
catch { }
try
{
lblModel.Text = moDisk["Model"].ToString();
}
catch { }
try
{
lblSerial.Text = moDisk["SerialNumber"].ToString();
}
catch { }
try
{
lblInterface.Text = moDisk["InterfaceType"].ToString();
}
catch { }
try
{
lblCapacity.Text = moDisk["Size"].ToString() + "bytes(" + Math.Round(((((double)Convert.ToDouble(moDisk["Size"]) / 1024) / 1024) / 1024), 2) + "GB)";
}
catch { }
try
{
lblPartitions.Text = moDisk["Partitions"].ToString();
}
catch { }
try
{
lblSignature.Text = moDisk["Signature"].ToString();
}
catch { }
try
{
lblFirmware.Text = moDisk["FirmwareRevision"].ToString();
}
catch { }
try
{
lblCylinders.Text = moDisk["TotalCylinders"].ToString();
}
catch { }
try
{
lblSectors.Text = moDisk["Totalsectors"].ToString();
}
catch { }
try
{
lblHeads.Text = moDisk["TotalHeads"].ToString();
}
catch { }
try
{
lblTracks.Text = moDisk["TotalTracks"].ToString();
}
catch { }
try
{
lblBytesPerSector.Text = moDisk["BytesPerSector"].ToString();
}
catch { }
try
{
lblSectorPerTrack.Text = moDisk["SectorsPerTrack"].ToString();
}
catch { }
try
{
lblTracksPerCylinder.Text = moDisk["TracksPerCylinder"].ToString();
}
catch { }
}
}
}
}
/////////////////////////////////////////////////////////////////
Download Code :Hard_diskinfo.rar
See Also :
-- /\/ir@\/ <(.'.)> (For showing how to add reference click here)
2) Add name space
using System.Management;
///////////////// CODE /////////////////////
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Management;
namespace HaardDiskInfoCSharp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// Getting information about hard disk;
ManagementObjectSearcher mosDisks = new ManagementObjectSearcher("Select * from Win32_DiskDrive");
foreach (ManagementObject moDisk in mosDisks.Get())
{
cmbHDD.Items.Add(moDisk["Model"].ToString());
}
}
private void cmbHDD_SelectedIndexChanged_1(object sender, EventArgs e)
{
lblType.Text = "-";
lblModel.Text = "-";
lblSerial.Text = "-";
lblInterface.Text = "-";
lblCapacity.Text = "-";
lblPartitions.Text = "-";
lblSignature.Text = "-";
lblFirmware.Text = "-";
lblCylinders.Text = "-";
lblSectors.Text = "-";
lblHeads.Text = "-";
lblTracks.Text = "-";
lblBytesPerSector.Text = "-";
lblSectorPerTrack.Text = "-";
lblTracksPerCylinder.Text = "-";
ManagementObjectSearcher mosDisk = new ManagementObjectSearcher("Select * From Win32_DiskDrive Where Model='" + cmbHDD.SelectedItem + "'");
foreach (ManagementObject moDisk in mosDisk.Get())
{
try
{
lblType.Text = moDisk["Name"].ToString();
}
catch { }
try
{
lblModel.Text = moDisk["Model"].ToString();
}
catch { }
try
{
lblSerial.Text = moDisk["SerialNumber"].ToString();
}
catch { }
try
{
lblInterface.Text = moDisk["InterfaceType"].ToString();
}
catch { }
try
{
lblCapacity.Text = moDisk["Size"].ToString() + "bytes(" + Math.Round(((((double)Convert.ToDouble(moDisk["Size"]) / 1024) / 1024) / 1024), 2) + "GB)";
}
catch { }
try
{
lblPartitions.Text = moDisk["Partitions"].ToString();
}
catch { }
try
{
lblSignature.Text = moDisk["Signature"].ToString();
}
catch { }
try
{
lblFirmware.Text = moDisk["FirmwareRevision"].ToString();
}
catch { }
try
{
lblCylinders.Text = moDisk["TotalCylinders"].ToString();
}
catch { }
try
{
lblSectors.Text = moDisk["Totalsectors"].ToString();
}
catch { }
try
{
lblHeads.Text = moDisk["TotalHeads"].ToString();
}
catch { }
try
{
lblTracks.Text = moDisk["TotalTracks"].ToString();
}
catch { }
try
{
lblBytesPerSector.Text = moDisk["BytesPerSector"].ToString();
}
catch { }
try
{
lblSectorPerTrack.Text = moDisk["SectorsPerTrack"].ToString();
}
catch { }
try
{
lblTracksPerCylinder.Text = moDisk["TracksPerCylinder"].ToString();
}
catch { }
}
}
}
}
/////////////////////////////////////////////////////////////////
Download Code :Hard_diskinfo.rar
See Also :
- how to crack IDM
- How to change name of start button in xp
- how to connect to facebook without Internet connec...
- How to customize send to menu.
- How to hide folder without any software.
0 comments:
Post a Comment
Thanks for comment