strComputer = “.”Set objWMIService = GetObject( “winmgmts:\\” & strComputer & “\root\cimv2”) Set colItems = objWMIService.ExecQuery (“Select * From Win32_LogicalDisk Where DeviceID = 'A:'”)
For Each objItem in colItems
intFreeSpace = objItem.FreeSpace
If IsNull(intFreeSpace) Then
Wscript.Echo "There is no disk in the floppy drive."
Else
Wscript.Echo "There is a disk in the floppy drive."
End If
Next
foreach ($objItem in $colItems)
{
$intFreeSpace = $objItem.FreeSpace
if ($intFreeSpace -eq $null) { "There is no disk in the floppy drive." }
else { "There is a disk in the floppy drive." }
}
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk")
For Each objDisk in colDisks
Wscript.Echo "DeviceID: "& vbTab _
& objDisk.DeviceID
Select Case objDisk.DriveType
Case 1
Wscript.Echo "No root directory. " & "Drive type could not be " & "determined."
Case 2
Wscript.Echo "DriveType: "& vbTab & "Removable drive."
Case 3
Wscript.Echo "DriveType: "& vbTab & "Local hard disk."
Case 4
Wscript.Echo "DriveType: "& vbTab & "Network disk."
Case 5
Wscript.Echo "DriveType: "& vbTab & "Compact disk."
Case 6
Wscript.Echo "DriveType: "& vbTab & "RAM disk."
Case Else
Wscript.Echo "Drive type could not be" & " determined."
End Select
Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery ("Select * from Win32_LogicalDisk")
For Each objDisk in colDisks
Wscript.Echo "DeviceID: " & objDisk.DeviceID
Wscript.Echo "Free Disk Space: " & objDisk.FreeSpace
Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colVolumes = objWMIService.ExecQuery ("Select * from Win32_Volume Where Name = 'K:\\'")
For Each objVolume in colVolumes
errResult = objVolume.Defrag()
Next
'使用磁盘驅動器裝置標識符 ' 尋找相關聯的分割區查詢 = “ASSOCIATORS OF {Win32_DiskDrive.DeviceID='” _ & wmiDiskDrive.DeviceID & “'} WHERE AssocClass = Win32_DiskDriveToDiskPartition”
設定 wmiDiskPartitions = wmiServices.ExecQuery(query)
針對每個 wmiDiskPartition In wmiDiskPartitions '使用分割區裝置標識符尋找邏輯磁碟 Set wmiLogicalDisks = wmiServices.ExecQuery _ (“ASSOCIATORS OF {Win32_DiskPartition.DeviceID='” _ & wmiDiskPartition.DeviceID & “'} WHERE AssocClass = Win32_LogicalDiskToPartition”)
For Each wmiLogicalDisk In wmiLogicalDisks
WScript.Echo "Drive letter associated" _
& " with disk drive = " _
& wmiDiskDrive.Caption _
& wmiDiskDrive.DeviceID _
& VbNewLine & " Partition = " _
& wmiDiskPartition.DeviceID _
& VbNewLine & " is " _
& wmiLogicalDisk.DeviceID
Next
Next
Next