逻辑驱动器个数和盘符获取GetLogicalDrives和GetLogicalDriverStrings

获取逻辑驱动器有两个函数GetLogicalDrives和GetLogicalDriverStrings

MSDN:GetLogicalDrives函数介绍

MSDN :GetLogicalDriverStrings函数介绍

一、盘符和标卷的获取 GetLogicalDriverStrings


// ConsoleApplication3.cpp : 定义控制台应用程序的入口点。
//#include "stdafx.h"
#include    
#include    #define BUFSIZE 1024int main(int   argc, char   **argv)
{TCHAR VolumeName[256];TCHAR szLogicDriveStrings[BUFSIZE];PCHAR szDrive;ZeroMemory(szLogicDriveStrings, BUFSIZE);GetLogicalDriveStrings(BUFSIZE - 1, szLogicDriveStrings);szDrive = (PCHAR)szLogicDriveStrings;/*方法二,采用do循环才能GetDriveType(szDrive);do{UINT uDriverType;printf("\n%s\n", 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;}szDrive += (lstrlen(szDrive) + 1);} while (*szDrive != '\x00');*/while(*szDrive){GetVolumeInformation(szDrive, VolumeName, 255, NULL, NULL, NULL, NULL, NULL);printf("%s的卷标:%s\n ", szDrive, VolumeName);szDrive+= (_tcslen(szDrive) + 1);}//system("PAUSE");return   0;
}


二,个数获取GetLogicalDrives


// ConsoleApplication3.cpp : 定义控制台应用程序的入口点。
//#include "stdafx.h"
#include    
#include    #define BUFSIZE 1024
int main()
{DWORD temp;char disk_path[5] = { 0 };int count = 0;int diskmount = 0;temp = GetLogicalDrives();while (temp != 0){if ((temp & 1) != 0)//if ((temp & 0x1) == 1){sprintf_s(disk_path, "%c:", 'A' + count);printf("%s \n", disk_path);diskmount++;}temp >>= 1;count++;}printf("驱动器个数:%d\n", diskmount);return 0;
}



本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部