Maybe somebody is interrested in this:
Code: Select all
Prototype.l NetJoinDomain(Server.p-unicode, Domain.p-unicode, AccountOU.p-unicode, Account.p-unicode, Password.p-unicode, JoinOptions)
Prototype.l NetUnjoinDomain(Server.p-unicode, Account.p-unicode, Password.p-unicode, UnjoinOptions)
Prototype.l NetJoinWorkgroup(Server.p-unicode, Domain.p-unicode, AccountOU.p-unicode, Account.p-unicode, Password.p-unicode, JoinOptions)
Prototype.l NetGetJoinInformation(Host.p-unicode, bufptr, dwBufferType)
;===========================
Procedure.s _GetSystemMessage(ErrorCode.l)
Buffer.STRING\s = Space(255)
tchar.l = FormatMessage_(#FORMAT_MESSAGE_FROM_SYSTEM, #Null, ErrorCode, 0, @Buffer\s, 255, #Null)
If tchar > 0
Buffer\s = Trim(Left(Buffer\s, tchar))
Else
Buffer\s = ""
EndIf
ProcedureReturn Buffer\s
EndProcedure
;==========================
Procedure.s NET_JoinDomain(Hostname$, Domain$, AccountOU$, Account$, Password$, JoinOptions.l)
Hostname$ = "\\" + RemoveString(Hostname$, "\")
Result$ = "Error - Library could not be opened"
LibNr.l = OpenLibrary(#PB_Any, "NetApi32.dll")
If LibNr
JoinDomain.NetJoinDomain = GetFunction(LibNr, "NetJoinDomain")
If JoinDomain <> 0
ErrorCode.l = JoinDomain(Hostname$, Domain$, AccountOU$, Account$, Password$, JoinOptions)
If ErrorCode = 0
Result$ = UCase(Hostname$) + " has joined the domain " + UCase(Domain$)
Else
Result$ = "Error - (" + Str(ErrorCode) + ") " + _GetSystemMessage(ErrorCode)
EndIf
EndIf
CloseLibrary(LibNr)
EndIf
ProcedureReturn Result$
EndProcedure
;Debug NET_JoinDomain("Computername", "domain.com", "OU=XXXXX,DC=domain,DC=com", "Admin@domain.com", "AdminPassword", $21)
;==========================
Procedure.s NET_UnjoinDomain(Hostname$, Account$, Password$, UnjoinOptions.l)
Hostname$ = "\\" + RemoveString(Hostname$, "\")
Result$ = "Error - Library could not be opened"
LibNr.l = OpenLibrary(#PB_Any, "NetApi32.dll")
If LibNr
UnjoinDomain.NetUnjoinDomain = GetFunction(LibNr, "NetUnjoinDomain")
If UnjoinDomain <> 0
ErrorCode.l = UnjoinDomain(Hostname$, Account$, Password$, UnjoinOptions)
If ErrorCode = 0
Result$ = "Unjoined"
Else
Result$ = "Error - (" + Str(ErrorCode) + ") " + _GetSystemMessage(ErrorCode)
EndIf
EndIf
CloseLibrary(LibNr)
EndIf
ProcedureReturn Result$
EndProcedure
;NET_UnjoinDomain("Computername", "Admin@domain.com", "AdminPassword", 0)
;==========================
Procedure.s NET_JoinWorkgroup(Hostname$, Domain$, AccountOU$, Account$, Password$, JoinOptions.l)
Hostname$ = "\\" + RemoveString(Hostname$, "\")
Result$ = "Error - Library could not be opened"
LibNr.l = OpenLibrary(#PB_Any, "NetApi32.dll")
If LibNr
JoinWorkgroup.NetJoinWorkgroup = GetFunction(LibNr, "NetJoinDomain")
If JoinWorkgroup <> 0
ErrorCode.l = JoinWorkgroup(Hostname$, Domain$, AccountOU$, Account$, Password$, JoinOptions)
If ErrorCode = 0
Result$ = UCase(Hostname$) + " has joined the group " + UCase(Domain$)
Else
Result$ = "Error - (" + Str(ErrorCode) + ") " + _GetSystemMessage(ErrorCode)
EndIf
EndIf
CloseLibrary(LibNr)
EndIf
ProcedureReturn Result$
EndProcedure
;(Computer must not be in a domain. Check with GetJoinInfo and if necessary unjoin from domain first)
;NET_JoinWorkgroup("Computername", "WORKGROUP", "", "LocalAdmin", "LocalAdminPassword", $20)
;==========================
Procedure.s NET_GetJoinInformation(Hostname$)
Hostname$ = "\\" + RemoveString(Hostname$, "\")
Result$ = "Status is unknown"
LibNr.l = OpenLibrary(#PB_Any, "NetApi32.dll")
If LibNr
dwBufferType.l
JoinInfo.NetGetJoinInformation = GetFunction(LibNr, "NetGetJoinInformation")
If JoinInfo <> 0
ErrorCode.l = JoinInfo(Hostname$, @*bufptr, @dwBufferType)
If ErrorCode = 0
Select dwBufferType
Case 1: Result$ = "Not joined to any domain or group"
Case 2: Result$ = "Joined to the group: " + PeekS(*bufptr, -1, #PB_Unicode)
Case 3: Result$ = "Joined to the domain: " + PeekS(*bufptr, -1, #PB_Unicode)
EndSelect
Else
Result$ = "Error - (" + Str(ErrorCode) + ") " + _GetSystemMessage(ErrorCode)
EndIf
EndIf
NetApiBufferFree_(*bufptr)
CloseLibrary(LibNr)
EndIf
ProcedureReturn Result$
EndProcedure