so the following code:
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim colDrives : Set colDrives = objFSO.Drives
Di开发者_如何学运维m objWMIService : Set objWMIService = GetObject("winmgmts:")
Dim objLogicalDisk
Dim objDrive
For Each objDrive in colDrives
Set objLogicalDisk =
objWMIService.Get("Win32_LogicalDisk.DeviceID='" & objDrive.DriveLetter & ":'")
Log(objLogicalDisk.DriveType)
Next
is used to get the disk type of each drive on a system. What I want to know is, what do the returned numbers ('3','4','5', etc) refer to? Looking around on the internet I find different answers to what they should be on my system - according to the internet:
Unknown = 0
Removable = 1 ' Removable medium
Fixed = 2 ' Fixed medium (hard disk)
Remote = 3 ' Network drive
CDROM = 4 ' CD-ROM
RAMDisk = 5 ' RAM disk
and according to the data i've gathered so far, 3 = my Local C Drive, 5 = my local D (DVD) Drive, 4 = network drives.
If anyone can help clear up this ambiguity, that would be great :)
I found this post looking for some examples of working with the DriveType property.
FWIW, while Helen clearly provided the right answer, I thought it was also worth noting that a likely reason the OP encountered some confusion in his results is because he was mixing and matching the use of objects from different interfaces.
He started with getting a list of drive objects using FileSystemObject, but then switched to WMI to get the properties he wanted from each drive object. The DriveType property values for the Drive object are different under FileSystemObject than they are under WMI.
The similar reference to what Helen provided for the WMI stuff, but for the FileSystemObject stuff is:
https://msdn.microsoft.com/en-us/library/aa243132(v=vs.60).aspx
Value Meaning
--------------------------
0 Unknown
1 Removable Disk
2 Fixed Disk
3 Network Drive
4 Compact Disc
5 RAM Disk
His results would have matched what he expected if he'd kept everything in FileSystemObject, something like:
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim colDrives : Set colDrives = objFSO.Drives
Dim objDrive
For Each objDrive in colDrives
Wscript.Echo objDrive.DriveType
Next
The official WMI reference is in the MSDN library.
As for your question, the Win32_LogicalDisk
class reference describes the following DriveType
values:
Value Meaning -------------------------- 0 Unknown 1 No Root Directory 2 Removable Disk 3 Local Disk 4 Network Drive 5 Compact Disc 6 RAM Disk
精彩评论