Jump to content

GUI Newb Needs A Little Direction


Recommended Posts

Hey guys, been using AutoIt for a few years now and never really got a chance to mess with the GUI stuff. But now I'm developing this simple reporting tools that I would like to open up with a GUI. The script is a basic Active Directory search and report script using dsquery.exe and dsget.exe. I know there is an adfunctions UDF but I'm trying to keep things as simple as possible without using third-party tools/scripts.

Here is the script:

#Region;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=beta.exe
#EndRegion;**** Directives created by AutoIt3Wrapper_GUI ****
#include<Array.au3>
#include<File.au3>

$root=ObjGet("LDAP://RootDSE")
$domain=$root.Get("defaultNamingContext")

$dsquery="bin\dsquery.exe"
$dsget="bin\dsget.exe"
$results=""
$get=""
$out=""

$query=Run($dsquery&' user "OU=users,OU=jax,'&$domain&'" -limit 0 -scope subtree',"","", 2)

Do
    $results&=StdOutRead($query)
Until @error

$array=StringSplit($results,@CRLF,1)

_ArrayDelete($array,_ArrayMax($array))

For $item In $array
    $cmd=Run($dsget&" user "&$item&" -samid","","", 2)
        Do
            $get&=StdOutRead($cmd)
        Until @error
Next

$get=StringReplace($get,"samid","")
$get=StringReplace($get,"dsget succeeded","")
$get=StringStripWS($get,4)
$get=StringReplace($get," ",@CRLF)
$get=StringSplit($out,@CRLF,1)

_ArrayDelete($out,_ArrayMax($out))
_ArrayDelete($out,1)
_ArrayMaxIndex($out)
$c=UBound($out)
$get[0]=$c
_ArraySort($out)

_FileWriteFromArray("c:\test.txt",$out,1)

And here is the basic GUI code I got from messing around with the Koda form designer:

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Administrator\Desktop\scripts\gui.kxf
$Query=GUICreate("Query",201,251,193,115)
GUICtrlCreateCombo("",8,32,150,25)
GUICtrlSetData(-1,"jax\users|jax\desktops|jax\desktops\ormond|jax\mobile|jax\servers|jax\groups\security|jax\groups\exchange")
$File=GUICtrlCreateInput("File",8,168,98,21)
$Browse=GUICtrlCreateButton("Browse",108,169,50,20,0)
$Recursive=GUICtrlCreateCheckbox("Recursive",8,56,75,17)
GUICtrlCreateCombo("",8,8,150,25)
GUICtrlSetData(-1,"user|computer|group|ou")
$Email=GUICtrlCreateCheckbox("email",88,72,75,25)
$Name=GUICtrlCreateCheckbox("name",8,96,75,25)
$User=GUICtrlCreateCheckbox("user",8,72,75,25)
$Dn=GUICtrlCreateCheckbox("dn",8,120,75,25)
$Tel=GUICtrlCreateCheckbox("tel",88,96,75,25)
$Fax=GUICtrlCreateCheckbox("fax",88,120,75,25)
$Desc=GUICtrlCreateCheckbox("desc",8,144,75,25)
$Progress=GUICtrlCreateProgress(8,216,150,25)
$Run=GUICtrlCreateButton("Run",107,192,50,20,0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg=GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit

Case $Browse
Case $Run
EndSwitch
WEnd

I really just have no idea how I structure those two, how I make it so when I click a check box it adds that variable to the script, etc. I'm not looking for anyone to do it for just maybe give me some basic pointers to get me going.

Also, if anyone would like to help streamline the script that would be good, I'm sure I'm going about somethings the wrong way so help a brother out!

*The script won't work unless you have dsquery and dsget in a 'bin' folder parallel to the script. I do this because the workstation I run it from isn't Server 2003 so it doesn't have it by default. If you run this from a server you can edit those variables so it uses the server's copy located in system32. Also don't forget to check the syntax for the dsquery part, since my OU structure is bound to be different than yours.*

Link to comment
Share on other sites

The magic is here:

While 1
$nMsg=GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit

Case $Browse
Case $Run
EndSwitch
WEndoÝ÷ Ú²Ì!jÜ(ºWaj^^*.¦·¬±çmæë£nëm¢r'Ê«q«Ê°¢é]¶©Ê«r^vºw-źw&Éû§pIÝéÜjwiºÙ²~éÜ{-y§h|Ë S¡È^rKazËZ¶ë(*.­È^rFèÅë.±á +kvX¤zʺÚ"µÍØÙH  ÌÍÐÝÜÙBRYÕRPÝXY
    ÌÍÔXÝÚ]JHH ÌÍÑÕRWÐÒPÒÑQ[BSÙÐÞ
    ][ÝÐ[ ][ÝË  ][ÝÔXÝÚ]HÈÚXÚÙY ÌÌÎÉ][ÝÊBQ[ÙBBSÙÐÞ
    ][ÝÐ[ ][ÝË  ][ÝÔXÝÚ]HÛÌÎNÝÚXÚÙY  ÌÌÎÉ][ÝÊBQ[Y

I think you'll figure it out.

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...