Jump to content

erease attribute contents from AD


Recommended Posts

Hi guys.

I needs to erese the contents of an attribute of an object from Active Directory.

I have one script to fill this attribute, and desire to use this same script to empty this attribute.

But if I inform an empty value the script dont change the attribute contents.

above the code...(still testing... some trash may be foud)

#include <file.au3>
#include <GUIConstants.au3>
#include <GUIListView.au3>
Dim $msg,$APPLY,$NAME, $USER, $NUID, $USERNAME, $UID
While 1
   GUI()
   If $msg = $APPLY Then
      If $NAME="" or GUICtrlRead($USER)="" Then
         $NAME=""
         $NUID=""
         Else
         $SPLIT=StringSplit(GUICtrlRead($UID),"")
            $NUID2=String(GUICtrlRead($UID))
            $usr = ObjGet("LDAP://"&$TST)
            $usr.employeeID = String($NUID2)
            $usr.SetInfo
            $NAME=""
            $NUID=""
      EndIf
   Else
      $objConnection = ObjCreate("ADODB.Connection")
      $objConnection.Open ("Provider=ADsDSOObject;")
      $objCommand = ObjCreate("ADODB.Command")
      $objCommand.ActiveConnection = $objConnection
      $objCommand.CommandText = "<LDAP://dc=test,dc=net>;(&(objectCategory=User)(samAccountName="&GUICtrlRead($USER)&"));SAmAccountName,DisplayName,employeeID,distinguishedName;subtree"
      $objRecordSet = $objCommand.Execute
      if $objRecordSet.RecordCount = 0 then
        MsgBox(0,"UID","Not Found!")
        $NAOME=""
        $NUID=""
     else
        $TST=$objRecordSet.Fields("distinguishedName").Value
        $USERNAME=$objRecordSet.Fields("DisplayName").Value
        $NOME=$objRecordSet.Fields("DisplayName").Value
        $NCPF=$objRecordSet.Fields("employeeID").Value
      EndIf
      $objConnection.Close()
   EndIf
WEnd
Func GUI()
   GUICreate("EID",450,200,-1,-1,$WS_SIZEBOX+$WS_SYSMENU)
   GUICtrlCreateLabel("User", 10,35,40,20)
   GUICtrlCreateLabel("Name", 10,65,40,20)
   GUICtrlCreateLabel("EIDF", 10,95,40,20)
   $USER=GUICtrlCreateInput($USERNAME, 70,30,120,20)
   $NAME=GUICtrlCreateLabel ($NAME, 70,65,350,20)
   $EID=GUICtrlCreateInput ($NEID, 70,90,75,20)
   $CONSULT=GUICtrlCreateButton ("Consult",  10, 150, 60)
   $APPLY=GUICtrlCreateButton ("Apply",  80, 150, 60)
   $CANCEL=GUICtrlCreateButton ( "Cancel",  150, 150, 60)
   GUISetState ()
   While 1
       $msg = GUIGetMsg()
       If $msg = $GUI_EVENT_CLOSE Then Exit
       If $msg = $APPLY or $msg = $CONSULT Then ExitLoop
       If $msg = $CANCEL Then Exit
   Wend
EndFunc

Thanks for your help

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...