timeshift
2006-02-09 15:30:53 UTC
--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
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