VB Code:
Private Declare Function NetJoinDomain _
Lib "NETAPI32.dll" (ByVal lpServer As String, _
ByVal lpDomain As String, ByVal lpAccountOU As String, _
ByVal lpAccount As String, ByVal lpPassword As String, _
ByVal fJoinOptions As Int32) As Int32
Public Sub ChangeDomain()
Dim d() As Char
Dim u() As Char
Dim p() As Char
' I replaced what the actual values are, since they were my username and password to the company domain
'InsertNulls is a function that I created to convert the strings to char arrays and insert null chars between each value
d = insertNulls("myDomain")
u = insertNulls("myUserName")
p = insertNulls("MyPassword")
err = NetJoinDomain("", d, "", u, p, JoinOptions.NETSETUP_DOMAIN_JOIN_IF_JOINED Or JoinOptions.NETSETUP_JOIN_DOMAIN)
End Sub