MFC读写磁盘信息
来源:互联网 发布:小米2s4g网络怎么设置 编辑:程序博客网 时间:2024/05/17 01:11
有五个基本的函数:GetLogicalDrives, GetLogicalDriveStrings, GetDriveType , GetVolumeInformation, SetVolumeLabel . 下面分别说下:
1 GetLogicalDrives
DWORD WINAPI GetLogicalDrives(void);
Retrieves a bitmask (位掩码)representing the currently available disk drives. If the function fails, the return value is zero
0位表示A盘,1位表示B盘, 2位表示C盘,以此类推. 我电脑上运行, 返回值是124 ,124转二进制1111100,所以有C ,D, E,F,G五个盘符
2 GetLogicalDriveStringsW
DWORD WINAPI GetLogicalDriveStrings( _In_ DWORD nBufferLength, _Out_ LPTSTR lpBuffer);
以char array 的方式返回盘符信息, 格式是"C:\\<NULL>D:\<NULL>E:\<NULL><NULL>"
注意 :必须用LPTSTR数组接收返回信息,不能用CString . 如果用CString只能接收第一个<NULL>之前的信息.
CStringList ValumeList;TCHAR buf[100];CString strDriverList;LPCTSTR lpRootPathName=TEXT("c:\\"); //取C盘LPTSTR lpVolumeNameBuffer= new WCHAR[12];//磁盘卷标DWORD nVolumeNameSize=12;// 卷标的字符串长度DWORD VolumeSerialNumber;//硬盘序列号DWORD MaximumComponentLength;// 最大的文件长度LPTSTR lpFileSystemNameBuffer=new WCHAR[10];// 存储所在盘符的分区类型的长指针变量DWORD nFileSystemNameSize=10;// 分区类型的长指针变量所指向的字符串长度DWORD FileSystemFlags;// 文件系统的一此标志GetLogicalDriveStringsW(100, buf);//"C:\\<NULL>D:\<NULL>E:\<NULL><NULL>"int count =0 ;while(count<100){if(buf[count] ==':' ){CString strtemp ;strtemp.AppendChar(buf[count-1]);strtemp.AppendChar(buf[count]);strtemp.AppendChar(buf[count+1]);//strtemp.AppendChar(buf[count+2]);//'/0'ValumeList.AddTail(strtemp);}count++;}
3 GetDriveType
UINT WINAPI GetDriveType( _In_opt_ LPCTSTR lpRootPathName);
Determines whether a disk drive is a removable, fixed, CD-ROM, RAM disk, or network drive.
LPCTSTR RootPathName=TEXT("F:\ ");int type = GetDriveType( RootPathName);
返回值定义在winbase.h中:
#define DRIVE_UNKNOWN 0
#define DRIVE_NO_ROOT_DIR 1
#define DRIVE_REMOVABLE 2
#define DRIVE_FIXED 3
#define DRIVE_REMOTE 4
#define DRIVE_CDROM 5
#define DRIVE_RAMDISK 6
4 GetVolumeInformation
Retrieves information about the file system and volume associated with the specified root directory.
BOOL WINAPI GetVolumeInformation( _In_opt_ LPCTSTR lpRootPathName,
_Out_opt_ LPTSTR lpVolumeNameBuffer,
_In_ DWORD nVolumeNameSize,
_Out_opt_ LPDWORD lpVolumeSerialNumber,
_Out_opt_ LPDWORD lpMaximumComponentLength,
_Out_opt_ LPDWORD lpFileSystemFlags,
_Out_opt_ LPTSTR lpFileSystemNameBuffer,
_In_ DWORD nFileSystemNameSize);
for(int i=0;i<ValumeList.GetCount();i++){ lpRootPathName= ValumeList.GetAt(ValumeList.FindIndex(i)); //用stringlist内容设置盘符 int returnv = GetVolumeInformationW(lpRootPathName, //获取盘符信息 lpVolumeNameBuffer, nVolumeNameSize, &VolumeSerialNumber, &MaximumComponentLength, &FileSystemFlags, lpFileSystemNameBuffer, nFileSystemNameSize); CString strVolumeName = lpVolumeNameBuffer ; if(strVolumeName.Compare(Parameter1)==0) { wcout<< Parameter1.GetBuffer()<<TEXT("--->")<<ValumeList.GetAt(ValumeList.FindIndex(i)).GetBuffer()<<endl; break; } }
5 SetVolumeLabel
Sets the label of a file system volume. 设置盘符的卷标,如果错误返回0 .
if( SetVolumeLabelW(argv[2],argv[3])) //related to UAC ,$err,hr = getlasterror(){ wcout<<TEXT("SetVolumeLabel pass")<<endl;}else{ wcout<<TEXT("SetVolumeLabel fail")<<endl;}
注意:win7上需要调低用户控制权限, 否则设置会失败. //修改用户权限后重启有效哦
- MFC读写磁盘信息
- MFC--获取磁盘信息
- MFC获取磁盘信息
- MFC之磁盘信息
- 动态查看磁盘读写信息
- 在没有打开进程统计磁盘读写统计信息情况下如何监控磁盘读写
- 读写磁盘
- 磁盘信息
- 磁盘信息
- 磁盘读写和数据库读写
- VC++信息安全编程(13)Windows2000/xp/vista/7磁盘扇区读写技术
- VC++信息安全编程(13)Windows2000/xp/vista/7磁盘扇区读写技术
- VC++信息安全编程(13)Windows2000/xp/vista/7磁盘扇区读写技术
- java读写磁盘文件
- 磁盘读写二叉树
- VB读写磁盘分区表
- 监控磁盘读写状况
- 磁盘读写原理
- 13周项目二
- scp ssh 不需要密码登录
- phpcms_v9二次开发后台弹窗口效果
- BAT三巨头开挖大数据
- 振荡器与谐振器(有源晶振无源晶振)
- MFC读写磁盘信息
- 基于谷歌调查报告:移动电商是大趋势,网站功能、支付环节和第三方服务有前途
- 看看孙正义怎么在百度收购PPS过程中横插一杠
- Eclipse快捷键
- 甲骨文公司老板埃里森在耶如大学的…
- Android--DataPicker用法
- 正则表达式
- java常用布局
- Android布局--TabHost的使用