window 根据盘符获取磁盘号
来源:互联网 发布:psd头像源码怎么使用 编辑:程序博客网 时间:2024/06/06 01:17
盘符
查找所有的盘符,并且只显示可移动磁盘,也就是U盘
/*** find all drivers and show removeable drivers*/void CUkeyKitDlg::FindAllDrivers(){ CComboBox* Driver=(CComboBox*)GetDlgItem(IDC_COMBO1); Driver->ResetContent(); DWORD dwNumBytesForDriveStrings;//实际存储驱动器号的字符串长度 HANDLE hHeap; LPSTR lp; CString strLogdrive; //获得实际存储驱动器号的字符串长度 dwNumBytesForDriveStrings=GetLogicalDriveStrings(0,NULL)*sizeof(TCHAR); //如果字符串不为空,则表示有正常的驱动器存在 if (dwNumBytesForDriveStrings!=0) { //分配字符串空间 hHeap=GetProcessHeap(); lp=(LPSTR)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,dwNumBytesForDriveStrings); //获得标明所有驱动器的字符串 GetLogicalDriveStrings(HeapSize(hHeap,0,lp),lp); //将驱动器一个个放到下拉框中 char s[40]; while (*lp!=0) { UINT nDriveType = GetDriveType(lp); if (nDriveType == DRIVE_REMOVABLE){ sprintf(s, "%s (%c:) %d MB", "可移动驱动器", lp[0],getTotalSpace(lp) ); //驱动器是这样的 c:\ d:\ 所以只取第一个字符 Driver->AddString(s); } lp=_tcschr(lp,0)+1; } }}
磁盘号
通过盘符,获取磁盘号
/******************************************************************************* Function: get disk's physical number from its drive letter* e.g. C-->0 (C: is on disk0)* input: letter, drive letter* output: N/A* return: Succeed, disk number* Fail, -1******************************************************************************/DWORD CUkeyKitDlg::GetPhysicalDriveFromPartitionLetter(CHAR letter){ HANDLE hDevice; // handle to the drive to be examined BOOL result; // results flag DWORD readed; // discard results STORAGE_DEVICE_NUMBER number; //use this to get disk numbers CHAR path[DISK_PATH_LEN]; sprintf(path, "\\\\.\\%c:", letter); hDevice = CreateFile(path, // drive to open GENERIC_READ | GENERIC_WRITE, // access to the drive FILE_SHARE_READ | FILE_SHARE_WRITE, //share mode NULL, // default security attributes OPEN_EXISTING, // disposition 0, // file attributes NULL); // do not copy file attribute if (hDevice == INVALID_HANDLE_VALUE) // cannot open the drive { fprintf(stderr, "CreateFile() Error: %ld\n", GetLastError()); return DWORD(-1); } result = DeviceIoControl( hDevice, // handle to device IOCTL_STORAGE_GET_DEVICE_NUMBER, // dwIoControlCode NULL, // lpInBuffer 0, // nInBufferSize &number, // output buffer sizeof(number), // size of output buffer &readed, // number of bytes returned NULL // OVERLAPPED structure ); if (!result) // fail { fprintf(stderr, "IOCTL_STORAGE_GET_DEVICE_NUMBER Error: %ld\n", GetLastError()); (void)CloseHandle(hDevice); return (DWORD)-1; } //printf("%d %d %d\n\n", number.DeviceType, number.DeviceNumber, number.PartitionNumber); (void)CloseHandle(hDevice); return number.DeviceNumber;}/** get totol space of disk* return : MB*/int CUkeyKitDlg::getTotalSpace(const char* lpRootPathName){ unsigned long long available,total,free; if(GetDiskFreeSpaceEx(lpRootPathName,(ULARGE_INTEGER*)&available,(ULARGE_INTEGER*)&total,(ULARGE_INTEGER*)&free)){ return total>>20; }else{ return -1; }}
自己写的grubist.exe 的界面
由于使用的是1.1版本,所以属于一次开发,使用的可以去这里下载想http://download.csdn.net/detail/li740207611/9595323
0 0
- window 根据盘符获取磁盘号
- JAVA获取磁盘盘符
- 获取逻辑磁盘符
- 获取磁盘符信息
- C++获取磁盘符
- 根据盘符获取硬件编号
- 获取盘符所在的物理磁盘号和分区号
- [Windows]_[获取磁盘盘符,类型和容量]
- 根据uuid来挂载磁盘
- 根据日期获取星期号
- 根据分割符获取值
- mac下根据文件路径,获取该文件所在磁盘的总容量和剩余容量
- windows的磁盘操作之四——根据逻辑分区号获得物理磁盘号
- windows的磁盘操作之四——根据逻辑分区号获得物理磁盘号
- windows的磁盘操作之四——根据逻辑分区号获得物理磁盘号
- windows的磁盘操作之四——根据逻辑分区号获得物理磁盘号
- 获取操作系统所在的物理磁盘号
- 获取物理磁盘物理索引号
- C++ :STL 算法unique , unique_copy函数
- net rtmp or hls play url
- Linux用ps命令查找进程PID再用kill命令终止进程的方法
- 【校内互测】Sunshine's book(找规律)
- Ubuntu 界面卡死的办法
- window 根据盘符获取磁盘号
- Python学习笔记五:数字和字符串
- 概率论中的建模思想
- js(javaScript)学习系列--基础
- 理解 Neutron Server 分层模型 - 每天5分钟玩转 OpenStack(69)
- javaScript笔记 (七) 正则表达式
- HDU 5793 A Boring Question (数学)
- 经典算法-给出2n+1个数,其中有2n个数出现过两次,用简便的最方法求出现一次的数
- 利用特征根方程实现通项公式与递推关系的互换