Jump to content
Sign in to follow this  
nitron

Ldap

Recommended Posts

nitron

Grande Problem!!!

And I don't get it!!!!

Can anyone tell me what is happening here?

When using this code, Stuff is written to the AD

$objTrans = ObjCreate("NameTranslate")
    $objTrans.Init ($ADS_NAME_INITTYPE_GC, "")
    $objTrans.Set ($ADS_NAME_TYPE_1779, @LogonDomain)
    $objTrans.Set ($ADS_NAME_TYPE_NT4, @LogonDomain & "\" & $username)
    $strUserDN = $objTrans.Get ($ADS_NAME_TYPE_1779)
    $UserObj = ObjGet("LDAP://" & $strUserDN)

    FileWrite($Inhalt1,$UserObj.LastName&";")
    FileWrite($Inhalt1,$UserObj.FirstName&";")
    FileWrite($Inhalt1,$UserObj.Initials&";")
    FileWrite($Inhalt1,$UserObj.TelephoneNumber&";")
    FileWrite($Inhalt1,$UserObj.FaxNumber&";")
    FileWrite($Inhalt1,$UserObj.EmailAddress&";")
    FileWrite($Inhalt1,$UserObj.Department&";")
    FileWrite($Inhalt1,$UserObj.physicalDeliveryOfficeName&";")
    FileWrite($Inhalt1,$UserObj.streetAddress &";")
    FileWrite($Inhalt1,$UserObj.postalCode&";")
    FileWrite($Inhalt1,$UserObj.l &";")
    FileWrite($Inhalt1,$UserObj.st &";")
    FileWrite($Inhalt1,$UserObj.countryCode &";")
    FileWrite($Inhalt1,$UserObj.mobile&";")
    FileWrite($Inhalt1,$UserObj.Manager &";")
    FileWrite($Inhalt1,$UserObj.Title &";")
    FileWriteLine($Inhalt1,$username&";")


    if $UserObj.FirstName<>"" Then
    if $UserObj.LastName<>"" Then
    if $UserObj.userAccountControl<>66050 Then

    If $X=$UserObj.LastName Then    
        $UserObj.put("Title","IT")
        $UserObj.setinfo
    EndIf

If I use this code!!! Nothing happens!!! Why??? Im going nuts over this!!

$objTrans = ObjCreate("NameTranslate")
    $objTrans.Init ($ADS_NAME_INITTYPE_GC, "")
    $objTrans.Set ($ADS_NAME_TYPE_1779, @LogonDomain)
    $objTrans.Set ($ADS_NAME_TYPE_NT4, @LogonDomain & "\" & $username)
    $strUserDN = $objTrans.Get ($ADS_NAME_TYPE_1779)
    $UserObj = ObjGet("LDAP://" & $strUserDN)
    if $UserObj.FirstName<>"" Then
    if $UserObj.LastName<>"" Then
    if $UserObj.userAccountControl<>66050 Then
        
    $Split=StringSplit($Us,";")
    If $Split[0]<13 Then MsgBox(4096,$Split[14],$UserObj.Title)
    if  $username=$Split[13] Then
        MsgBox(4096,$Split[14],$UserObj.Title)
        $UserObj.put("LastName",$Split[1])
        $UserObj.setinfo
        $UserObj.put("FirstName",$Split[2])
        $UserObj.setinfo
        $UserObj.put("Initials",$Split[3])
        $UserObj.setinfo
        $UserObj.put("TelephoneNumber",$Split[4])
        $UserObj.setinfo
        $UserObj.put("FaxNumber",$Split[5])
        $UserObj.setinfo
        $UserObj.put("Department",$Split[6])
        $UserObj.setinfo
        $UserObj.put("physicalDeliveryOfficeName",$Split[]))
        $UserObj.setinfo
        $UserObj.put("streetAddress",$Split[7])
        $UserObj.setinfo
        $UserObj.put("postalCode",$Split[8])
        $UserObj.setinfo
        $UserObj.put("l",$Split[9])
        $UserObj.setinfo
        $UserObj.put("st",$Split[10])
        $UserObj.setinfo
        $UserObj.put("mobile",$Split[11])
        $UserObj.setinfo
        $UserObj.put("Manager",$Split[]15))
        $UserObj.setinfo
        $UserObj.put("Title",$Split[12])
        $UserObj.setinfo
        $Exit=100
    EndIf

The Problem is not that the String used is empty or something, when watching the Result by Displaying ist via Msgbox, everthing seems to be right, except the AD is not changed

The only diffrence I see is, that im doing only one change per Repate... but that should be no prob or is ist?

Help Please!!!

Edited by nitron

Share this post


Link to post
Share on other sites
ptrex

@nitron

