Hi,
can someone please tell me why the **** this does not
work as expected:
First at all, thats what a WMI parameter looks like:
public class WMIParameter {
private string pName;
private Type pType;
private object pValue;
public WMIParameter(st ring Name, Type Type, object Value) {
this.pName = Name;
this.pValue = Value;
this.pType = Type;
}
public Type Type {
get {
return this.pType;
}
}
public string Name
{
get
{
return this.pName;
}
}
public object Value
{
get
{
return this.pValue;
}
}
}
private static ManagementBaseO bject
ExecuteWMIMetho dOnRemoteMachin e_ThrowsExcepti on(string TargetMachine,
string ManagementPathS tring,
string MethodName,
WMIParameter[] inParams, string UserName, string Password)
{
try
{
ConnectionOptio ns connOptions = new ConnectionOptio ns();
connOptions.Ena blePrivileges = true;
connOptions.Imp ersonation = ImpersonationLe vel.Impersonate ;
if (UserName != string.Empty && Password != string.Empty)
{
connOptions.Use rname = UserName;
connOptions.Sec urePassword = CreateSecureStr ing(Password);
}
ManagementScope manScope = new
ManagementScope (String.Format( @"\\{0}\ROOT\CI MV2", TargetMachine),
connOptions);
manScope.Connec t();
ObjectGetOption s objectGetOption s = new ObjectGetOption s();
ManagementPath managementPath = new ManagementPath( ManagementPathS tring);
ManagementClass processClass = new ManagementClass (manScope, managementPath,
objectGetOption s);
ManagementBaseO bject Params = processClass.Ge tMethodParamete rs(MethodName);
foreach (WMIParameter wmip in inParams)
{
Params[wmip.Name] = Convert.ChangeT ype(wmip.Value, wmip.Type);
}
ManagementBaseO bject outParams;
if (inParams == null)
{
outParams = processClass.In vokeMethod(Meth odName, null, null);
}
else
{
outParams = processClass.In vokeMethod(Meth odName, Params, null);
}
return outParams;
}
catch (Exception e)
{
throw e;
}
}
I always get a error saying "The Methods Parameter are invalid".
Thats how i call this:
WMIParameter[] wmip = new WMIParameter[2];
wmip[0] = new WMIParameter("R eserved", typeof(Int32), 0);
wmip[1] = new WMIParameter("F lags", typeof(Int32), (Int32)ew);
ExecuteWMIMetho dOnRemoteMachin e_ThrowsExcepti on(TargetMachin eName,
"Win32_Operatin gSystem",
"Win32Shutdown" ,
wmip,
TargetMachineUs erName,
TargetMachineUs erPassword);
I want to hold the call to the WMI methods as transparent as possible, so
hats why i wrote this function. Please can you show me, or if possible
correct this function,...
TIA,...
Regards
Kerem
--
-----------------------
Beste Grüsse / Best regards / Votre bien devoue
Kerem Gümrükcü
Latest Project: http://www.codeplex.com/restarts
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------
"This reply is provided as is, without warranty express or implied."
can someone please tell me why the **** this does not
work as expected:
First at all, thats what a WMI parameter looks like:
public class WMIParameter {
private string pName;
private Type pType;
private object pValue;
public WMIParameter(st ring Name, Type Type, object Value) {
this.pName = Name;
this.pValue = Value;
this.pType = Type;
}
public Type Type {
get {
return this.pType;
}
}
public string Name
{
get
{
return this.pName;
}
}
public object Value
{
get
{
return this.pValue;
}
}
}
private static ManagementBaseO bject
ExecuteWMIMetho dOnRemoteMachin e_ThrowsExcepti on(string TargetMachine,
string ManagementPathS tring,
string MethodName,
WMIParameter[] inParams, string UserName, string Password)
{
try
{
ConnectionOptio ns connOptions = new ConnectionOptio ns();
connOptions.Ena blePrivileges = true;
connOptions.Imp ersonation = ImpersonationLe vel.Impersonate ;
if (UserName != string.Empty && Password != string.Empty)
{
connOptions.Use rname = UserName;
connOptions.Sec urePassword = CreateSecureStr ing(Password);
}
ManagementScope manScope = new
ManagementScope (String.Format( @"\\{0}\ROOT\CI MV2", TargetMachine),
connOptions);
manScope.Connec t();
ObjectGetOption s objectGetOption s = new ObjectGetOption s();
ManagementPath managementPath = new ManagementPath( ManagementPathS tring);
ManagementClass processClass = new ManagementClass (manScope, managementPath,
objectGetOption s);
ManagementBaseO bject Params = processClass.Ge tMethodParamete rs(MethodName);
foreach (WMIParameter wmip in inParams)
{
Params[wmip.Name] = Convert.ChangeT ype(wmip.Value, wmip.Type);
}
ManagementBaseO bject outParams;
if (inParams == null)
{
outParams = processClass.In vokeMethod(Meth odName, null, null);
}
else
{
outParams = processClass.In vokeMethod(Meth odName, Params, null);
}
return outParams;
}
catch (Exception e)
{
throw e;
}
}
I always get a error saying "The Methods Parameter are invalid".
Thats how i call this:
WMIParameter[] wmip = new WMIParameter[2];
wmip[0] = new WMIParameter("R eserved", typeof(Int32), 0);
wmip[1] = new WMIParameter("F lags", typeof(Int32), (Int32)ew);
ExecuteWMIMetho dOnRemoteMachin e_ThrowsExcepti on(TargetMachin eName,
"Win32_Operatin gSystem",
"Win32Shutdown" ,
wmip,
TargetMachineUs erName,
TargetMachineUs erPassword);
I want to hold the call to the WMI methods as transparent as possible, so
hats why i wrote this function. Please can you show me, or if possible
correct this function,...
TIA,...
Regards
Kerem
--
-----------------------
Beste Grüsse / Best regards / Votre bien devoue
Kerem Gümrükcü
Latest Project: http://www.codeplex.com/restarts
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------
"This reply is provided as is, without warranty express or implied."
Comment