English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

用vb6.0如何查出隨身碟的名稱及所在磁碟位置?
例如說 : 本機磁碟 (C:)
DVD/RW 磁碟 (D:)
隨身碟 (E:)
用Text1.text (顯示磁碟機名稱(本機磁碟))
Text2.text(顯示磁碟機位置(C:))
用VB6.0要如何寫呢?
請各位前輩指導一下

2006-03-07 18:23:45 · 1 個解答 · 發問者 Nick 5 in 電腦與網際網路 程式設計

1 個解答

'以下程式是列出所有磁碟機的名稱,類型,標籤;須用到APIPrivate Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As LongPrivate Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As LongPrivate 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 LongPrivate Sub Command1_Click()    Dim T As Long, S As String, D As String, P As Integer    Dim E As Long, L As String    S = String$(255, Chr(0))    GetLogicalDriveStrings 255, S        Do        P = InStr(S, Chr(0)): D = Left(S, P - 1)        If Len(D) = 0 Then Exit Do        S = Mid(S, P + 1): T = GetDriveType(D)        L = String$(255, Chr(0))        GetVolumeInformation Left(D, 3), L, 255, E, 0, 0, F, 255        L = Left$(L, InStr(L, Chr$(0)) - 1)        Print "磁碟路徑 : "; Left(D, 3)        Print "類型 : "; GetN(T), " 標籤 : "; L; Tab(1)    Loop Until P <= 0End SubFunction GetN(N As Long)    Select Case N        Case 1            GetN = "目錄不存在"        Case 2            GetN = "抽取式磁碟(軟碟)"        Case 3            GetN = "硬碟機"        Case 4            GetN = "遠端(網路)儲存裝置"        Case 5            GetN = "光碟機"        Case 6            GetN = "RAM Disk"        Case Else            GetN = "無從判斷"    End SelectEnd Function

2006-03-10 11:56:34 補充:
Nick大,由於你設定不接受網友來信,所以無法回信給你XD.至於磁碟機的ID求法我找很久找不到,GetVolumeInformation Left(D, 3), L, 255, E, 0, 0, F, 255,其中的E(lpVolumeSerialNumber)是磁碟機序號不知道是否是你要的?

2006-03-08 16:48:17 · answer #1 · answered by W.J.S. 7 · 0 0

fedest.com, questions and answers