VC下怎么才能判断哪个分区是系统分区? 如果在C、D分区都装了操作系统,怎么才能知道当前系统是从那个分区启动的?

flaring 2005-07-21 01:38:23
如果能判断, 如何判断?
如果不能判断, 也请说明原因?

多谢高手指教
...全文
312 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
qinghai0011 2010-06-23
  • 打赏
  • 举报
回复
GetWindowsDirectory只是得到本地硬盘的分区信息,那如果我在电脑上外接一块硬盘,如何判断某个分区是否是系统分区啊
idAnts 2005-07-21
  • 打赏
  • 举报
回复
你不是得到分区了,根据分区确定硬盘可以这样做:

HANDLE hDevice;
DWORD bytesReturned;
char rawDiskName[] = "\\\\.\\C:";//假定是c分区


hDevice = CreateFile(rawDiskName, GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);

if (hDevice == INVALID_HANDLE_VALUE) return FALSE;

STORAGE_DEVICE_NUMBER deviceInfo;
BOOL retcode=DeviceIoControl(hDevice,
IOCTL_STORAGE_GET_DEVICE_NUMBER,
NULL,
0,
&deviceInfo,
sizeof(deviceInfo),
&bytesReturned,
NULL);

if(retcode==FALSE)
{
CloseHandle(hDevice);
return FALSE;
}

*diskNumberPtr = deviceInfo.DeviceNumber;
flaring 2005-07-21
  • 打赏
  • 举报
回复
谢谢楼上的回答。

想再问一句,如果我有两块硬盘,都可以对系统进行boot,我怎么才能知道当前正在运行的系统是从哪个硬盘boot进来的呢?
WuOu 2005-07-21
  • 打赏
  • 举报
回复
该说的楼上都说了,顶一下了.
surstar 2005-07-21
  • 打赏
  • 举报
回复
GetWindowsDirectory
返回后,再处理一下路径就可以了
thinp 2005-07-21
  • 打赏
  • 举报
回复
GetWindowsDirectory
DentistryDoctor 2005-07-21
  • 打赏
  • 举报
回复
可以认为Windows目录的驱就是活动的系统分区
DentistryDoctor 2005-07-21
  • 打赏
  • 举报
回复
GetWindowsDirectory

The GetWindowsDirectory function retrieves the path of the Windows directory. The Windows directory contains such files as applications, initialization files, and help 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 GetWindowsDirectory(
LPTSTR lpBuffer,
UINT uSize
);

Parameters
lpBuffer
[out] Pointer to the buffer to receive the null-terminated string containing the path. This path does not end with a backslash unless the Windows directory is the root directory. For example, if the Windows directory is named Windows on drive C, the path of the Windows directory retrieved by this function is C:\Windows. If the system was installed in the root directory of drive C, the path retrieved is C:\.
uSize
[in] Maximum size of the buffer specified by the lpBuffer parameter, in TCHARs. This value should be set to MAX_PATH.

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