Maybe you should add this to the top of the script

Const $ADS_NAME_INITTYPE_GC = 3
;Const $ADS_NAME_TYPE_NT4 = 3
;Const $ADS_NAME_TYPE_GUID = 7
Const $ADS_NAME_TYPE_1779 = 1
Const $ADS_NAME_TYPE_CANONICAL = 2
Const $ADS_NAME_TYPE_NT4 = 3
Const $ADS_NAME_TYPE_DISPLAY = 4
Const $ADS_NAME_TYPE_DOMAIN_SIMPLE = 5
Const $ADS_NAME_TYPE_ENTERPRISE_SIMPLE = 6
Const $ADS_NAME_TYPE_GUID = 7
Const $ADS_NAME_TYPE_UNKNOWN = 8
Const $ADS_NAME_TYPE_USER_PRINCIPAL_NAME = 9
Const $ADS_NAME_TYPE_CANONICAL_EX = 10
Const $ADS_NAME_TYPE_SERVICE_PRINCIPAL_NAME = 11
Const $ADS_NAME_TYPE_SID_OR_SID_HISTORY_NAME = 12

Enjoy !!

Regards

Share this post


Link to post
Share on other sites
nitron

THX but i allready added that, i didnot Post that maybe i should have... Here is the entire Script...

it read information from a file...

;VerteilungsProgram
;***************************************************************************************************

****************
;*********************************************** include ***********************************************************
;***************************************************************************************************

****************
#include <GuiConstants.au3>
#include <GuiList.au3>
#include <GuiListView.au3>
#include <GuiCombo.au3>
#include <GuiTab.au3>
#include <Process.au3>
#include <Date.au3>
#include <Misc.au3>
;***************************************************************************************************

****************
;********************************************** Variablen **********************************************************
;***************************************************************************************************

****************
;-------------------------------------------------------------------------------------------------------------------
;************************************ Global nicht veränderbare Variablen ******************************************
;-------------------------------------------------------------------------------------------------------------------

Global Const $Server="\\Path"
Global $Users,$Exit=10

Dim $Fenster
Dim $PictureHandle
Dim $FileHandle


Global $objRootDSE = ObjGet("LDAP://RootDSE")
Global $strDNSDomain = $objRootDSE.Get ("defaultNamingContext") ; Retrieve the current AD domain name
Global $strHostServer = $objRootDSE.Get ("dnsHostName"); Retrieve the name of the connected DC
Global $strConfiguration = $objRootDSE.Get ("ConfigurationNamingContext"); Retrieve the Configuration naming context
Global $UserId = ""
Global $UserDomain = "dc=Dom,dc=Dom"
Global $UserName = ""
Global $UserLongName = ""
Global $UserDN = ""
Const $ADS_NAME_INITTYPE_GC = 3
Const $ADS_NAME_TYPE_1779 = 1
Const $ADS_NAME_TYPE_CANONICAL = 2
Const $ADS_NAME_TYPE_NT4 = 3
Const $ADS_NAME_TYPE_DISPLAY = 4
Const $ADS_NAME_TYPE_DOMAIN_SIMPLE = 5
Const $ADS_NAME_TYPE_ENTERPRISE_SIMPLE = 6
Const $ADS_NAME_TYPE_GUID = 7
Const $ADS_NAME_TYPE_UNKNOWN = 8
Const $ADS_NAME_TYPE_USER_PRINCIPAL_NAME = 9
Const $ADS_NAME_TYPE_CANONICAL_EX = 10
Const $ADS_NAME_TYPE_SERVICE_PRINCIPAL_NAME = 11
Const $ADS_NAME_TYPE_SID_OR_SID_HISTORY_NAME = 12

DIm $oMyError, $objTrans, $objRootDSE, $strUserDN, $UserObj, $HexNumber, $username, $ComputerNa,$Btn_Unlock,$locked, $locked2,$locked3, $locked4
Dim $Nr=1
Dim $UserStr=""
$Inhalt1=FileOpen("\\Path\UserInfos.Set",0)
$Zaehler=1
while 1
        $Users=FileReadLine($Inhalt1)
        If @error = -1 Then ExitLoop
        _EnumUsers("YourDomain","")
        $Zaehler=$Zaehler+1
WEnd
FileClose($Inhalt1)


