Discussion:
Bug in ManagementClass.InvokeMethod
(too old to reply)
timeshift
2006-02-09 15:30:53 UTC
Permalink
--Consider the following two procedures with similar syntax, one works,
one doesn't.

# System.Management.ManagementException: Invalid method Parameter(s)

private void ChangeRDCStatus(int status)
{
ConnectionOptions options = new ConnectionOptions();
if (radioCustomcred.Checked)
{
options.Username = boxUsername.Text;
options.Password = boxPassword.Text;
}

ManagementScope scope = new ManagementScope("\\\\" +
boxHost.Text + "\\root\\cimv2", options);
ManagementPath path = new
ManagementPath("Win32_TerminalServiceSetting");


ManagementClass processClass = new ManagementClass(scope,
path, null);

object[] methodArgs = { status };

try
{
processClass.InvokeMethod("SetAllowTSConnections",
methodArgs);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}

# Works like a charm

private void CreateProcess()
{
ConnectionOptions options = new ConnectionOptions();
if (radioCustomcred.Checked)
{
options.Username = boxUsername.Text;
options.Password = boxPassword.Text;
}

ManagementScope scope = new ManagementScope("\\\\" +
boxHost.Text + "\\root\\cimv2", options);
ManagementPath path = new ManagementPath("Win32_Process");


ManagementClass processClass = new ManagementClass(scope,
path, null);

object[] methodArgs = {"calc.exe", null, null, 0};

try
{
processClass.InvokeMethod("Create", methodArgs);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}

SetAllowTSConnections:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/termserv/termserv/win32_terminalservicesetting_setallowtsconnections.asp

Create:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/create_method_in_class_win32_process.asp
Willy Denoyette [MVP]
2006-02-09 20:43:30 UTC
Permalink
You cant run "windows" applications on a remote server using WMI.

Willy.

"timeshift" <***@gmail.com> wrote in message news:***@g47g2000cwa.googlegroups.com...
| --Consider the following two procedures with similar syntax, one works,
| one doesn't.
|
| # System.Management.ManagementException: Invalid method Parameter(s)
|
| private void ChangeRDCStatus(int status)
| {
| ConnectionOptions options = new ConnectionOptions();
| if (radioCustomcred.Checked)
| {
| options.Username = boxUsername.Text;
| options.Password = boxPassword.Text;
| }
|
| ManagementScope scope = new ManagementScope("\\\\" +
| boxHost.Text + "\\root\\cimv2", options);
| ManagementPath path = new
| ManagementPath("Win32_TerminalServiceSetting");
|
|
| ManagementClass processClass = new ManagementClass(scope,
| path, null);
|
| object[] methodArgs = { status };
|
| try
| {
| processClass.InvokeMethod("SetAllowTSConnections",
| methodArgs);
| }
| catch (Exception ex)
| {
| Console.WriteLine(ex.ToString());
| }
| }
|
| # Works like a charm
|
| private void CreateProcess()
| {
| ConnectionOptions options = new ConnectionOptions();
| if (radioCustomcred.Checked)
| {
| options.Username = boxUsername.Text;
| options.Password = boxPassword.Text;
| }
|
| ManagementScope scope = new ManagementScope("\\\\" +
| boxHost.Text + "\\root\\cimv2", options);
| ManagementPath path = new ManagementPath("Win32_Process");
|
|
| ManagementClass processClass = new ManagementClass(scope,
| path, null);
|
| object[] methodArgs = {"calc.exe", null, null, 0};
|
| try
| {
| processClass.InvokeMethod("Create", methodArgs);
| }
| catch (Exception ex)
| {
| Console.WriteLine(ex.ToString());
| }
| }
|
| SetAllowTSConnections:
|
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/termserv/termserv/win32_terminalservicesetting_setallowtsconnections.asp
|
| Create:
|
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/create_method_in_class_win32_process.asp
|
timeshift
2006-02-10 09:41:40 UTC
Permalink
Sorry, I wasn't being clear enough. The problem isn't with the
'calc.exe', that opens fine on locally, was just used to illustrate the
similarity in the procedure. The point is that the
processClass.InvokeMethod("SetAllowTSConnections", methodArgs); gives
me an exception, which it shouldn't.
timeshift
2006-02-10 09:47:19 UTC
Permalink
"You cant run "windows" applications on a remote server using WMI. "
<--
that is not true though, if you specify admin username/pass for the
remote machine you can run applications using WMI.
Willy Denoyette [MVP]
2006-02-10 10:02:34 UTC
Permalink
"timeshift" <***@gmail.com> wrote in message news:***@o13g2000cwo.googlegroups.com...
| "You cant run "windows" applications on a remote server using WMI. "
| <--
| that is not true though, if you specify admin username/pass for the
| remote machine you can run applications using WMI.
|

"Windows" applications, these are applications that have a UI canot be
started on a remote server.

Willy.
Willy Denoyette [MVP]
2006-02-10 10:03:44 UTC
Permalink
"timeshift" <***@gmail.com> wrote in message news:***@g44g2000cwa.googlegroups.com...
| Sorry, I wasn't being clear enough. The problem isn't with the
| 'calc.exe', that opens fine on locally, was just used to illustrate the
| similarity in the procedure. The point is that the
| processClass.InvokeMethod("SetAllowTSConnections", methodArgs); gives
| me an exception, which it shouldn't.
|

And the exception is?????


Willy.
timeshift
2006-02-10 10:20:32 UTC
Permalink
It was written on the top of the first post, but here it is:

System.Management.ManagementException: Invalid method Parameter(s)
Willy Denoyette [MVP]
2006-02-10 12:50:57 UTC
Permalink
"timeshift" <***@gmail.com> wrote in message news:***@g47g2000cwa.googlegroups.com...
| It was written on the top of the first post, but here it is:
|
| System.Management.ManagementException: Invalid method Parameter(s)
|

Try with boolean status instead of an int.

Willy.
timeshift
2006-02-10 13:28:52 UTC
Permalink
No luck :(

Im beginning to think that I have to somehow call the method on an
instance of the Win32_TerminalServiceSetting and not on the class
directly, but I have no idea on how to accomplish it, any ideas?

I've reported this as a bug on msdn.

Thanks for helping, I really appreciate it.
timeshift
2006-02-10 13:29:29 UTC
Permalink
No luck :(

Im beginning to think that I have to somehow call the method on an
instance of the Win32_TerminalServiceSetting and not on the class
directly, but I have no idea on how to accomplish it, any ideas?

I've reported this as a bug on msdn.

Thanks for helping, I really appreciate it.
Willy Denoyette [MVP]
2006-02-10 21:34:49 UTC
Permalink
Yes, you need an instance, this should work...

SelectQuery q= new SelectQuery("select * from
Win32_TerminalServiceSetting");
using(ManagementObjectSearcher searcher = new ManagementObjectSearcher(q))
{
ManagementObjectCollection TS = searcher.Get();
foreach(ManagementObject o in TS)
{
ManagementBaseObject inputArgs =
o.GetMethodParameters("SetAllowTSConnections");
inputArgs["AllowTSConnections"] = 0;
ManagementBaseObject outParams =
o.InvokeMethod("SetAllowTSConnections", inputArgs, null);
uint ret = (uint)(outParams.Properties["ReturnValue"].Value);
if(ret != 0)
Console.WriteLine("Failed {0}", ret);
}

Willy.

"timeshift" <***@gmail.com> wrote in message news:***@g14g2000cwa.googlegroups.com...
| No luck :(
|
| Im beginning to think that I have to somehow call the method on an
| instance of the Win32_TerminalServiceSetting and not on the class
| directly, but I have no idea on how to accomplish it, any ideas?
|
| I've reported this as a bug on msdn.
|
| Thanks for helping, I really appreciate it.
|
N.Srividya
2009-02-23 04:41:06 UTC
Permalink
Following code is giving me a invalid method parameters error - -2146233087

string _DOMAIN = "development";
string _USERNAME = "letest";
string _PASSWORD = "letest";

string _MSIPATH = @"C:\sourcepath\A.msi"; //error 1603
string _ARGS = "REINSTALLMODE=\"omus\" REINSTALL=\"ALL\"";
string _MACHINE = "dev-chen-pc2292";
bool allUsers = true ;
TimeSpan connectionTimeout;
connectionTimeout = new TimeSpan(0,10,0);
object[] parameters = null;

//connect local computer
ConnectionOptions connection = new ConnectionOptions();
connection.Impersonation = ImpersonationLevel.Impersonate;
connection.Authentication = AuthenticationLevel.PacketPrivacy;
connection.EnablePrivileges = true;
ManagementScope mMgmtScope;
mMgmtScope = new ManagementScope(@"\\" + "." + @"\root\CIMV2", connection);
string errormsg = "";
try
{
mMgmtScope.Connect();
parameters = new object[] { _MSIPATH, _ARGS, false };
ManagementClass productClass = new ManagementClass(mMgmtScope,
new ManagementPath("Win32_Product"), new ObjectGetOptions());


ManagementBaseObject inParams = productClass.GetMethodParameters("Upgrade");
inParams["PackageLocation"] = _MSIPATH;
inParams["Options"] = _ARGS;

object result = productClass.InvokeMethod("Upgrade", inParams,null);
MessageBox.Show(result.ToString());
}
catch (COMException comException)
{
mMgmtScope = null;
}
catch (UnauthorizedAccessException authException)
{
mMgmtScope = null;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);


From http://www.google.co.in/search?hl=en&q=-2146233087++-+Invalid+method+Parameter(s)+in+WMI+invokemethod&meta

Posted via DevelopmentNow.com Group
http://www.developmentnow.com/g/
N.Srividya
2009-02-23 04:41:11 UTC
Permalink
Following code is giving me a invalid method parameters error - -2146233087

string _DOMAIN = "development";
string _USERNAME = "letest";
string _PASSWORD = "letest";

string _MSIPATH = @"C:\sourcepath\A.msi"; //error 1603
string _ARGS = "REINSTALLMODE=\"omus\" REINSTALL=\"ALL\"";
string _MACHINE = "dev-chen-pc2292";
bool allUsers = true ;
TimeSpan connectionTimeout;
connectionTimeout = new TimeSpan(0,10,0);
object[] parameters = null;

//connect local computer
ConnectionOptions connection = new ConnectionOptions();
connection.Impersonation = ImpersonationLevel.Impersonate;
connection.Authentication = AuthenticationLevel.PacketPrivacy;
connection.EnablePrivileges = true;
ManagementScope mMgmtScope;
mMgmtScope = new ManagementScope(@"\\" + "." + @"\root\CIMV2", connection);
string errormsg = "";
try
{
mMgmtScope.Connect();
parameters = new object[] { _MSIPATH, _ARGS, false };
ManagementClass productClass = new ManagementClass(mMgmtScope,
new ManagementPath("Win32_Product"), new ObjectGetOptions());


ManagementBaseObject inParams = productClass.GetMethodParameters("Upgrade");
inParams["PackageLocation"] = _MSIPATH;
inParams["Options"] = _ARGS;

object result = productClass.InvokeMethod("Upgrade", inParams,null);
MessageBox.Show(result.ToString());
}
catch (COMException comException)
{
mMgmtScope = null;
}
catch (UnauthorizedAccessException authException)
{
mMgmtScope = null;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);


From http://www.google.co.in/search?hl=en&q=-2146233087++-+Invalid+method+Parameter(s)+in+WMI+invokemethod&meta

Posted via DevelopmentNow.com Group
http://www.developmentnow.com/g/
N.Srividya
2009-02-23 04:41:20 UTC
Permalink
Following code is giving me a invalid method parameters error - -2146233087

string _DOMAIN = "development";
string _USERNAME = "letest";
string _PASSWORD = "letest";

string _MSIPATH = @"C:\sourcepath\A.msi"; //error 1603
string _ARGS = "REINSTALLMODE=\"omus\" REINSTALL=\"ALL\"";
string _MACHINE = "dev-chen-pc2292";
bool allUsers = true ;
TimeSpan connectionTimeout;
connectionTimeout = new TimeSpan(0,10,0);
object[] parameters = null;

//connect local computer
ConnectionOptions connection = new ConnectionOptions();
connection.Impersonation = ImpersonationLevel.Impersonate;
connection.Authentication = AuthenticationLevel.PacketPrivacy;
connection.EnablePrivileges = true;
ManagementScope mMgmtScope;
mMgmtScope = new ManagementScope(@"\\" + "." + @"\root\CIMV2", connection);
string errormsg = "";
try
{
mMgmtScope.Connect();
parameters = new object[] { _MSIPATH, _ARGS, false };
ManagementClass productClass = new ManagementClass(mMgmtScope,
new ManagementPath("Win32_Product"), new ObjectGetOptions());


ManagementBaseObject inParams = productClass.GetMethodParameters("Upgrade");
inParams["PackageLocation"] = _MSIPATH;
inParams["Options"] = _ARGS;

object result = productClass.InvokeMethod("Upgrade", inParams,null);
MessageBox.Show(result.ToString());
}
catch (COMException comException)
{
mMgmtScope = null;
}
catch (UnauthorizedAccessException authException)
{
mMgmtScope = null;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);


From http://www.google.co.in/search?hl=en&q=-2146233087++-+Invalid+method+Parameter(s)+in+WMI+invokemethod&meta

Posted via DevelopmentNow.com Group
http://www.developmentnow.com/g/
SrividyaN
2009-02-23 04:53:42 UTC
Permalink
Following code is giving me a invalid method parameters error - -2146233087

string _DOMAIN = "development";
string _USERNAME = "letest";
string _PASSWORD = "letest";

string _MSIPATH = @"C:\sourcepath\A.msp"; //error 1603
string _ARGS = "REINSTALLMODE=\"omus\" REINSTALL=\"ALL\"";
string _MACHINE = "dev-chen-pc2292";
bool allUsers = true ;
TimeSpan connectionTimeout;
connectionTimeout = new TimeSpan(0,10,0);
object[] parameters = null;

//connect local computer
ConnectionOptions connection = new ConnectionOptions();
connection.Impersonation = ImpersonationLevel.Impersonate;
connection.Authentication = AuthenticationLevel.PacketPrivacy;
connection.EnablePrivileges = true;
ManagementScope mMgmtScope;
mMgmtScope = new ManagementScope(@"\\" + "." + @"\root\CIMV2", connection);
string errormsg = "";
try
{
mMgmtScope.Connect();
parameters = new object[] { _MSIPATH, _ARGS, false };
ManagementClass productClass = new ManagementClass(mMgmtScope,
new ManagementPath("Win32_Product"), new ObjectGetOptions());


ManagementBaseObject inParams = productClass.GetMethodParameters("Upgrade");
inParams["PackageLocation"] = _MSIPATH;
inParams["Options"] = _ARGS;

object result = productClass.InvokeMethod("Upgrade", inParams,null);
MessageBox.Show(result.ToString());
}
catch (COMException comException)
{
mMgmtScope = null;
}
catch (UnauthorizedAccessException authException)
{
mMgmtScope = null;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);


From http://www.developmentnow.com/groups/viewthread.aspx?newsgroupid=33&threadid=69425

Posted via DevelopmentNow.com Group
http://www.developmentnow.com/g/

Loading...