程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Access數據庫 >> 關於Access數據庫 >> 取得磁碟機之Volumn及Serial Number

取得磁碟機之Volumn及Serial Number

編輯:關於Access數據庫
這兩項磁碟機資料須使用API函數方可取得,代碼如下:
Private Declare Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long

Function GetVolumn(X As String) As String
    If Len(X) < 3 Then
        X = Left(X, 1) & ":\"
    Else
        X = Left(X, 3)
    End If
    Dim nRet As Long, VolName As String, VolSN As Long, MaxCompLen As Long
    Dim VolFlags As Long, VolFileSys As String
    VolName = Space$(256)
    VolFileSys = Space$(256)
    nRet = GetVolumeInformation(X, VolName, Len(VolName), _
            VolSN, MaxCompLen, VolFlags, _
            VolFileSys, Len(VolFileSys))
    If nRet = 1 Then
        GetVolumn = VolName
    Else
        GetVolumn = ""
    End If
End Function

Function GetNumber(X As String) As String
    If Len(X) < 3 Then
        X = Left(X, 1) & ":\"
    Else
        X = Left(X, 3)
    End If
    Dim nRet As Long, VolName As String, VolSN As Long, MaxCompLen As Long
    Dim VolFlags As Long, VolFileSys As String
    VolName = Space$(256)
    VolFileSys = Space$(256)
    nRet = GetVolumeInformation(X, VolName, Len(VolName), _
            VolSN, MaxCompLen, VolFlags, _
            VolFileSys, Len(VolFileSys))
    If nRet = 1 Then
        GetNumber = VolSN
    Else
        GetVolumn = ""
    End If
End Function

前面的Declare陳述式宣告一個API函數(GetVolumeInformation),可取得磁碟機的兩項資料。
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved