By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,671 Members | 1,568 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,671 IT Pros & Developers. It's quick & easy.

Informations about HDD

P: n/a
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
Nov 15 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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" <mi**********@yahoo.co.uk> wrote in message
news:c0**********@fegnews.vip.hr...
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

Nov 15 '05 #2

P: n/a
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 [MVP]" <wi*************@pandora.be> wrote in message
news:u8**************@TK2MSFTNGP10.phx.gbl...
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" <mi**********@yahoo.co.uk> wrote in message
news:c0**********@fegnews.vip.hr...
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


Nov 15 '05 #3

P: n/a
Add a reference to your project for System.Management

"midnighthell" <mi**********@yahoo.co.uk> wrote in message
news:c0**********@fegnews.vip.hr...
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 [MVP]" <wi*************@pandora.be> wrote in message
news:u8**************@TK2MSFTNGP10.phx.gbl...
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" <mi**********@yahoo.co.uk> wrote in message
news:c0**********@fegnews.vip.hr...
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



Nov 15 '05 #4

P: n/a
A I'm new in C#, so I didn't know for that

Thanks, now It's working
"Nick Malik" <ni*******@hotmail.nospam.com> wrote in message
news:96EWb.291461$na.450272@attbi_s04...
Add a reference to your project for System.Management

"midnighthell" <mi**********@yahoo.co.uk> wrote in message
news:c0**********@fegnews.vip.hr...
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 [MVP]" <wi*************@pandora.be> wrote in message
news:u8**************@TK2MSFTNGP10.phx.gbl...
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" <mi**********@yahoo.co.uk> wrote in message
news:c0**********@fegnews.vip.hr...
> 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
>
>



Nov 15 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.