Jump to content
Sign in to follow this  
skippynz

error with my script - help!

Recommended Posts

skippynz

its been a while since ive had to post but heres the low down - Im wanting to export a list of users from groups in AD - i found a script here which does that but i wanted to modify a bit by putting in a gui etc. my problem is with the $GROUP1 = GuiCtrlCreateInput("Group Name", 45, 30, 300, 20) and $GROUP_NAME = GUICtrlRead ( $GROUP1 ) lines as when i use an input box the script works as it should

this is the error i get - " Export.au3 (61) : ==> Variable must be of type "Object".: "

the line the error occurs on is $objGroup.getInfo()

#include <GuiConstants.au3>

GuiCreate("OU_Location", 390, 110,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$QUESTION = GuiCtrlCreateLabel('Please enter the name of the group you would like to export below?', 35, 10)
$GROUP1 = GuiCtrlCreateInput("Group Name", 45, 30, 300, 20)
$AKL = GuiCtrlCreateButton("Auckland", 5, 55, 75, 20)
$HLZ = GuiCtrlCreateButton("Hamilton", 80, 55, 75, 20)
$WLG = GuiCtrlCreateButton("Wellington", 155, 55, 75, 20)
$CHC = GuiCtrlCreateButton("Christchurch", 230, 55, 75, 20)
$DUN = GuiCtrlCreateButton("Dunedin", 305, 55, 75, 20)
$NZ_NATIONAL = GuiCtrlCreateButton("NZ National Group", 130, 80, 125, 20)


$GROUP_NAME = GUICtrlRead ( $GROUP1  )

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $AKL
        $OU = "ou=groups,ou=auckland"
        Export()
        ExitLoop
    Case $msg = $HLZ
        $OU = "ou=groups,ou=hamilton"
        Export()
        ExitLoop
    Case $msg = $WLG
        $OU = "ou=Groups,ou=Wellington"
        Export()
        ExitLoop
    Case $msg = $CHC
        $OU = "ou=groups,ou=christchurch"
        Export()
        ExitLoop
    Case $msg = $DUN
        $OU = "ou=groups,ou=dunedin"
        Export()
        ExitLoop
    Case $msg = $NZ_NATIONAL
        $OU = "ou=nz national group"
        Export()
        ExitLoop
    EndSelect
WEnd
Exit

Func Export()
GuiSetState(@SW_HIDE)

;  Bind to Active Directory;
$objRootDSE = ObjGet("LDAP://RootDSE")
$strDNSDomain = $objRootDSE.Get("DefaultNamingContext")

;  Get the Builtin Administrators group
$strContainer = "cn=" & $GROUP_NAME & "," & $OU & " ,ou=nz, "
$objGroup = ObjGet ("LDAP://"& $strContainer & $strDNSDomain )
$objGroup.getInfo()

$adminlist = ""
$arrMemberOf = $objGroup.GetEx("member")
For $strMember in $arrMemberOf
    $user = ObjGet ("LDAP://"&$strMember)
    if isobj($user) Then $adminlist &= $user.sAMAccountName & @crlf
Next
    
msgbox(0,"Admin List",$adminlist)

EndFunc
Edited by craig.gill

Share this post


Link to post
Share on other sites
Paulie

well, i don't have the files, so i can't up and test your script, mind telling us where you think the problem might lie, as in whats not working?

Share this post


Link to post
Share on other sites
skippynz

well, i don't have the files, so i can't up and test your script, mind telling us where you think the problem might lie, as in whats not working?

when i run the script i get the gui ok - no problem there but when i enter in a value in the GuiCtrlCreateInputon the gui and press a button to runthe function it just errors - when i used the inputbox command it had the vaule there straight away so worked no worries

i tried with $GROUP_NAME = GUICtrlRead ( $GROUP1 ) as part of the case $msg = $akl etc but that didnt make a difference

PS this is the entire script if you change the OU=GROUPS,OU=AUCKLAND etc it should work for you if you are on a domain. also would need to change $strContainer = "cn=" & $GROUP_NAME & "," & $OU & " ,ou=nz, " to be correct also...

Share this post


Link to post
Share on other sites
skippynz

when i run the script i get the gui ok - no problem there but when i enter in a value in the GuiCtrlCreateInputon the gui and press a button to runthe function it just errors - when i used the inputbox command it had the vaule there straight away so worked no worries

i tried with $GROUP_NAME = GUICtrlRead ( $GROUP1 ) as part of the case $msg = $akl etc but that didnt make a difference

PS this is the entire script if you change the OU=GROUPS,OU=AUCKLAND etc it should work for you if you are on a domain. also would need to change $strContainer = "cn=" & $GROUP_NAME & "," & $OU & " ,ou=nz, " to be correct also...

dont worry found that i tried putting the $GROUP_NAME = GUICtrlRead ( $GROUP1 ) back into the case $msg=$akl and its working this time. not sure why it didnt before.... thanks

Share this post


Link to post
Share on other sites
PsaltyDS

when i run the script i get the gui ok - no problem there but when i enter in a value in the GuiCtrlCreateInputon the gui and press a button to runthe function it just errors - when i used the inputbox command it had the vaule there straight away so worked no worries

i tried with $GROUP_NAME = GUICtrlRead ( $GROUP1 ) as part of the case $msg = $akl etc but that didnt make a difference

PS this is the entire script if you change the OU=GROUPS,OU=AUCKLAND etc it should work for you if you are on a domain. also would need to change $strContainer = "cn=" & $GROUP_NAME & "," & $OU & " ,ou=nz, " to be correct also...

Don't you want to read the input control AFTER the operator hits a button?

I think you should move "$GROUP_NAME = GUICtrlRead($GROUP1)" to the top of the Export function:

Func Export()
     $GROUP_NAME = GUICtrlRead($GROUP1)
     GuiSetState(@SW_HIDE)

     ; The rest of the function
EndFunc ; ===> Export

:ph34r:

Edit: Doh! Beat me to it! :lmao:

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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  

×