有多颗硬盘,如何Get当前正在 run的 Windows OS是在第几颗 硬盘上? - C++ Builder / Windows SDK/API
有多颗硬盘,如何Get当前正在 run的 Windows OS是在第几颗 硬盘上?
请大家帮帮忙了...
[解决办法]
读取以下系统目录,不就知道当前操作系统的盘符和目录了吗?
Retrieves the path of the system directory. The system directory contains system files such as dynamic-link libraries, drivers, and font files.
This function is provided primarily for compatibility. Applications should store code in the Program Files folder and persistent data in the Application Data folder in the user's profile. For more information, see ShGetFolderPath.
UINT GetSystemDirectory(
LPTSTR lpBuffer,
UINT uSize
);
Parameters
lpBuffer
[out] A pointer to the buffer to receive the path. This path does not end with a backslash unless the system directory is the root directory. For example, if the system directory is named Windows\System on drive C, the path of the system directory retrieved by this function is C:\Windows\System.
uSize
[in] The maximum size of the buffer, in TCHARs.
Return Value
If the function succeeds, the return value is the length, in TCHARs, of the string copied to the buffer, not including the terminating null character. If the length is greater than the size of the buffer, the return value is the size of the buffer required to hold the path, including the terminating null character.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
Applications should not create files in the system directory. If the user is running a shared version of the operating system, the application does not have write access to the system directory.
或者
Returns the device path to the Windows system disk.
boolean GetSystemDisk(
string Disk
);
Parameters
Disk
[out] The device path to the Windows system disk.
[解决办法]
在获得系统路径后,
String S = ...;
//如: S = "D:\\Windows"
Byte n = S.c_str()[0] - 'A'; // OK n 就是第0,1,2
// n = 3
[解决办法]
这个很困难啊,如果硬盘做了raid呢?把2个硬盘合并为一个分区的话,没有办法分辨是在那个硬盘的