已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025标准住宅买卖合同样本
- 2025年工会基础知识考试题库及答案
- 2025成都市临时工劳动合同模板
- 2025年下半年呼和浩特市事业单位招考易考易错模拟试题(共500题)试卷后附参考答案
- 2025年下半年吉林高新区新冠核酸检测实验室(PCR实验室)招聘20人易考易错模拟试题(共500题)试卷后附参考答案
- 2025年下半年吉林长春德惠市事业单位招考(134人)易考易错模拟试题(共500题)试卷后附参考答案
- 2025年下半年吉林通化县事业单位招聘50人(8号)易考易错模拟试题(共500题)试卷后附参考答案
- 2025年下半年吉林直事业单位招考考试(6号)易考易错模拟试题(共500题)试卷后附参考答案
- 2025年下半年吉林市规划编研中心招考工作人员(2号)易考易错模拟试题(共500题)试卷后附参考答案
- 2025年下半年吉林双辽市事业单位招聘56人(2号)易考易错模拟试题(共500题)试卷后附参考答案
- 2023-2024学年北京西城区一六一中高三(上)期中数学试题及答案
- 红色旅游合同范本
- GB/T 20878-2024不锈钢牌号及化学成分
- 高中生考试焦虑心理咨询案例报告
- 《工程结构抗震设计》课件 第10章-地下建筑抗震设计
- SBAR交接班模式在临床运用
- 碎石临时停车场施工方案
- 静电消除作业指导书
- 华侨城集团领导岗位业绩考核管理规定
- 机械设备安全检查表88612
- 培智二年级体育课教案
评论
0/150
提交评论