每个硬盘都有唯一的序列号。
FileSystemObject对象下的Drive对象提供了一整套对硬盘的各种信息的访问对象模型。
可以使用如下的代码获取所有硬盘的序列号:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
Sub QQ1722187970() Dim oFSO Dim oDrive Set oFSO = CreateObject("Scripting.FileSystemObject") For Each oDrive In oFSO.drives With oDrive '硬盘是否准备好 If .IsReady Then '硬盘序列号 Debug.Print .SerialNumber '卷名称 Debug.Print .VolumeName '卷字符 Debug.Print .DriveLetter '硬盘路径 Debug.Print .Path End If End With Next End Sub |
如果要获取具体的指定的硬盘的序列号,先用FileSystemObject对象的GetDrive方法获取硬盘对象,然后使用使用如下的代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
Sub QQ1722187970() Dim oFSO Dim oDrive Set oFSO = CreateObject("Scripting.FileSystemObject") Set oDrive = oFSO.GetDrive("c:") With oDrive '硬盘是否准备好 If .IsReady Then '硬盘序列号 Debug.Print .SerialNumber '卷名称 Debug.Print .VolumeName '卷字符 Debug.Print .DriveLetter '硬盘路径 Debug.Print .Path End If End With End Sub |
发表评论