المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : WMI 'Invalid Method Parameter(s)' JoinDomainOrWorkGroup



C# Programming
12-12-2009, 03:00 PM
I am at a lost. I have verified what I am doing against the documentation on microsofts website:
http://msdn.microsoft.com/en-us/library/aa392154(VS.85).aspx[^ (http://msdn.microsoft.com/en-us/library/aa392154(VS.85).aspx)] and I just can't figure out why it would give me this error.


My Connection object is not shown as it is global within the class I have it in. I am connect to this machine that is not on the domain and get installed applications, all services, and computer information. The problem is it keeps throwing a "Invalid Method Parameter(s)" error.

In case your wondering.. I ran a foreach look on the inParams.Properties and verified that all the method parameters existed in the inParams (which it does).

Any help would be great!


public string Join(string dns, string domain, string username, string password)
{
try
{
ManagementScope scope = new ManagementScope(@"\\" + dns + @"\root\CIMV2", conn);
ManagementPath path = new ManagementPath("Win32_ComputerSystem");
ManagementClass mgmtClass = new ManagementClass(scope, path, null);
ManagementBaseObject inParams = mgmtClass.GetMethodParameters("JoinDomainOrWorkgroup");

inParams["Name"] = domain;
inParams["UserName"] = username;
inParams["Password"] = password;
inParams["AccountOU"] = null;
inParams["FJoinOptions"] = (UInt32)1;

ManagementBaseObject outParams = mgmtClass.InvokeMethod("JoinDomainOrWorkgroup", inParams, null);
string status = ReturnedValue.JoinDomainOrWorkgroup(Convert.ToInt32(outParams["ReturnValue"]));

return status;
}
catch (Exception ex)
{
EventLog.WriteEntry("ADEM Application", ex.Message, EventLogEntryType.Error);
return ex.Message;
}
}