Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2005

Tip: Looking for answers? Try searching our database.

displaying only 1 WMI object

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
D.Bot - 30 Sep 2005 10:46 GMT
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"]);

}
Willy Denoyette [MVP] - 30 Sep 2005 11:43 GMT
> 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:\
[quoted text clipped - 11 lines]
>
> }

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.Bot - 30 Sep 2005 12:18 GMT
I know my SQL so there is not my problem, it's that this "function" is
expacting more results then it  gets.

>> 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:\
[quoted text clipped - 19 lines]
>
> Willy.
Willy Denoyette [MVP] - 30 Sep 2005 14:54 GMT
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.

>I know my SQL so there is not my problem, it's that this "function" is
>expacting more results then it  gets.
[quoted text clipped - 22 lines]
>>
>> Willy.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.