The UnjoinDomainOrWorkgroup method un-joins or removes a computer system from a domain or workgroup. This method is only ...

The UnjoinDomainOrWorkgroup method un-joins or removes a computer system from 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.
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.