EDN Admin
Well-known member
OK, I have another problem with trying to execute InvokeMethod()... I needed to make a change to my .MOF file, compiled it, and it parsed fine, and the changes are reflected in the WMI CIM studio. Now, when I execute InvokeMethod(), I get the oh-so-helpful
message "Generic Failure". I have given full privileges to all users on the WMI namespace. I believe my MOF is ok -- Ill paste it below, with my C# code. BTW - using VS2008 with .NET framework 3.5 on Win7 if that helps.
<div style="color:Black; background-color:White
<pre>ConnectionOptions con = <span style="color:Blue new ConnectionOptions();
con.EnablePrivileges = <span style="color:Blue true;
con.Impersonation = ImpersonationLevel.Impersonate;
ManagementScope s = <span style="color:Blue new ManagementScope(<span style="color:#A31515 "root\WMI", con);
ManagementPath p = <span style="color:Blue new ManagementPath(<span style="color:#A31515 "AcpiTest_MULong");
ManagementClass c = <span style="color:Blue new ManagementClass(s, p, <span style="color:Blue null);
ManagementBaseObject inParams = c.Methods[<span style="color:#A31515 "WMHC"].InParameters;
inParams[<span style="color:#A31515 "Request"] = 0x01;
inParams[<span style="color:#A31515 "Index"] = 0x32;
inParams[<span style="color:#A31515 "Data"] = 0x11;
<span style="color:Blue foreach (ManagementObject mo <span style="color:Blue in c.GetInstances())
{
ManagementBaseObject outParams = mo.InvokeMethod(<span style="color:#A31515 "WMHC", inParams, <span style="color:Blue null);
Console.WriteLine(<span style="color:#A31515 "after write");
outParams[<span style="color:#A31515 "Request"] = 0x00;
outParams[<span style="color:#A31515 "Index"] = 0x32;
outParams[<span style="color:#A31515 "Data"] = 0x00;
outParams = mo.InvokeMethod(<span style="color:#A31515 "WMHC", outParams, <span style="color:Blue null);
<span style="color:Blue break;
}
}
<span style="color:Blue catch (ManagementException err)
{
Console.WriteLine(<span style="color:#A31515 "An error occurred while trying to execute the WMI method: " + err.ErrorInformation + <span style="color:#A31515 " " + err.ToString());
}
[/code]
and my MOF code:
<pre>[WMI,
Dynamic,
Provider("WmiProv"),
Locale("MS\0x409"),
Description("Class used to operate methods in the EC space"),
guid("{F07BB20D-C270-45F5-BC42-839165E1E0F7}")
]
class AcpiTest_MULong
{
[key, read]
string InstanceName;
[read] boolean Active;
[WmiMethodId(1),
Implemented,
read, write,
Description("Test Method")
] uint16 WMHC([in, Description("UChar Request")] uint8 Request,
[in, Description("UChar Index")] uint8 Index,
[in, Description("UChar Data")] uint8 Data);
};
[/code]
View the full article
message "Generic Failure". I have given full privileges to all users on the WMI namespace. I believe my MOF is ok -- Ill paste it below, with my C# code. BTW - using VS2008 with .NET framework 3.5 on Win7 if that helps.
<div style="color:Black; background-color:White
<pre>ConnectionOptions con = <span style="color:Blue new ConnectionOptions();
con.EnablePrivileges = <span style="color:Blue true;
con.Impersonation = ImpersonationLevel.Impersonate;
ManagementScope s = <span style="color:Blue new ManagementScope(<span style="color:#A31515 "root\WMI", con);
ManagementPath p = <span style="color:Blue new ManagementPath(<span style="color:#A31515 "AcpiTest_MULong");
ManagementClass c = <span style="color:Blue new ManagementClass(s, p, <span style="color:Blue null);
ManagementBaseObject inParams = c.Methods[<span style="color:#A31515 "WMHC"].InParameters;
inParams[<span style="color:#A31515 "Request"] = 0x01;
inParams[<span style="color:#A31515 "Index"] = 0x32;
inParams[<span style="color:#A31515 "Data"] = 0x11;
<span style="color:Blue foreach (ManagementObject mo <span style="color:Blue in c.GetInstances())
{
ManagementBaseObject outParams = mo.InvokeMethod(<span style="color:#A31515 "WMHC", inParams, <span style="color:Blue null);
Console.WriteLine(<span style="color:#A31515 "after write");
outParams[<span style="color:#A31515 "Request"] = 0x00;
outParams[<span style="color:#A31515 "Index"] = 0x32;
outParams[<span style="color:#A31515 "Data"] = 0x00;
outParams = mo.InvokeMethod(<span style="color:#A31515 "WMHC", outParams, <span style="color:Blue null);
<span style="color:Blue break;
}
}
<span style="color:Blue catch (ManagementException err)
{
Console.WriteLine(<span style="color:#A31515 "An error occurred while trying to execute the WMI method: " + err.ErrorInformation + <span style="color:#A31515 " " + err.ToString());
}
[/code]
and my MOF code:
<pre>[WMI,
Dynamic,
Provider("WmiProv"),
Locale("MS\0x409"),
Description("Class used to operate methods in the EC space"),
guid("{F07BB20D-C270-45F5-BC42-839165E1E0F7}")
]
class AcpiTest_MULong
{
[key, read]
string InstanceName;
[read] boolean Active;
[WmiMethodId(1),
Implemented,
read, write,
Description("Test Method")
] uint16 WMHC([in, Description("UChar Request")] uint8 Request,
[in, Description("UChar Index")] uint8 Index,
[in, Description("UChar Data")] uint8 Data);
};
[/code]
View the full article