Why does this WMI Invoke not work?

Tech-Archive recommends: Fix windows errors by optimizing your registry



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(string 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 ManagementBaseObject ExecuteWMIMethodOnRemoteMachine_ThrowsException(string TargetMachine,
string ManagementPathString,
string MethodName,
WMIParameter[] inParams, string UserName, string Password)
{
try
{
ConnectionOptions connOptions = new ConnectionOptions();
connOptions.EnablePrivileges = true;
connOptions.Impersonation = ImpersonationLevel.Impersonate;
if (UserName != string.Empty && Password != string.Empty)
{
connOptions.Username = UserName;
connOptions.SecurePassword = CreateSecureString(Password);
}
ManagementScope manScope = new ManagementScope(String.Format(@"\\{0}\ROOT\CIMV2", TargetMachine), connOptions);
manScope.Connect();
ObjectGetOptions objectGetOptions = new ObjectGetOptions();
ManagementPath managementPath = new ManagementPath(ManagementPathString);
ManagementClass processClass = new ManagementClass(manScope, managementPath, objectGetOptions);
ManagementBaseObject Params = processClass.GetMethodParameters(MethodName);
foreach (WMIParameter wmip in inParams)
{
Params[wmip.Name] = Convert.ChangeType(wmip.Value,wmip.Type);
}
ManagementBaseObject outParams;
if (inParams == null)
{
outParams = processClass.InvokeMethod(MethodName, null, null);
}
else
{
outParams = processClass.InvokeMethod(MethodName, 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("Reserved", typeof(Int32), 0);
wmip[1] = new WMIParameter("Flags", typeof(Int32), (Int32)ew);

ExecuteWMIMethodOnRemoteMachine_ThrowsException(TargetMachineName,
"Win32_OperatingSystem",
"Win32Shutdown",
wmip,
TargetMachineUserName,
TargetMachineUserPassword);



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."

.



Relevant Pages

  • Re: common dialog w/api instead of COMDLG32.OCX, possible?
    ... As Long, ByVal lpHelpFile As String, ByVal wCommand As Long, ByVal dwData As ... Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias ... Public Property Get FileNameAs String ...
    (microsoft.public.vb.winapi)
  • Re: Incompatibility between Access 2003 and Access 2002
    ... Private WithEvents mlst As ListBox ... Private mot As ObjectType ... Public DisplayField As String ... Dim prm As DAO.Parameter ...
    (microsoft.public.access.modulesdaovba)
  • Re: GetOpenFilename With MultiSelect Intermittently Returns String
    ... ByVal lpWindowName As String) As Long ... Private Declare Function lstrlen Lib "kernel32" _ ... Private Const OFN_ALLOWMULTISELECT As Long = &H200 ...
    (microsoft.public.excel.programming)
  • Re: Getting Windows Display Name
    ... Private Type WKSTA_USER_INFO_1 ... usri3_script_path As Long 'Pointer to a Unicode string specifying the path for the user's logon script file. ... Dim bufptr As Long ... Public Property Get PasswordAgeAs Long ...
    (microsoft.public.access.modulesdaovba)
  • Re: FTP-Service throgh WinInet-API
    ... Dim sTmpPath As String: sTmpPath = AppPath) ... Private hInternet As Long ... Public Declare Function InternetCloseHandle _ ...
    (microsoft.public.vb.general.discussion)