Use WMI to obtain the drive list

Source: Internet
Author: User
In yesterday's Essay: two hard disks and files related tips use APIs for obtaining the list of Hard Disk Partitions. As a reminder of the source of inspiration, WMI is used for implementation, now we have succeeded. Thanks for the ideas provided by the inspiration source.

The following is the sample code:

You must first reference System. Management. dll,

Using System. Management;

SelectQuery query =
New SelectQuery ("SELECT * FROM Win32_LogicalDisk WHERE DriveType = 3 ");

ManagementObjectSearcher searcher =
New ManagementObjectSearcher (query );

Foreach (ManagementBaseObject envVar in searcher. Get ())
{
This. listBox1.Items. Add (envVar ["Name"]. ToString ());
}

If the value of DriveType in the query statement is 2, the drive is obtained. If the value is 5, the drive is obtained.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.