Informations about HDD

M

midnighthell

I'm trying to get informations about my HDD, and I plan to use
DeviceIoControl, but i don't understand how to use it,:
First of all Function asks me to sign dwIoControlCode (this is
DRIVE_LAYOUT_INFORMATION_EX) and it must be an integer, so how can I found
it as integer.

If anyone have a sample code for this purpose, please sent it to me by
email.


[DllImport("Kernel32.dll", SetLastError = true)]
static extern bool DeviceIoControl(
IntPtr hDevice,
int dwIoControlCode,
IntPtr lpInBuffer,
int nInBufferSize,
IntPtr lpOutBuffer,
int nOutBufferSize,
out int lpBytesReturned,
IntPtr lpOverlapped
);


Thanks a lot
 
W

Willy Denoyette [MVP]

Most (if not all) disk drive info can be obtained using the
System.Management and the WMI classes.
Here's a sample to get you started...

using System;
using System.Management;
// Enum mapped network drives
class App {
public static void Main() {
// Get drive info for first HD drive
ShowHDproperties("Win32_DiskDrive.DeviceId='\\\\.\\PHYSICALDRIVE0'");
}
static void ShowHDproperties(string objectClass) {
ManagementObject hd;
using(hd = new ManagementObject (objectClass))
{
hd.Get();
PropertyDataCollection hdProperties = hd.Properties;
foreach (PropertyData hdProperty in hdProperties ) {
if(hdProperty.Value !=null) // Show only non-null property values
Console.WriteLine("Property = {0}\t Value = {1}",
hdProperty.Name, hdProperty.Value);
}
foreach (ManagementBaseObject b in hd.GetRelated()) {
Console.WriteLine("--------------- {0} -----------------",
b.ClassPath.ToString());
ShowHDassocProperties(b.ToString());
b.Dispose();
}
}
}
static void ShowHDassocProperties(string objectClass) {
ManagementObject hd;
using(hd = new ManagementObject (objectClass))
{
hd.Get();
PropertyDataCollection hdProperties = hd.Properties;
foreach (PropertyData hdProperty in hdProperties ) {
if(hdProperty.Value !=null) // Show only non-null property values
Console.WriteLine("Property = {0}\t Value = {1}",
hdProperty.Name, hdProperty.Value);
}
}
}
}

Willy.
 
M

midnighthell

I dont' know is it problem with my .NET studio or simple I don't
understand, bacause I don't have
System.Managment classes

But thanks a lot.

Willy Denoyette said:
Most (if not all) disk drive info can be obtained using the
System.Management and the WMI classes.
Here's a sample to get you started...

using System;
using System.Management;
// Enum mapped network drives
class App {
public static void Main() {
// Get drive info for first HD drive
ShowHDproperties("Win32_DiskDrive.DeviceId='\\\\.\\PHYSICALDRIVE0'");
}
static void ShowHDproperties(string objectClass) {
ManagementObject hd;
using(hd = new ManagementObject (objectClass))
{
hd.Get();
PropertyDataCollection hdProperties = hd.Properties;
foreach (PropertyData hdProperty in hdProperties ) {
if(hdProperty.Value !=null) // Show only non-null property values
Console.WriteLine("Property = {0}\t Value = {1}",
hdProperty.Name, hdProperty.Value);
}
foreach (ManagementBaseObject b in hd.GetRelated()) {
Console.WriteLine("--------------- {0} -----------------",
b.ClassPath.ToString());
ShowHDassocProperties(b.ToString());
b.Dispose();
}
}
}
static void ShowHDassocProperties(string objectClass) {
ManagementObject hd;
using(hd = new ManagementObject (objectClass))
{
hd.Get();
PropertyDataCollection hdProperties = hd.Properties;
foreach (PropertyData hdProperty in hdProperties ) {
if(hdProperty.Value !=null) // Show only non-null property values
Console.WriteLine("Property = {0}\t Value = {1}",
hdProperty.Name, hdProperty.Value);
}
}
}
}

Willy.



midnighthell said:
I'm trying to get informations about my HDD, and I plan to use
DeviceIoControl, but i don't understand how to use it,:
First of all Function asks me to sign dwIoControlCode (this is
DRIVE_LAYOUT_INFORMATION_EX) and it must be an integer, so how can I found
it as integer.

If anyone have a sample code for this purpose, please sent it to me by
email.


[DllImport("Kernel32.dll", SetLastError = true)]
static extern bool DeviceIoControl(
IntPtr hDevice,
int dwIoControlCode,
IntPtr lpInBuffer,
int nInBufferSize,
IntPtr lpOutBuffer,
int nOutBufferSize,
out int lpBytesReturned,
IntPtr lpOverlapped
);


Thanks a lot
 
N

Nick Malik

Add a reference to your project for System.Management

midnighthell said:
I dont' know is it problem with my .NET studio or simple I don't
understand, bacause I don't have
System.Managment classes

