displaying only 1 WMI object

D

D.Bot

I have this to search every diskdrive there is on a computer.
But now I want to show/acces only 1 diskdrive for example only the C:\
drive.

SelectQuery query = new SelectQuery( "Select * from Win32_DiskDrive" );

ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);

foreach (ManagementObject mo in searcher.Get())

{

this.listBox1.Items.Add(mo["DeviceID"]);

}
 
W

Willy Denoyette [MVP]

D.Bot said:
I have this to search every diskdrive there is on a computer.
But now I want to show/acces only 1 diskdrive for example only the C:\
drive.

SelectQuery query = new SelectQuery( "Select * from Win32_DiskDrive" );

ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);

foreach (ManagementObject mo in searcher.Get())

{

this.listBox1.Items.Add(mo["DeviceID"]);

}

Change you query into:
Select * from Win32_DiskDrive where DeviceId='c:'

and check the .NET framework documentation for samples and the WMI
documentation for possible query options.

Willy.
 
D

D.Bot

I know my SQL so there is not my problem, it's that this "function" is
expacting more results then it gets.


Willy Denoyette said:
D.Bot said:
I have this to search every diskdrive there is on a computer.
But now I want to show/acces only 1 diskdrive for example only the C:\
drive.

SelectQuery query = new SelectQuery( "Select * from Win32_DiskDrive" );

ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);

foreach (ManagementObject mo in searcher.Get())

{

this.listBox1.Items.Add(mo["DeviceID"]);

}

Change you query into:
Select * from Win32_DiskDrive where DeviceId='c:'

and check the .NET framework documentation for samples and the WMI
documentation for possible query options.

Willy.
 
W

Willy Denoyette [MVP]

Ok I see, you are using the Win32_DiskDrive class which denotes a physical
drive, so it's 'DeviceID' property contains the physical device name like:
\\\\.\\PHYSICALDRIVE0. A physical drive has no associated drive letter, as
it can hold one or more partitions that each are logical drives that can
have associated drive letters.
What you are looking for (I guess) is the drive letter, in this case you
should use the Win32_LogicalDisk class.
Starting with the Win32_LogicalDisk you can get at the corresponding
partition by querying for the associators of the Win32_LogicalDisk, one you
have the associated partition (win32_diskpartition) you can get at the
win32_diskdrive by querying for it's associators.

Willy.

D.Bot said:
I know my SQL so there is not my problem, it's that this "function" is
expacting more results then it gets.


Willy Denoyette said:
D.Bot said:
I have this to search every diskdrive there is on a computer.
But now I want to show/acces only 1 diskdrive for example only the C:\
drive.

SelectQuery query = new SelectQuery( "Select * from Win32_DiskDrive" );

ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);

foreach (ManagementObject mo in searcher.Get())

{

this.listBox1.Items.Add(mo["DeviceID"]);

}

Change you query into:
Select * from Win32_DiskDrive where DeviceId='c:'

and check the .NET framework documentation for samples and the WMI
documentation for possible query options.

Willy.
 

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