The JoinDomainOrWorkgroup method joins computer systems to a domain or workgroup. This method is only available on Windows ...

The JoinDomainOrWorkgroup method joins computer systems to a domain or workgroup.  This method is only available on Windows 2000 platforms and beyond. The method can return the following values:
0 - Success.
Other - For integer values other than those listed above, refer to Win32 error code documentation.
Note: If moving a computer from a Domain to a WorkGroup, the computer must first be removed from the domain before running this method to join the Workgroup. 
Password and Username must use a high authentication level (i.e. no less than RPC_C_AUTHN_LEVEL_PKT_PRIVACY) when they connect to winmgmt (i.e. in the call to obtain the IWbemServices interface) or SetProxyBlanket on their IWbemServices ptr. If they are local to winmgmt then this is not a concern because their authentication level is as good as RPC_C_AUTHN_LEVEL_PKT_PRIVACY as well as their client request never goes over the wire to get to the winmgmt. 
If Password and Username are left null, the provider does not care. 
If the provider determines that the authentication level is too low and a Password or Username has been specified then WBEM_E_ENCRYPTED_CONNECTION_REQUIRED will be returned.