Jump to content

Recommended Posts

Posted

B)

Hi.

I am trying to retrieve the Company properti of an User object from Active Directory.

I can do this using the VBS below:

strUserName="test"
dtStart = TimeValue(Now())
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"

Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection

objCommand.CommandText = "<LDAP://dc=test,dc=net>;(&(objectCategory=User)(samAccountName=" & strUserName & "));Company;subtree"

Set objRecordSet = objCommand.Execute

if objRecordSet.RecordCount = 0 then
  WScript.Echo "not found!"
else
  WScript.Echo objRecordSet("Company")
end if

objConnection.Close

I try to translate this VBS to AU3 using vaconvert.au3, but is not working...

the translation result was:

#include <date.au3>
#include <bk-logfile.au3>

$strUserName="test"
$dtStart = TimeValue(_Now()())
 $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=" & @UserName & "));Company, Department;subtree"

 $objRecordSet = $objCommand.Execute

if $objRecordSet.RecordCount = 0 then
  _WriteLog ("Não encontrado!")
else
  _WriteLog ($objRecordSet("Company") & ", " & $objRecordSet("Department"))
EndIf

$objConnection.Close()

Tks for any help.

Posted

I see two obvious syntax errors...

This line looks wrong:

$dtStart = TimeValue(_Now()())

and in this line:

$objCommand.CommandText = "<LDAP://dc=test,dc=net>;(&(objectCategory=User)(samAccountName=" & @UserName & "));Company, Department;subtree"

@UserName should be $strUserName right?

Dale

#include <date.au3>
#include <bk-logfile.au3>

$strUserName="test"
$dtStart = TimeValue(_Now()())
 $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=" & @UserName & "));Company, Department;subtree"

 $objRecordSet = $objCommand.Execute

if $objRecordSet.RecordCount = 0 then
  _WriteLog ("Não encontrado!")
else
  _WriteLog ($objRecordSet("Company") & ", " & $objRecordSet("Department"))
EndIf

$objConnection.Close()

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Posted

Any one knows where can i find docs or manuals with informations about functions like "_WriteLog"?

I just translate the VBS script using the vaconvert tool, but I realy cant understand how this AU3 script can run...

Please

Posted

I assumed they were in your function bk-logfile.au3

If not, then convert them to ConsoleWrite commands...

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

  • 2 weeks later...
Posted

Working on the script, and asking other guys, I do it runs.... well... more or less...

The code are:

$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="&@UserName&"));Company;subtree"
$objRecordSet = $objCommand.Execute
if $objRecordSet.RecordCount = 0 then
  MsgBox(0,"","Not Found!")
else
  MsgBox(0,"",$objRecordSet(0))
EndIf
$objConnection.Close()

If the script found the object, the msgbox shows ever the same 3 characters "ÀË"¸ or "¾Ë" if I dont use @UserName and fix the username.

Aby one knows why the script do not returns the corect object property text?

TKS

Pierre

Posted

Any ideas on how to pull multiple fields from the ldap search? below is what i got and it keeps erroring on the second .value Any suggestions?

;Script Options
autoitsetoption("trayiconhide", 1)
#include <GUIConstants.au3>
#include<constants.au3>
opt("GUIDataSeparatorChar", Chr('13'))

;Creation of GUI
GUICreate("Employee Contact Information App", 400,400)

;Search, list and TAB
GUICtrlCreateLabel("Employee last name:",20,16)
$name1=GUICtrlCreateInput("",20,30,100,"")
$search=GUICtrlCreateButton("Search",70,55,50,"",$BS_DEFPUSHBUTTON)
GUICtrlCreateLabel("Results:",130,16)
$list=GUICtrlCreateList("",130,30,160,75,-1)
$edit=GUICtrlCreateButton("   Edit Info   ",295,65,70,22)

;Close button
$close=guictrlcreatebutton("    Close    ",321,360)

;General Information
guictrlcreatetab(15,100,370,250)
GUICtrlCreatetabitem("  General Info  ")
guictrlcreatelabel("Description",25,130)
$desc=GUICtrlCreateinput("",25,145,200,20,-1)
guictrlcreatelabel("Office",25,170)
$office=GUICtrlCreateinput("",25,185,200,20,-1)
guictrlcreatelabel("Telephone",25,210)
$tel=GUICtrlCreateinput("",25,225,200,20,-1)

