DWORD GetLogicalDrives()
Declare Function GetLogicalDrives Lib "kernel32" () As Long
返された情報は、ビットマスクの形を取り、bit0がAドライブ、bit1がBドライブ、...として、1であるビットが有効なドライブを示し、0であるビットが無効なドライブを示す。 戻り値は、有効なドライブを表すビットマスク。関数の実行に失敗した場合、0が返される。
void DispLogicalDrives() { DWORD i, d; d = GetLogicalDrives(); printf("有効なドライブの一覧:\n"); for(i=0; i<32; i++) { if((1<<i)&d) printf("%c:\n", 'A'+i); } }
Private Sub DispLogicalDrives() Dim Drives As Long Dim I As Long Dim Bit As Long Dim Msg As String Bit = 1 'ドライブ一覧取得 Drives = GetLogicalDrives() 'メッセージ作成 For I = Asc("A") To Asc("Z") If (Drives And Bit) <> 0 Then Msg = Msg & Chr(I) & ":" & vbCr End If Bit = Bit * 2 Next '表示 MsgBox Msg End Sub