Home > Software engineering >  WMI development consult
WMI development consult

Time:11-02

WMI development for the first time, is docking with a entrance guard system,
Has successfully realized the data acquisition, use the following way:
 m_hRes=m_pService - & gt; ExecQuery (
Bstr_t (" WQL "),
Bstr_t (mp_strQueryCMD),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
& M_pEnumerator);


But to increase the data into the system, don't know how to implement, provides the process of VB and c #, don't know how to implement in 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;//the Employee
NewBadgeInstance [" DEST_EXEMPT "]=0;//at teh value is required

//We Could just call Put, but this way We will never know what BADGEKEY (and other defaults) got assigned,
Home//call the "AddBadge" static method
//newBadgeInstance. The Put ();//to commit the new instance.


//Get the an input parameters object for AddBadge method
ManagementBaseObject inParams=badgeClass. GetMethodParameters (" AddBadge ");
InParams. Properties [r]. "BadgeIn" Value=https://bbs.csdn.net/topics/newBadgeInstance;

//the Execute the method
ManagementBaseObject outParamObject=badgeClass. InvokeMethod (" AddBadge inParams, null);

If (outParamObject!=null)
{

//Display the results
The 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"));
}
The else
{
Console. WriteLine (" Failed to add the badge. Check the DataConduIT. The log for details ");

}


//Undo impersonation now that we 'r e done
ImpersonatedUser. Undo ();


These are two different functions, a warrior can give me some advice, how to implement it in c + +, thank you very much,

CodePudding user response:

Ah thank you consult WMI development framework

CodePudding user response:

Just started to use don't know how to start writing code, consult ah, thank you very much, use VS2010 can write programs?

CodePudding user response:

Creating a WMI Application Using c + +

CodePudding user response:

The
reference 3 floor zgl7903 response:
Creating a WMI Application Using c + +
thank you
  • Related