;Address Information
;guictrlcreatetabitem("  Address Info  ")
;guictrlcreatelabel("Street",25,130)
;guictrlcreateedit("",25,145,155,40,Bitor($ES_WANTRETURN,$WS_VSCROLL,$ES_MULTILINE))
;guictrlcreatelabel("P.O. Box",25,190)
;guictrlcreateinput("",25,205,155,20,-1)
;guictrlcreatelabel("City",25,230)
;guictrlcreateinput("",25,245,155,20,-1)
;guictrlcreatelabel("State/Province",25,265)
;guictrlcreateinput("",25,280,155,20,-1)
;guictrlcreatelabel("Zip/Postal Code",200,265)
;guictrlcreateinput("",200,280,155,20,-1)
;guictrlcreatelabel("Country/region",25,300)
;GUICtrlCreateCombo("",25,315,155,20,-1)

;Telephones Information
GUICtrlCreateTabItem("  Telephones  ")
guictrlcreatelabel("Home",25,130)
$hometel=GUICtrlCreateinput("",25,145,200,20,-1)
guictrlcreatelabel("Mobile",25,170)
$mobile=GUICtrlCreateinput("",25,185,200,20,-1)
guictrlcreatelabel("Fax",25,210)
$fax=GUICtrlCreateinput("",25,225,200,20,-1)
;Organization Information
Guictrlcreatetabitem("  Organization  ")
guictrlcreatelabel("Title",25,130)
$title=GUICtrlCreateinput("",25,145,200,20,-1)
guictrlcreatelabel("Department",25,170)
$dept=GUICtrlCreateinput("",25,185,200,20,-1)
guictrlcreatelabel("Company",25,210)
$company=GUICtrlCreateinput("",25,225,200,20,-1)

;Show Application Window
GUISetState(@SW_SHOW)
;Actions
while 1
    $msg=GUIGetMsg()
    Dim $input
    Dim $PID
    $objConnection = ObjCreate("ADODB.Connection")
    $objConnection.Open ("Provider=ADsDSOObject;")
    $objCommand = ObjCreate("ADODB.Command")
    $objCommand.ActiveConnection = $objConnection

