0

I am trying to use C# to add a machine to an AD domain using WMI and I am having problems, the thing is if I comment out username and password parameters it works fine, but it adds the system to a workgroup instead of a domain, when I try to set the username and password it throws an "Attempted to access an unloaded AppDomain" exception. here's my code:

        ManagementClass networkTask = new ManagementClass(connectionScope,
                      new ManagementPath("Win32_ComputerSystem"), new ObjectGetOptions());
        ManagementObjectCollection moc = networkTask.GetInstances();
        foreach (ManagementObject mo in moc)
        {
            ManagementBaseObject newDomain = mo.GetMethodParameters("JoinDomainOrWorkgroup");
            newDomain["Name"] = domainName;    
            newDomain["Password"] = password;
            newDomain["UserName"] = username;
            newDomain["FJoinOptions"] = 3;
            ManagementBaseObject rename = mo.InvokeMethod("JoinDomainOrWorkgroup", newDomain, null);
            return 0;
        }

I am connecting to the system using local administrator credentials

4

0 に答える 0