zoukankan      html  css  js  c++  java
  • 使用GetLogicalDriveStrings获取驱动器根路径

    使用GetLogicalDriveStrings获取驱动器根路径,并使用自定义的GetDriveInfo函数获取驱动器的属性。

    VS2012 + win7 x64下调试通过。

    #include <Windows.h>
    #include <stdio.h>
    #include <stdlib.h>
    #define BUFSIZE 1024
    BOOL GetDriverInfo(LPSTR szDrive);
    //int WinMain(HINSTANCE hInstance,HINSTANCE hPreInstance,LPSTR lpCmdLine,int nCmdShow)
    int main(void)
    {
        CHAR szLogicDriveStrings[BUFSIZE];
        PCHAR szDrive;
    
        ZeroMemory(szLogicDriveStrings,BUFSIZE);
    
        GetLogicalDriveStrings(BUFSIZE-1,szLogicDriveStrings);
        szDrive = (PCHAR)szLogicDriveStrings;
    
        do 
        {
            if(!GetDriverInfo(szDrive))
            {
                printf("
    Get Volume Information Error:%d",GetLastError());
    
            }
            szDrive += (lstrlen(szDrive)+1);
        } while (*szDrive !='x00');
    
       system("PAUSE");
        return 0;
    
    }
    
    
    BOOL GetDriverInfo(LPSTR szDrive)
    {
        UINT uDriverType;
        DWORD dwVolumeSerialNumber;
        DWORD dwMaximumComponentlength;
        DWORD dwFileSystemFlags;
        CHAR szFileSystemNameBuffer[BUFSIZE];
        CHAR szDriveName[MAX_PATH];
    
        printf("
    %s
    ",szDrive);
        uDriverType = GetDriveType(szDrive);
    
        switch(uDriverType)
        {
        case DRIVE_UNKNOWN:
            printf("The driver type cannot be determined!");
            break;
        case DRIVE_NO_ROOT_DIR:
            printf("The root path is invalid,for example,no volume is mounted at the path");
            break;
        case DRIVE_REMOVABLE:
            printf("The drive is a type that has removable media,for example:a floppy drive or removable hard disk");
            break;
        case DRIVE_FIXED:
            printf("The drive is a type that cannot be removed, for example,a fixed hard drive");
            break;
        case DRIVE_REMOTE:
            printf("This drive is a remote(network) drive");
            break;
        case DRIVE_CDROM:
            printf("This drive is a CD-ROM drive.");
            break;
        case DRIVE_RAMDISK:
            printf("This drive is a RAM disk");
            break;
        default:
            break;
        }
    
        if (!(GetVolumeInformation(
            szDrive,
            szDriveName,
            MAX_PATH,
            &dwVolumeSerialNumber,
            &dwMaximumComponentlength,
            &dwFileSystemFlags,
            szFileSystemNameBuffer,
            BUFSIZE)))
        {
            return FALSE;
    
        }
    
        if (0!=lstrlen(szDriveName))
        {
            printf("
    Drive Name is %s.
    ",szDriveName);
        }
    
        printf("
    Volume Serial is %u.",dwVolumeSerialNumber );
        printf("
    Maximum Component Length is %u.",dwMaximumComponentlength);
        printf("
    System Type is %s.
    ",szFileSystemNameBuffer);
        
        if (dwFileSystemFlags & FILE_VOLUME_QUOTAS)
        {
    
            printf("The file system supports disk Quotas.
    ");
        }
    
        if (dwFileSystemFlags & FILE_SUPPORTS_REPARSE_POINTS)
        {
            printf("The file system does not support volume mount points.
    ");
    
        }
    
        if (dwFileSystemFlags & FILE_CASE_SENSITIVE_SEARCH)
        {
            printf("The file system supports case-sentitive file name.
    ");
        }
    
        printf("...
    ");
    
        return TRUE;
    
    }
  • 相关阅读:
    Keil MDK中的Code, RO-data , RW-data, ZI-data分别代表什么意思?(转)
    nrf开发笔记一开发软件
    ARM CORTEX-M3的时钟
    stm32之Cortex系统定时器(SysTick)
    micrium ucprobe使用笔记
    C语言结构体初始化的四种方法(转载)
    setsockopt的作用
    Java之RandomAccessFile小结
    疯狂JAVA讲义---第十五章:输入输出(上)流的处理和文件
    java压缩解压zip文件,中文乱码还需要ant.jar包
  • 原文地址:https://www.cnblogs.com/dabiao/p/3576697.html
Copyright © 2011-2022 走看看