使用WMI无法在Windows 2012 Server上读取BCDStore信息
发布时间:2020-12-13 20:10:18 所属栏目:Windows 来源:网络整理
导读:我们使用以下函数来获取当前引导配置指定的处理器数量.这个数字纯粹用于记录. 以下功能在XP,Vista,7,2003和2008上可以正常工作,但在Windows 2012 Server上失败. // -1 = not implemented or not allowed// 0 = not limited// 0 = number of processors in th
我们使用以下函数来获取当前引导配置指定的处理器数量.这个数字纯粹用于记录.
以下功能在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: https://stackoverflow.com/questions/7517965/accessing-bcdstore-from-delphi/7527164#7527164 Result := -1; try objWMIService := GetObject('winmgmts:{(Backup,Restore)}.rootwmi: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 on Server 2012 (not VarIsNull(objElement)) then Result := StrToIntDef(objElement.Integer,0) else Result := 0; except on E: EOleSysError do Result := -1; end; end; 如果我尝试在Win2012上运行它,objWBL.GetElement引发EOleSysError异常,文本OLE错误D0000225. Google找不到与此错误代码相关的任何有意义的内容:( 堆栈跟踪表示异常在System.Win.ComObj.DispatchInvokeError中被触发,由DispatchInvoke调用,由VarDispInvoke调用. 所有这些都是使用XE2进行复制的.我可以尝试重复XE3的问题,但我不相信Delphi RTL与它有任何关系. 有谁有任何想法可能的原因这种行为?
GetElement部分:
if objWBL.GetElement($25000061,objElement) and //<-- fails here on Server 2012 (not VarIsNull(objElement)) then Result := StrToIntDef(objElement.Integer,0) else Result := 0; 可以用EnumerateElements替换: if objWBL.EnumerateElements(objArray) then try for i := VarArrayLowBound(objArray,1) to VarArrayHighBound(objArray,1) do begin objElement := objArray[i]; if objElement.Type = $25000061 then Exit(objElement.Integer); end; finally VarClear(objArray); end; 这不会引发EOleException,但是遗憾的是还没有找到NumberOfProcessors元素. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- file-upload – 打开的文件似乎已被锁定,无法在Microsoft E
- 如何在Windows 10上安装pyYAML
- Windows 下安装MongoDB
- Windows – Subversion客户端应用程序[已关闭]
- 使用Microsoft Azure机器学习查看rgl图
- wix – Windows msi:错误1316:指定的帐户已存在
- windows-server-2008 – 通过Powershell创建网络打印机
- 如何制作直径为3xp的圆形javafx按钮?
- Windows – Active Directory如何使组策略允许用户更改其网
- windows-server-2008 – 每个用户的网络监控