Function TranslateName ($InitType, $BindName, $LookupNameType, $LookupName, $ReturnNameType)
Dim $InitType, $BindName, $LookupNameType, $LookupName, $ReturnNameType
Dim $NameTranslate, $ReturnName, $Error, $ErrorText
$Error = 0
$ErrorText = ""
$ReturnName = ""
$NameTranslate = CreateObject ("NameTranslate")
$Error = @error
$ErrorText = @serror
If $Error = 0
$NameTranslate.Init ($InitType, $BindName)
$Error = @error
$ErrorText = @serror
If $Error = 0
$NameTranslate.Set ($LookupNameType, $LookupName)
$Error = @error
$ErrorText = @serror
If $Error = 0
$ReturnName = $NameTranslate.Get($ReturnNameType)
$Error = @error
$ErrorText = @serror
EndIf
EndIf
EndIf
$TranslateName = $ReturnName, $Error, $ErrorText
EndFunction
Function AddComputerToGroup($ComputerName, $GroupName)
$objGroup = GetObject("WinNT://" + @Domain + "/" + $GroupName + ",group")
If @error
$AddComputerToGroup = 1
Return
EndIf
If $ObjGroup.IsMember("WinNT://" + @Domain + "/" + $ComputerName + "$$")
$AddComputerToGroup = 1
Return
EndIf
$GroupDN = TranslateName(3, "", 3, "@Domain\" + $GroupName, 1)
If $GroupDN[1] = 0 ; ErrorCode
$ComputerDN = TranslateName(3, "", 3, "@Domain\" + $ComputerName + "$", 1)
If $ComputerDN[1] = 0
$Cmd = 'cmd /c dsmod group "' + $GroupDN[0] + '" -addmbr "' + $ComputerDN[0] + '" >nul'
Shell $Cmd
$AddComputerToGroup = @ERROR
Else
$AddComputerToGroup = $ComputerDN[1]
EndIf
Else
$AddComputerToGroup = $GroupDN[1]
EndIf
EndFunction
$Ret = AddComputerToGroup("ComputerName", "GroupName")