第一次進行WMI開發,是與一個門禁系統進行對接。
已經成功實作了資料的獲取,采用如下方式:
m_hRes = m_pService->ExecQuery(
bstr_t("WQL"),
bstr_t(mp_strQueryCMD),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&m_pEnumerator);
但是要往系統里增加資料的時候,不知道如何實作。提供了VB及C#的歷程,不知道如何在C++里實作
VB Demo:
var wbemServices = GetObject("winmgmts://./root/onguard");
var cardholderClass = wbemServices.Get("Lnl_Cardholder");
var cardholder = cardholderClass.SpawnInstance_();
cardholder.FirstName = "John";
cardholder.LastName = "Smith";
cardholder.City = "Rochester";
var cardholderPath = cardholder.Put_();
cardholder = wbemServices.Get(cardholderPath);
// use cardholder object...C# demo:
WindowsImpersonationContext impersonatedUser = WindowsIdentity.GetCurrent().Impersonate();
//Get the badge class object
ManagementClass badgeClass = new ManagementClass("root\\OnGuard","Lnl_Badge",null);
//Create a new instance of the Badge
ManagementObject newBadgeInstance = badgeClass.CreateInstance();
newBadgeInstance["ID"] = 10000;
newBadgeInstance["PERSONID"] = 3;
newBadgeInstance["STATUS"] = 1; //Active
newBadgeInstance["TYPE"] = 1; // Employee
newBadgeInstance["DEST_EXEMPT"] = 0; // Sometimes teh value is required
// We Could just call Put, but this way we will never know what BADGEKEY (and other defaults) got assigned,
// call the "AddBadge" static method instead
//newBadgeInstance.Put(); //to commit the new instance.
//Get an input parameters object for AddBadge method
ManagementBaseObject inParams = badgeClass.GetMethodParameters("AddBadge");
inParams.Properties["BadgeIn"].Value = newBadgeInstance;
//Execute the method
ManagementBaseObject outParamObject = badgeClass.InvokeMethod ("AddBadge", inParams, null);
if(outParamObject!=null)
{
//Display results
object outObj = outParamObject["BadgeOut"];
ManagementBaseObject addedBadge = (ManagementBaseObject)outObj;
Console.WriteLine("Badgekey of the badge added: " + addedBadge["BADGEKEY"]);
Console.WriteLine("Badge ID of the badge added: " + addedBadge["ID"]);
}
else
{
Console.WriteLine("Failed to add the badge. Check the DataConduIT.log for details");
}
//Undo impersonation now that we're done
impersonatedUser.Undo();
以上是2個不同的功能,有大俠能給我點指點,如何在C++中實作嗎,非常感謝。
uj5u.com熱心網友回復:
求教WMI開發框架啊 謝謝了uj5u.com熱心網友回復:
剛開始使用不知道代碼怎么開始寫,求教呀,非常感謝了,用VS2010可以寫程式么?uj5u.com熱心網友回復:
Creating a WMI Application Using C++uj5u.com熱心網友回復:
謝謝
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/153550.html
