Win32API ディスクのボリュームの情報を取得する GetVolumeInformation

ディスクのボリュームの情報を取得する


使用するAPI

  • GetVolumeInformation

  • #include <windows.h>
    
    int main()
    {
    	BOOL bRet;
    	char szVolumeName[MAX_PATH];
    	DWORD dwVolumeSerialNumber;
    	DWORD dwMaxComponentLength;
    	DWORD dwFileSystemFlags;
    	char szFileSystemName[MAX_PATH];
    
    	bRet = GetVolumeInformation("C:\\", 
    		szVolumeName,
    		sizeof(szVolumeName)/sizeof(szVolumeName[0]),
    		&dwVolumeSerialNumber,
    		&dwMaxComponentLength,
    		&dwFileSystemFlags,
    		szFileSystemName,
    		sizeof(szFileSystemName)/sizeof(szFileSystemName[0]));
    
    	if (!bRet) {
    		return 1;
    	}
    
    	printf("VolumeName = %s\n", szVolumeName);
    	printf("VolumeSerialNumber = %u\n", dwVolumeSerialNumber);
    	printf("MaxComponentLength = %u\n", dwMaxComponentLength);
    	printf("FileSystemName = %s\n", szFileSystemName);
    	
    	printf("FileSystemFlags = ");
    	if (dwFileSystemFlags & FS_CASE_IS_PRESERVED) {
    		printf("FS_CASE_IS_PRESERVED ");
    	}
    	if (dwFileSystemFlags & FS_CASE_SENSITIVE) {
    		printf("FS_CASE_SENSITIVE ");
    	}
    	if (dwFileSystemFlags & FS_UNICODE_STORED_ON_DISK) {
    		printf("FS_UNICODE_STORED_ON_DISK ");
    	}
    
    	return 0;
    }