




已阅读5页,还剩2页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
include stdafx h define WIN32 DCOM include using namespace std include include include pragma comment lib wbemuuid lib BOOL ManageWMI 函数声明 int tmain int argc TCHAR argv if ManageWMI printf WMI Error getch return 0 BOOL ManageWMI HRESULT hres Step 1 Initialize COM hres CoInitializeEx 0 COINIT MULTITHREADED if FAILED hres cout Failed to initialize COM library Error code 0 x hex hres endl return 1 Program has failed Step 2 Set general COM security levels Note If you are using Windows 2000 you need to specify the default authentication credentials for a user by using a SOLE AUTHENTICATION LIST structure in the pAuthList parameter of CoInitializeSecurity hres CoInitializeSecurity NULL 1 COM authentication NULL Authentication services NULL Reserved RPC C AUTHN LEVEL DEFAULT Default authentication RPC C IMP LEVEL IMPERSONATE Default Impersonation NULL Authentication info EOAC NONE Additional capabilities NULL Reserved if FAILED hres cout Failed to initialize security Error code 0 x hex hres endl CoUninitialize return 1 Program has failed Step 3 Obtain the initial locator to WMI IWbemLocator pLoc NULL hres CoCreateInstance CLSID WbemLocator 0 CLSCTX INPROC SERVER IID IWbemLocator LPVOID if FAILED hres cout Failed to create IWbemLocator object Err code 0 x hex hres ConnectServer bstr t L ROOT CIMV2 Object path of WMI namespace NULL User name NULL current user NULL User password NULL current 0 Locale NULL indicates current NULL Security flags 0 Authority e g Kerberos 0 Context object if FAILED hres cout Could not connect Error code 0 x hex hres Release CoUninitialize return 1 Program has failed cout Connected to ROOT CIMV2 WMI namespace endl Step 5 Set security levels on the proxy hres CoSetProxyBlanket pSvc Indicates the proxy to set RPC C AUTHN WINNT RPC C AUTHN xxx RPC C AUTHZ NONE RPC C AUTHZ xxx NULL Server principal name RPC C AUTHN LEVEL CALL RPC C AUTHN LEVEL xxx RPC C IMP LEVEL IMPERSONATE RPC C IMP LEVEL xxx NULL client identity EOAC NONE proxy capabilities if FAILED hres cout Could not set proxy blanket Error code 0 x hex hres Release pLoc Release CoUninitialize return 1 Program has failed Step 6 Use the IWbemServices pointer to make requests of WMI For example get the name of the operating system IEnumWbemClassObject pEnumerator NULL hres pSvc ExecQuery bstr t WQL bstr t SELECT FROM Win32 NetworkAdapterConfiguration WHERE IPEnabled TRUE WBEM FLAG FORWARD ONLY WBEM FLAG RETURN IMMEDIATELY NULL if FAILED hres cout Query for Network Adapter Configuration failed Error code 0 x hex hres Release pLoc Release CoUninitialize return 1 Program has failed Step 7 Get the data from the query in step 6 IWbemClassObject pclsObj ULONG uReturn 0 while pEnumerator HRESULT hr pEnumerator Next WBEM INFINITE 1 if 0 uReturn break VARIANT vtProp VariantInit hr pclsObj Get L IPSubnet 0 Get the value of the Enable property hr pclsObj Get L IPEnabled 0 Get the value of the MacAddress property if vtProp boolVal hr pclsObj Get L MacAddress 0 wcout MacAddress vtProp bstrVal Get L IPEnabled 0 if vtProp boolVal LONG lstart lend LONG idx 1 BSTR pbstr SAFEARRAY sa hr pclsObj Get L Description 0 if FAILED hr wcout Description vtProp bstrVal Get L DNSHostName 0 if FAILED hr cout DNS vtProp bstrVal Get L IPAddress 0 if
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 我的成长故事在挑战中成长记事作文5篇
- 活动策划与志愿服务合作承诺函9篇
- 技术团队成果报告评审流程模板多版本比对
- (正式版)DB15∕T 3253.5-2023 《食品生产加工小作坊生产规范 第5部分:熟面食》
- 初中英语语法从句学习教案
- 地球妈妈的家书800字(8篇)
- 团队建设与团队沟通辅助工具包
- 客户关怀与服务水平监测表模板
- 知识产权保护与法律合规性检查工具
- 农业种植基地土地托管合同
- 金属学第三章
- 人工智能训练师(5级)培训考试复习题库-上(单选题汇总)
- 小学科学-哪杯水热教学课件设计
- 酒店明住宿清单(水单)
- 《中国儿童维生素A、维生素D临床应用专家共识》解读
- 应用技术推广中心 报告1212
- 教学第七章-无机材料的介电性能课件
- 应急值班值守管理制度
- 外国文学史-总课件
- 《中小企业划型标准规定》补充说明
- 房屋租赁信息登记表
评论
0/150
提交评论