ボリューム情報の取得             <TOP>


Cドライブのボリューム情報を取得します。

アプリケーションをインストールするPCの識別に使えるかナ・・

GetWindowsDirectory Windowsディレクトリを取得

GetVolumeInformation ボリューム情報の取得

 

 

'================================================================
'= ボリューム情報取得
'=    (GetVolumeInformation2.bas)
'================================================================
#include "Windows.bi"

' Windowsディレクトリのパス名を取得
Declare Function Api_GetWindowsDirectory& Lib "Kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer$, ByVal nSize&)

' ルート ディレクトリが呼び出しで指定されたファイル システムとボリュームについての情報を返す
Declare Function Api_GetVolumeInformation& Lib "Kernel32" Alias "GetVolumeInformationA" (ByVal RootPathName$, ByVal VolNameBuff$, ByVal VolNameSize&, VolSerialNum&, MaxComponentLen&, FileSysFlag&, ByVal FileSysNameBuff$, ByVal FileSysNameSize&)

#define MAX_PATH 260

Var Shared Text1 As Object
Text1.Attach GetDlgItem("Text1") : Text1.SetFontSize 14

'================================================================
'=
'================================================================
Declare Sub MainForm_Start edecl ()
Sub MainForm_Start()
    Var WinDir As String
    Var WkDir As String
    Var VolName As String
    Var VolSerNum As Long
    Var MaxCompoLen As Long
    Var FileSysFlags As Long
    Var FileSysNameBuff As String
    Var txt As String
    Var Ret As Long

    'Windowsがインストールされているドライブを取得
    WinDir = space$(255)
    Ret = Api_GetWindowsDirectory(WinDir, Len(WinDir))
    WinDir = Left$(WinDir, InStr(WinDir, Chr$(0)) - 1)

    'ボリューム情報の取得にはルートパスにする
    WkDir = Left$(WinDir, 3)

    'ボリューム情報取得
    VolName = Space$(MAX_PATH)
    FileSysNameBuff = Space$(MAX_PATH)
    Ret = Api_GetVolumeInformation(WkDir, VolName, MAX_PATH, VolSerNum, MaxCompoLen, FileSysFlags, FileSysNameBuff, MAX_PATH)

    '文字列にはNullが入ってるのでNullをカット
    VolName = Left$(VolName, InStr(VolName, Chr$(0)) - 1)
    FileSysNameBuff = Left$(FileSysNameBuff, InStr(FileSysNameBuff, Chr$(0)) - 1)

    'TextBoxにボリューム情報をセット
    txt = ""
    txt = txt & " WindowsDirectory:" & WinDir & Chr$(13, 10)
    txt = txt & Chr$(13, 10)
    txt = txt & "【 " & WkDir & " 】Information" & Chr$(13, 10)
    txt = txt & " VolumeName         :" & VolName & Chr$(13, 10)
    txt = txt & " VolumeSerialNumber :" & Trim$(Str$(VolSerNum)) & Chr$(13, 10)
    txt = txt & " MaxComponentLength :" & Trim$(Str$(MaxCompoLen)) & Chr$(13, 10)
    txt = txt & " FileSystemFlags    :" & Trim$(Str$(FileSysFlags)) & Chr$(13, 10)
    txt = txt & " FileSystemName     :" & FileSysNameBuff & Chr$(13, 10)

    Text1.SetWindowText txt
End Sub

'================================================================
'=
'================================================================
While 1
    WaitEvent
Wend
Stop
End