bcdedit.exeに直接アクセスする際に多くの問題があるようですが、C#でWMIを使用してBcdStoreにアクセスする方法を理解できました。
ConnectionOptions connectionOptions = new ConnectionOptions();
connectionOptions.Impersonation = ImpersonationLevel.Impersonate;
connectionOptions.EnablePrivileges = true;
// The ManagementScope is used to access the WMI info as Administrator
ManagementScope managementScope = new ManagementScope(@"root\WMI", connectionOptions);
// {9dea862c-5cdd-4e70-acc1-f32b344d4795} is the GUID of the System BcdStore
ManagementObject privateLateBoundObject = new ManagementObject(managementScope, new ManagementPath("root\\WMI:BcdObject.Id=\"{9dea862c-5cdd-4e70-acc1-f32b344d4795}\",StoreFilePath=\"\""), null);
ManagementBaseObject inParams = null;
inParams = privateLateBoundObject.GetMethodParameters("GetElement");
// 0x24000001 is a BCD constant: BcdBootMgrObjectList_DisplayOrder
inParams["Type"] = ((UInt32)0x24000001);
ManagementBaseObject outParams = privateLateBoundObject.InvokeMethod("GetElement", inParams, null);
ManagementBaseObject mboOut = ((ManagementBaseObject)(outParams.Properties["Element"].Value));
string[] osIdList = (string[]) mboOut.GetPropertyValue("Ids");
// Each osGuid is the GUID of one Boot Manager in the BcdStore
foreach (string osGuid in osIdList)
{
ManagementObject currentManObj = new ManagementObject(managementScope, new ManagementPath("root\\WMI:BcdObject.Id=\"" + osGuid + "\",StoreFilePath=\"\""), null);
MessageBox.Show("" + currentManObj.GetPropertyValue("Id"));
}
これにより、BcdStore内のすべてのWindows Boot ManagerのGUIDが取得され、メッセージボックスに表示されます。適切なConnectionOptionsが必要であり、このプログラムを管理者として実行する必要があることに注意してください。
http://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=18233でBCD定数を検索してくれたRossJohnstonと、 http://wwwで彼のプロジェクトをしてくれたTranDinhHopに感謝します。 .codeproject.com / script / Articles / ViewDownloads.aspx?aid = 19208これには、BcdStoreで動作するすべてのC#コードが含まれています(前述の定数を除く)。
アップデート:
使用:
ManagementObject privateLateBoundObject = new ManagementObject(managementScope, new ManagementPath("root\\WMI:BcdObject.Id=\"{fa926493-6f1c-4193-a414-58f0b2456d1e}\",StoreFilePath=\"\""), null);
現在実行中のWindowsBootManagerのBcdObjectを取得します。その後、電話をかける場合:
currentManObj.GetPropertyValue("Id")
現在のブートマネージャーへのリンクである「{fa926493-6f1c-4193-a414-58f0b2456d1e}」とは異なる、現在実行中のWindowsブートマネージャーのGUIDを取得します。
現在のブートマネージャーにリンクするGUID定数を持っているMicrosoftScriptingGuysとそのプロジェクト(http://technet.microsoft.com/en-us/magazine/2008.07.heyscriptingguy.aspx?pr=blog )に感謝します。