GetLogicalDrives加上c++的附加信息
GetLogicalDrives plus additional information C++
我的一个程序需要帮助,它可以在系统上取出可用的驱动器并打印有关驱动器的各种信息。我正在使用vc++,我对c++相当陌生,需要一些高级输入或经验丰富的程序员的示例代码。
这是我当前的源代码:
#include "stdafx.h"
#include Windows.h
#include stdio.h
#include iostream
using namespace std;
int main()
{
// Initial Dummy drive
WCHAR myDrives[] = L" A";
// Get the logical drive bitmask (1st drive at bit position 0, 2nd drive at bit position 1... so on)
DWORD myDrivesBitMask = GetLogicalDrives();
// Verifying the returned drive mask
if(myDrivesBitMask == 0)
wprintf(L"GetLogicalDrives() failed with error code: %dn", GetLastError());
else {
wprintf(L"This machine has the following logical drives:n");
while(myDrivesBitMask) {
// Use the bitwise AND with 1 to identify
// whether there is a drive present or not.
if(myDrivesBitMask & 1) {
// Printing out the available drives
wprintf(L"drive %sn", myDrives);
}
// increment counter for the next available drive.
myDrives[1]++;
// shift the bitmask binary right
myDrivesBitMask >>= 1;
}
wprintf(L"n");
}
system("pause");
}
'
This machine has the following logical drives:
drive C
drive D
drive E
drive F
drive G
drive H
drive I
我需要输出关于每个驱动器的额外信息(也许一个示例将在更短的时间内说明这个故事):
Drive - C:驱动类型:固定Drive Ready Status: True卷标:引导驱动器文件系统类型:NTFS空闲空间:30021926912总驱动器大小:240055742464
Drive - D:驱动类型:固定Drive Ready Status: True卷标:应用数据文件系统类型:NTFS空闲空间:42462507008总驱动器大小:240054693888
我可以使用哪些方法,libs api等来拔出驱动器类型,驱动器状态,卷标签,文件系统类型,可用空间和总驱动器大小?
*旁注,我注意到我的预处理器指令有一个缺陷,特别是在标准I/O头文件中。我知道这不是使用printf的推荐方式cout是类型安全的,也是正确的路径但是我不知道如何在cout中格式化输出,就像在wprintf(L"drive %sn", myDrives);.... so how would you do this with cout??
提前感谢。
您需要查看GetVolumeInformation等函数来检索文件系统信息,如可用空间和卷名。
GetDriveType将为您提供有关驱动器类型的一些基本信息,但USB拇指棒和闪存读取器可以给出令人惊讶的结果。
我不确定你所说的"就绪状态"是什么意思。如果您指的是驱动器中是否存在有效卷,那么您可以尝试CreateFile
的路径为"\"。C:"试着打开音量。如果失败,则没有卷(磁盘)存在。这将用于SD卡读卡器。要做到这一点而不出现错误对话框,您需要先调用SetErrorMode(SEM_NOOPENFILEERRORBOX)
。
要检查驱动器是否准备就绪,您也可以使用GetDiskFreeSpaceEx。如果这失败,驱动器还没有准备好/可用。
下面是一些示例代码:http://pinvoke.net/default.aspx/coredll/GetDiskFreeSpaceEx.html- 正在查找文档以获得PS4平台的C++中的设备信息
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- 奇怪的(对我来说)返回声明 - 在谷歌上找不到任何关于它的信息
- 如何设置一个范围来提取我想要获得的信息
- 如何在C++向量中奇数元素前面加上值-1,我在使用insert函数时遇到了问题
- 系统参数信息A 与 SPI_GETMOUSE 返回 0
- 为什么 gcovr 会生成空覆盖率统计信息?
- thread_local unordered_map加上 AccessibleObjectFromWindow 无法在 WinXP 中运行
- 我已经阅读了很多关于 2d 数组的信息,但我在作业中使用它时遇到了麻烦
- OpenMP 加上unordered_map<字符串、双字符串的缩减>
- 在命名空间名称之前加上 :: 是什么意思?
- 将信息输入到下面显示的结构向量中的正确语法/格式是什么
- 调试符号中缺少 QObject 类信息(编辑但存在其他 Qt 类)
- 为什么数组大小信息可用于"sizeof"运算符和 delete[] 运算符,但在将数组作为参数传递到
- Pisarze - 来自波兰奥林匹克信息学的数据分析任务
- 将数组信息存储到 c++ 向量中有一个"Access violation reading location"
- C++20 个模块在 clang (Windows):在最简单的示例中键入信息错误
- C++ 如何暂停控制台输出,以便用户可以在继续之前阅读信息
- 如何从WebAssembly模块检测浏览器信息?
- GetLogicalDrives加上c++的附加信息