Select
Case $msg=$search 
    ProgressOn("Please Wait","Searching...","0 percent")
    guictrlsetdata($list, "")
    ProgressSet( 10, "10 percent")
    $PID=Run(@comspec & " /c" & " dsquery user -name " & guictrlread($name1) & "* " & "-o rdn -limit 1000", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    ProgressSet( 20, "20 percent")
sleep(1000)
    ProgressSet( 60, "60 percent")
    $input=stdoutread($PID)
    ProgressSet( 70, "70 percent")
    $strip=stringreplace($input,chr(10),"")
    ProgressSet( 80, "80 percent")
    $strip2=stringreplace($strip,'"',"")
    ProgressSet( 90, "90 percent")
    guictrlsetdata($list, $strip2 )
    ProgressSet( 100, "100 percent")
sleep(100)
    progressoff()
case $msg=$edit
$objCommand.CommandText = "<LDAP://dc=test,dc=com>;(&(objectCategory=User)(displayName="&guictrlread($list)&"));Company, Department;subtree"
$objRecordSet = $objCommand.Execute
if $objRecordSet.RecordCount = 0 then
  MsgBox(0,"","Not Found!")
else
    guictrlsetdata($company, $objRecordSet.Fields("Company").Value)
    guictrlsetdata($office, $objRecordSet.Fields("Office").Value)
EndIf

Case $msg=$GUI_EVENT_CLOSE
    ExitLoop
Case $msg=$close
    ExitLoop
EndSelect
wend
$objConnection.Close()


            
        

        

        
    

    
    

    

                    
                    
                        
                    
                    
                

                    

                    
                    






    

    

    
        
            
                


    
        
    

                
                
                    
                        

                    
                
            
        
        
            
                


ter-pierre
            
            
                Posted 
                
            
        
    
    
        


ter-pierre
            
        
        
            
                
                    


    
        
    

                    
                    
                        

                    
                
            
            
                Active Members
                
            
            
                
                    
                        
                            
                                
                            
                                 85
                            
                                
                            
                        
                        
                    
                
            
            
                

            
        
    
    
        



    
        
            
                
                    
                        Author
                    
                    
                    
                    
                    
                
            
            
                
                    
                    
                        
                        
                        
                        
                        
                        
                            
                                
                            
                            
                            
                            
                            
                            
                        
                    
                
                
            
        

        
           
           Posted 
           
            
            
                
                
            
        
    

    

    

    
        
        
            I think that are you querying Department and trying to show Office.

Try to change thin the red line Office by Department

Pierre


            
        

        

        
    

    
    

    

                    
                    
                        
                    
                    
                

                    

                    
                    






    

    

    
        
            
                


    
        
    

                
                
                    
                        

                    
                
            
        
        
            
                


Richie20
            
            
                Posted 
                
            
        
    
    
        


Richie20
            
        
        
            
                
                    


    
        
    

                    
                    
                        

                    
                
            
            
                Members
                
            
            
                
                    
                        
                            
                                
                            
                                 3
                            
                                
                            
                        
                        
                    
                
            
            
                

            
        
    
    
        



    
        
            
                
                    
                    
                    
                    
                    
                
            
            
                
                    
                    
                        
                        
                        
                        
                        
                        
                            
                                
                            
                            
                            
                            
                            
                            
                        
                    
                
                
            
        

        
           
           Posted 
           
            
            
                
                
            
        
    

    

    

    
        
        
            I think that are you querying Department and trying to show Office.Try to change thin the red line Office by DepartmentPierrethanks for your help! I am new to LDAP searches.I think originally i had office there, but it still errored out. I changed the second field value to department and it worked for department. i think i just need to find out the correct search filters for each field/attribute i am looking for.Thanks again.


            
        

        

        
    

    
    

    

                    
                    
                        
                    
                    
                

                    

                    
                    






    

    

    
        
            
                


    
        
    

                
                
                    
                        

                    
                
            
        
        
            
                


Richie20
            
            
                Posted 
                
            
        
    
    
        


Richie20
            
        
        
            
                
                    


    
        
    

                    
                    
                        

                    
                
            
            
                Members
                
            
            
                
                    
                        
                            
                                
                            
                                 3
                            
                                
                            
                        
                        
                    
                
            
            
                

            
        
    
    
        



    
        
            
                
                    
                    
                    
                    
                    
                
            
            
                
                    
                    
                        
                        
                        
                        
                        
                        
                            
                                
                            
                            
                            
                            
                            
                            
                        
                    
                
                
            
        

        
           
           Posted 
           
            
            
                
                
            
        
    

    

    

    
        
        
            Do you know if i can use these same functions to send info instead of retrieving it? Basicly i want to beable to edit the fields i am pulling. Thanks.


            
        

        

        
    

    
    

    

                    
                    
                        
                    
                    
                

                    

                    
                    






    

    

    
        
            
                


    
        
    

                
                
                    
                        

                    
                
            
        
        
            
                


ter-pierre
            
            
                Posted 
                
            
        
    
    
        


ter-pierre
            
        
        
            
                
                    


    
        
    

                    
                    
                        

                    
                
            
            
                Active Members
                
            
            
                
                    
                        
                            
                                
                            
                                 85
                            
                                
                            
                        
                        
                    
                
            
            
                

            
        
    
    
        



    
        
            
                
                    
                        Author
                    
                    
                    
                    
                    
                
            
            
                
                    
                    
                        
                        
                        
                        
                        
                        
                            
                                
                            
                            
                            
                            
                            
                            
                        
                    
                
                
            
        

        
           
           Posted 
           
            
            
                
                
            
        
    

    

    

    
        
        
            Yes. I think that is possible, but I dont know exactly how. Needs to search and lost some time...


            
        

        

        
    

    
    

    

                    
                    
                        
                            


     (adsbygoogle = window.adsbygoogle || []).push({});

                        
                    
                    
                

                    

                    
                    






    

    

    
        
            
                


    
        
    

                
                
                    
                        

                    
                
            
        
        
            
                


ter-pierre
            
            
                Posted 
                
            
        
    
    
        


ter-pierre
            
        
        
            
                
                    


    
        
    

                    
                    
                        

                    
                
            
            
                Active Members
                
            
            
                
                    
                        
                            
                                
                            
                                 85
                            
                                
                            
                        
                        
                    
                
            
            
                

            
        
    
    
        



    
        
            
                
                    
                        Author
                    
                    
                    
                    
                    
                
            
            
                
                    
                    
                        
                        
                        
                        
                        
                        
                            
                                
                            
                            
                            
                            
                            
                            
                        
                    
                
                
            
        

        
           
           Posted 
           
            
            
                
                
            
        
    

    

    

    
        
        
            
Hi guys.

My script are running perfectly.... except on W9x workstations...  

$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=tstuser));memberOf,Company;subtree"
$objRecordSet = $objCommand.Execute
if $objRecordSet.RecordCount = 0 then
  MsgBox(0,"","Not found")
else
   MsgBox(0,"",$objRecordSet.Fields("Company").Value)
EndIf
$objConnection.Close()

an error popup point to $objRecordSet = $objCommand.Execute line.

Any ones can help me?

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
  • Recently Browsing   0 members

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