我们使用以下函数来获取当前引导配置指定的处理器数.此数字仅用于记录.
以下功能适用于XP,Vista,7,2003和2008.但是,它在Windows 2012 Server上失败.
// -1 = not implemented or not allowed
// 0 = not limited
// >0 = number of processors in the {current} boot entry
function Internal_GetBCDNumberOfProcessors: integer;
var
objBcdStore : OleVariant;
objElement : OleVariant;
objWBL : OleVariant;
objWMIService: OleVariant;
begin
// for more info, see: http://stackoverflow.com/questions/7517965/accessing-bcdstore-from-delphi/7527164#7527164
Result := -1;
try
objWMIService := GetObject('winmgmts:{(Backup,Restore)}\\.\root\wmi:BcdStore');
if (not VarIsNull(objWMIService)) and
boolean(objWMIService.OpenStore('', objBcdStore)) and
(not VarIsNull(objBcdStore)) and
boolean(objBcdStore.OpenObject('{fa926493-6f1c-4193-a414-58f0b2456d1e}', objWBL)) and
(not VarIsNull(objWBL))
then
if objWBL.GetElement($25000061, objElement) and //<-- fails here …Run Code Online (Sandbox Code Playgroud) 如何使用bcdedit. 例如,我尝试了以下步骤,但未添加启动项。
bcdedit /create /d "LinuxLoader" /application osloader
Run Code Online (Sandbox Code Playgroud)
这将返回一个新的 guid(比如 newguid)
bcdedit /set {newguid} device partition=S:
bcdedit /set {newguid} path \boot\efi\bootx64.efi
bcdedit /set {fwbootmgr} displayorder {newguid} /addfirst
Run Code Online (Sandbox Code Playgroud)
提前致谢。
我正在尝试将此代码片段转换为Delphi,而我却陷入困境for each objWBL in colObjects.
if not objBcdStore.EnumerateObjects( &h10200003, colObjects ) then
WScript.Echo "ERROR objBcdStore.EnumerateObjects( &h10200003 ) failed."
WScript.Quit(1)
end if
for each objWBL in colObjects
WScript.Echo ""
WScript.Echo "Windows Boot Loader"
WScript.Echo "-------------------"
WScript.Echo "identifier " & GetBcdId( objWBL.Id )
If objWBL.Id = current then
if not objWBL.GetElement(BcdOSLoaderInteger_NumberOfProcessors, objElement ) then
WScript.Echo "ERROR WBL GetElement for " & Hex(BcdOSLoaderInteger_NumberOfProcessors) & " failed."
WScript.Quit(1)
end if
WScript.Echo "numproc " & objElement.Integer
if not objWBL.GetElement(BcdOSLoaderBoolean_UseBootProcessorOnly, objElement ) then
WScript.Echo …Run Code Online (Sandbox Code Playgroud) 我需要能够使用c#从引导配置数据存储中访问当前运行的Windows安装程序的标识符GUID.它可以从运行的命令行返回:
bcdedit /enum {current} /v
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是在c#中,如果我尝试直接运行此命令(即使程序以管理员身份运行),我被告知bcdedit不存在.我正在使用:
ProcessStartInfo procStartInfo = new ProcessStartInfo("bcdedit.exe", "/enum {current} /v");
Run Code Online (Sandbox Code Playgroud)
我研究的另一件事是使用WMI,但我必须这样做的唯一参考是http://msdn.microsoft.com/en-us/library/windows/desktop/aa362673(v=vs.85).aspx这不是很有帮助.
最好的解决方案是,如果我不必使用bcdedit,而是可以使用本机WMI类.如何使用C#找到当前的Windows Boot Loader标识符?
所以我可以在powershell脚本中编写bcd命令,就像我在cmd提示符中一样,例如:
bcdedit /default '{current}'
Run Code Online (Sandbox Code Playgroud)
但是我需要一个执行此操作的脚本:
bcdedit /default '{current}'
bcdedit /set '{otherboot}' description "my description"
Run Code Online (Sandbox Code Playgroud)
如果它没有这样做,那将是另一种方式:
bcdedit /default '{otherboot}'
bcdedit /set '{current}' description "my description"
Run Code Online (Sandbox Code Playgroud)
我需要做的是在powershell中找到其他启动的标识符,我不知道如何.所有谷歌搜索都说这样做:
$bcdStore=gwmi -name root\wmi -list bcdstore -enableall
$bcdStore|gm
$result=$bcdStore.OpenStore("") # can also use explicit file name.
$store=$result.Store
Run Code Online (Sandbox Code Playgroud)
但我不知道如何使用它,这似乎有点太复杂.我的意思是应该有一个更简单的方法......不是吗?