You can get the general idea of joining a domain from
here[
^]. It's just another WMI method call, like any other. But, of course, the user running this has to have Domain Admin permissions, or the domain account already has to be setup for the machine name.