【ドライブ情報取得】


Dim lDrvLtrAscStrt
Dim lDrvLtrAscLast
lDrvLtrAscStrt = asc("A")
lDrvLtrAscLast = asc("Z")
 
On Error Resume Next
Dim lDrvLtrIdx
Dim sDriveLetter
Dim objFSO
Dim objDrive
Dim asDriveTypeTable
asDriveTypeTable = Array("Unknown", "Removable", "HDD", "Network", "CD-ROM", "RAM")
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
For lDrvLtrIdx = lDrvLtrAscStrt to lDrvLtrAscLast
	sDriveLetter = Chr(lDrvLtrIdx)
	If Err.Number = 0 Then
		If objFSO.DriveExists(sDriveLetter) Then
			Set objDrive = objFSO.GetDrive(sDriveLetter)
			If objDrive.IsReady = True Then
				MsgBox "ボリュームラベル:" & objDrive.VolumeName                  & vbNewLine & _
				       "フォルダ:"         & objDrive.Path                        & vbNewLine & _
				       "ルートフォルダ:"   & objDrive.RootFolder                  & vbNewLine & _
				       "種類:"             & asDriveTypeTable(objDrive.DriveType) & vbNewLine & _
				       "ファイルシステム:" & objDrive.FileSystem                  & vbNewLine & _
				       "容量:"             & FormatNumber(objDrive.TotalSize, 0)  & vbNewLine & _
				       "空き領域:"         & FormatNumber(objDrive.FreeSpace, 0)  & vbNewLine & _
				       "シリアルナンバー:" & Hex(objDrive.SerialNumber)
			Else
				MsgBox "準備ができていません"
			End If
		Else
			'Do Nothing
		End If
	Else
		MsgBox Err.Description
	End If
Next
On Error Goto 0
 

最終更新:2016年11月01日 21:13