Get the drive list (C #) using WMI

zhaozj2021-02-16  66

The following is a sample code:

First reference System.Management.dll,

Using system.management;

SELECTQUERY? Query?

=

??????????????????

New

? SelectQuery

"

SELECT? *? From? Win32_logicaldisk? Where? DriveType? =? 3

"

); ???????????? managementObjectsearchSearcher? Searcher?

=

??????????????????

New

? ManagementObjectSearcher (query); ????????????

Foreach

? (ManagementBaseObject? Envvar?

in

? Searcher.get ()) ?????????????

{?????????????????????????? THISLISTBOX1.Items.Add (Envvar ["name"]. TOSTRING ()); ????????????}

If the DriveType in the query statement is 2, it will get a floppy drive. If it is 5, the optical drive will be obtained.

转载请注明原文地址:https://www.9cbs.com/read-14665.html

New Post(0)