使用WMI API编辑BCD数据的代码帮助 [英] Help on code to edit BCD data using WMI APIs

查看:328
本文介绍了使用WMI API编辑BCD数据的代码帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我需要使用Microsoft提供的WMI API编辑基于VISTA的BCD存储文件.我的目标是修改给定的BCD文件并编辑osdevice和设备属性,以将WinPE.wim ramdisk文件名替换为给定的.wim文件名.

目前,我已经在C ++中实现了以下读取BCD文件的部分代码并成功地从中加载BcdStore类对象.但是之后,我无法获取BCD标识符的BcdObject实例.我想我需要BcdObject实例来设置所需的属性值.

程序的O/P是:

M:\> MyBCDedit.exe

Hi,

I need to edit VISTA based BCD store file using WMI APIs provided by Microsoft. My goal is to modify the given BCD file and edit osdevice and device attributes to replace WinPE.wim ramdisk file name with some given .wim file name.

Currently I have implemented below partial code in C++ which reads BCD file and successfully loads BcdStore class object out of that. But after that I cannot get BcdObject instance for the BCD identifier. And I guess I would need BcdObject instance to set the required attribute values.

O/P of the program is:

M:\>MyBCDedit.exe

已连接到WMI

Connected to WMI

检索到IWbemClassObject.

IWbemClassObject retrieved.

创建OpenStore的参数.

Exec方法OpenStore成功.

获得了BCD存储对象.

找到了OpenObject方法.

参数设置适用于OpenObject方法.

OpenObject方法无法执行.十六进制:8004102f

对BcdStore类的OpenObject方法的执行调用失败.

 

hr = pSvc-> ExecMethod(bstrObjectName,bstrMthdName ,0,NULL,pInParam,& pOutParam,& pCallResult);

pSvc-> Release();
pLoc-> ; Release();
CoUninitialize();

返回0;
}

hr = pSvc->ExecMethod(bstrObjectName, bstrMthdName, 0, NULL, pInParam, &pOutParam, &pCallResult);

推荐答案

替换此:

hr = pSvc-> ExecMethod(bstrObjectName,bstrMthdName,0,NULL,pInParam,& pOutParam,& pCallResult);

与此:

VARIANT vPath;

Replace this:

    hr = pSvc->ExecMethod(bstrObjectName, bstrMthdName, 0, NULL, pInParam, &pOutParam, &pCallResult);
 
With this:

VARIANT vPath;

BSTR strClassProp = SysAllocString(L ; __ RELPATH"; );

BSTR strClassProp = SysAllocString(L"__RELPATH");

HRESULT小时;

HRESULT hr;

hr = pGotBcdStore-> Get(strClassProp,0,& vPath,0,0);

hr = pGotBcdStore->Get(strClassProp, 0, &vPath, 0, 0);

SysFreeString(strClassProp);

SysFreeString(strClassProp);

//检查HRESULT以查看操作是否成功.

// check the HRESULT to see if the action succeeded.

如果 (SUCCEEDED(hr)&&(V_VT(& vPath)== VT_BSTR) )

if (SUCCEEDED(hr) && (V_VT(&vPath) == VT_BSTR))

{

wprintf(L "类名是%s \ n." ,V_BSTR(& vPath));

    wprintf(L"The class name is %s\n.", V_BSTR(&vPath));

}

其他

else

{

wprintf(L "获取指定对象时出错\ n" );

wprintf(L"Error in getting specified object\n");

}

hr = pSvc-> ExecMethod(V_BSTR(& vPath),bstrMthdName,0,NULL,pInParam,& pOutParam,& pCallResult);

hr = pSvc->ExecMethod(V_BSTR(&vPath), bstrMthdName, 0, NULL, pInParam, &pOutParam, &pCallResult);

VariantClear(& vPath);

VariantClear(&vPath);


这篇关于使用WMI API编辑BCD数据的代码帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