But thanks a lot.

Willy Denoyette said:
Most (if not all) disk drive info can be obtained using the
System.Management and the WMI classes.
Here's a sample to get you started...

using System;
using System.Management;
// Enum mapped network drives
class App {
public static void Main() {
// Get drive info for first HD drive
ShowHDproperties("Win32_DiskDrive.DeviceId='\\\\.\\PHYSICALDRIVE0'");
}
static void ShowHDproperties(string objectClass) {
ManagementObject hd;
using(hd = new ManagementObject (objectClass))
{
hd.Get();
PropertyDataCollection hdProperties = hd.Properties;
foreach (PropertyData hdProperty in hdProperties ) {
if(hdProperty.Value !=null) // Show only non-null property values
Console.WriteLine("Property = {0}\t Value = {1}",
hdProperty.Name, hdProperty.Value);
}
foreach (ManagementBaseObject b in hd.GetRelated()) {
Console.WriteLine("--------------- {0} -----------------",
b.ClassPath.ToString());
ShowHDassocProperties(b.ToString());
b.Dispose();
}
}
}
static void ShowHDassocProperties(string objectClass) {
ManagementObject hd;
using(hd = new ManagementObject (objectClass))
{
hd.Get();
PropertyDataCollection hdProperties = hd.Properties;
foreach (PropertyData hdProperty in hdProperties ) {
if(hdProperty.Value !=null) // Show only non-null property values
Console.WriteLine("Property = {0}\t Value = {1}",
hdProperty.Name, hdProperty.Value);
}
}
}
}

Willy.



midnighthell said:
I'm trying to get informations about my HDD, and I plan to use
DeviceIoControl, but i don't understand how to use it,:
First of all Function asks me to sign dwIoControlCode (this is
DRIVE_LAYOUT_INFORMATION_EX) and it must be an integer, so how can I found
it as integer.

If anyone have a sample code for this purpose, please sent it to me by
email.


[DllImport("Kernel32.dll", SetLastError = true)]
static extern bool DeviceIoControl(
IntPtr hDevice,
int dwIoControlCode,
IntPtr lpInBuffer,
int nInBufferSize,
IntPtr lpOutBuffer,
int nOutBufferSize,
out int lpBytesReturned,
IntPtr lpOverlapped
);


Thanks a lot
 
M

midnighthell

A I'm new in C#, so I didn't know for that

Thanks, now It's working
Nick Malik said:
Add a reference to your project for System.Management

midnighthell said:
I dont' know is it problem with my .NET studio or simple I don't
understand, bacause I don't have
System.Managment classes

But thanks a lot.

Willy Denoyette said:
Most (if not all) disk drive info can be obtained using the
System.Management and the WMI classes.
Here's a sample to get you started...

using System;
using System.Management;
// Enum mapped network drives
class App {
public static void Main() {
// Get drive info for first HD drive
ShowHDproperties("Win32_DiskDrive.DeviceId='\\\\.\\PHYSICALDRIVE0'");
}
static void ShowHDproperties(string objectClass) {
ManagementObject hd;
using(hd = new ManagementObject (objectClass))
{
hd.Get();
PropertyDataCollection hdProperties = hd.Properties;
foreach (PropertyData hdProperty in hdProperties ) {
if(hdProperty.Value !=null) // Show only non-null property values
Console.WriteLine("Property = {0}\t Value = {1}",
hdProperty.Name, hdProperty.Value);
}
foreach (ManagementBaseObject b in hd.GetRelated()) {
Console.WriteLine("--------------- {0} -----------------",
b.ClassPath.ToString());
ShowHDassocProperties(b.ToString());
b.Dispose();
}
}
}
static void ShowHDassocProperties(string objectClass) {
ManagementObject hd;
using(hd = new ManagementObject (objectClass))
{
hd.Get();
PropertyDataCollection hdProperties = hd.Properties;
foreach (PropertyData hdProperty in hdProperties ) {
if(hdProperty.Value !=null) // Show only non-null property values
Console.WriteLine("Property = {0}\t Value = {1}",
hdProperty.Name, hdProperty.Value);
}
}
}
}

Willy.



I'm trying to get informations about my HDD, and I plan to use
DeviceIoControl, but i don't understand how to use it,:
First of all Function asks me to sign dwIoControlCode (this is
DRIVE_LAYOUT_INFORMATION_EX) and it must be an integer, so how can I found
it as integer.

If anyone have a sample code for this purpose, please sent it to me by
email.


[DllImport("Kernel32.dll", SetLastError = true)]
static extern bool DeviceIoControl(
IntPtr hDevice,
int dwIoControlCode,
IntPtr lpInBuffer,
int nInBufferSize,
IntPtr lpOutBuffer,
int nOutBufferSize,
out int lpBytesReturned,
IntPtr lpOverlapped
);


Thanks a lot
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top