Func UserFirst($username)

    Dim $noRemoes,$getter,$X=""

    $oMyError = ObjEvent("AutoIt.Error", "ComError")

    $objTrans = ObjCreate("NameTranslate")
    $objTrans.Init ($ADS_NAME_INITTYPE_GC, "")
    $objTrans.Set ($ADS_NAME_TYPE_1779, @LogonDomain)
    $objTrans.Set ($ADS_NAME_TYPE_NT4, @LogonDomain & "\" & $username)
    $strUserDN = $objTrans.Get ($ADS_NAME_TYPE_1779)
    $UserObj = ObjGet("LDAP://" & $strUserDN)
    if $UserObj.FirstName<>"" Then
    if $UserObj.LastName<>"" Then
    if $UserObj.userAccountControl<>66050 Then
        
    $Split=StringSplit($Users,";")
    if  $username=$Split[13] Then
        $UserObj.put("LastName",$Split[1])
        $UserObj.setinfo
        $UserObj.put("FirstName",$Split[2])
        $UserObj.setinfo
        $UserObj.put("Initials",$Split[3])
        $UserObj.setinfo
;       $UserObj.put("TelephoneNumber",$Split[4])
;       $UserObj.setinfo
;       $UserObj.put("FaxNumber",$Split[5])
;       $UserObj.setinfo
        $UserObj.put("Department",$Split[6])
        $UserObj.setinfo
;   $UserObj.put("physicalDeliveryOfficeName",$Split[]))
;       $UserObj.setinfo
        $UserObj.put("streetAddress",$Split[7])
        $UserObj.setinfo
;       $UserObj.put("postalCode",$Split[8])
;       $UserObj.setinfo
;       $UserObj.put("l",$Split[9])
;       $UserObj.setinfo
;       $UserObj.put("st",$Split[10])
;       $UserObj.setinfo
;       $UserObj.put("mobile",$Split[11])
;       $UserObj.setinfo
;       $UserObj.put("Manager",$Split[]15))
        $UserObj.setinfo
        $UserObj.put("Title",$Split[12])
        $UserObj.setinfo
        $Exit=100
    EndIf
    EndIf   
    EndIf
    EndIf
    $oMyError = ObjEvent("AutoIt.Error", "")
;COM Error function

EndFunc

Func _EnumUsers($IDomain, $l_UserId)
  ; 
    $Found_Users = ""
    $Counter = 0
    Local $objCommand = ObjCreate("ADODB.Command")
    Local $objConnection = ObjCreate("ADODB.Connection")
    $objConnection.Provider = "ADsDSOObject"
    $objConnection.Open ("Active Directory Provider")
    $objCommand.ActiveConnection = $objConnection
    Local $strBase = "<GC://" & $UserDomain & ">"
    Local $strFilter = "(&(objectCategory=person)(objectClass=user)(sAMAccountName=" & $l_UserId & "*))"
    Local $strAttributes = "cn,sAMAccountName,displayName,sn,distinguishedName"
    Local $strQuery = $strBase & ";" & $strFilter & ";" & $strAttributes & ";subtree"
    $objCommand.CommandText = $strQuery
    $objCommand.Properties ("Page Size") = 100
    $objCommand.Properties ("Timeout") = 10
    $objCommand.Properties ("Cache Results") = False
    $ADS_SCOPE_SUBTREE = 2
    $objCommand.Properties ("searchscope") = $ADS_SCOPE_SUBTREE
    Local $objRecordSet = $objCommand.Execute
    While Not $objRecordSet.EOF
        $strName = $objRecordSet.Fields ("sAMAccountName").Value
        $strCN = $objRecordSet.Fields ("cn").value
        $strdisplayName = $objRecordSet.Fields ("displayName").value
        $strSN = $objRecordSet.Fields ("SN").value
        $strdistinguishedName = $objRecordSet.Fields ("distinguishedName").value
        $Counter = $Counter + 1
        UserFirst($strName)
    ;$Users[$Nr]=$strName
        $Nr=$Nr+1
        $objRecordSet.MoveNext
        If $Exit=100 then ExitLoop
    WEnd
    $objConnection.Close
; Check if any match is found
    If $Counter = 0 Then
        Return ""
    EndIf
    $MouseDown = 0
  ; If only 1 found than assume it the one wanted
    If $Counter = 1 Then
        $UserId = $strName
        $UserName = $strdisplayName
        $UserDN = $strdistinguishedName
        Return $strName
    EndIf
  ;
EndFunc ;==>_EnumUsers

Func ComError()
    If IsObj($oMyError) Then
        $HexNumber = Hex($oMyError.number, 8)
        SetError($HexNumber)
    Else
        SetError(1)
    EndIf
    Return 0
EndFunc;==>ComError

Share this post


Link to post
Share on other sites
ptrex
nitron

just to answer and close this!

I tried an found the reason even so i don't realy understand it.

Fact seems, that some Variable need to be set by .put an others need to be set by actually setting the Variable its self.

Looks like :

$UserObj.put("Department",GUICtrlRead($Data8))

$UserObj.LastName=GUICtrlRead($Data2)

$UserObj.setinfo

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.