【发布时间】:2013-02-27 23:44:15
【问题描述】:
我需要将引导管理器映射到一个分区号:
Manufacturer Recovery partition = Partition 0
Boot manager = Partition 1
C:\ = Partition 2
D:\ = Partition 3
对于已挂载的分区,例如 C:\ 或 D:\,我使用 IOCTL_STORAGE_GET_DEVICE_NUMBER 来检索分区号。
现在我想做一些类似的事情来获取 Windows 启动管理器的编号。我不能假设 BootMgr 是 100 MB 分区或系统分区的前一个分区。
我查看了IOCTLs related to disk geometry,但没有发现任何有用的东西。我需要将 Boot Manager 分区与 100 MB 制造商的 Recovery 分区区分开来。
BCDEDIT.exe 工具显示所需的信息;
Identificador {bootmgr}
device partition=\Device\HarddiskVolume1
description Windows Boot Manager
locale es-ES
inherit {globalsettings}
extendedinput Yes
default {current}
resumeobject {5586dd33-361b-11e0-8df8-0018716eb820}
displayorder {current}
toolsdisplayorder {memdiag}
timeout 30
customactions 0x1000085000001
0x5400000f
custom:5400000f {1f473c8f-0c00-11e1-898d-78acc0c157a7}
我正在用 C 语言开发我的应用程序,因此 the BCDEDIT approach implies to include a COM/WMI 依赖于我相对简单的应用程序。
请注意,我说的是使用通过 WMI 检索的“\Device\HarddiskVolume1”打开 BootMgr 分区的句柄,然后使用 IOCTL_STORAGE_GET_DEVICE_NUMBER:
hHandle = CreateFile ("\\\\?\\GLOBALROOT\\Device\\HarddiskVolume1",
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if ( hHandle != INVALID_HANDLE_VALUE )
{
VOLUME_DISK_EXTENTS diskExtents;
DWORD dwSize;
BOOL iRes;
iRes = DeviceIoControl(hHandle,
IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS,
NULL,
0,
(LPVOID) &diskExtents,
(DWORD) sizeof(diskExtents),
(LPDWORD) &dwSize,
NULL);
if (iRes)
{
STORAGE_DEVICE_NUMBER deviceNumber;
DWORD bytesReturned = 0;
iRes = DeviceIoControl(hHandle,
IOCTL_STORAGE_GET_DEVICE_NUMBER,
NULL,
0,
&deviceNumber,
sizeof(deviceNumber),
&bytesReturned, NULL);
对于更简单的解决方法有什么想法吗?
【问题讨论】:
-
我没有在 BCDEdit 输出中看到你想要的。
-
嗯,输出显示 {bootmgr} 是分区 \Device\HarddiskVolume1。考虑到在这台机器上 C: 是 \Device\HarddiskVolume2 而 D: 是 \Device\HarddiskVolume3... 是一种分区枚举。不这么认为?
-
如果 C: 是 \Device\HarddiskVolume1 ?也许这个问题对你有帮助:stackoverflow.com/questions/12488337/…
-
你真的认为bootmgr有自己的分区吗???
-
真的吗?????? bootmgr.exe位于系统分区的根目录!!!
标签: windows hard-drive bootloader