Sign in to follow this  
Followers 0
CartoonDragon

Finished

17 posts in this topic

#1 ·  Posted (edited)

Hey Guys, i want to share with everyone, in wishing that this might be helpfull to someone else, all of this is thanks to Melba23 for all of his help and his patience.

To make this work you are going to need to download and use the script made by Water for the AD functions for the script. which can be found here:

Active Directory UDF - by Water

What it does for me:

1.) It checks the users credentials against our AD and checks how old the password is, and if the password needs to be changed

2.) It checks which groups the user is a member of, and by that i'll know which drives the user should have access to

3.) It reads the logfile that our logon script makes so i can figure out which computer the user has been using, and formulates the logfile to make it more reader friendly.

#include <GUIConstantsEx.au3>
#include <AD.au3>
#include <String.au3>
#include <file.au3>


_AD_Open()

$LogFile = "\\fs11\log$\login information.Log"
Global $File
Global $sList
Global $Noftimes

#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Password Checker", 806, 500, 192, 124)
$UserName = GUICtrlCreateInput("", 16, 32, 113, 21)
$Button1 = GUICtrlCreateButton("OK", 196, 465, 97, 25)
GUICtrlSetState(-1, $GUI_DEFBUTTON)
$Button2 = GUICtrlCreateButton("Close", 483, 465, 97, 25)
$Label1 = GUICtrlCreateLabel("Username", 16, 8, 107, 17)
$Label2 = GUICtrlCreateLabel("Status", 152, 8, 146, 17)
$Label3 = GUICtrlCreateLabel("User is a member of the following groups", 330, 8, 190, 17)
$Edit2 = GUICtrlCreateList("", 330, 32, 290, 200)
$Label3 = GUICtrlCreateLabel("User last logged on to:", 16, 238, 200, 17)
$hList = GUICtrlCreateList("", 16, 255, 780, 200, 1)
$Edit1 = GUICtrlCreateLabel("", 152, 30, 153, 25)

GUICtrlSetFont(-1, 8, 400, 0, "Verdana")
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###



While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $Button2
            _AD_Close()
            Exit
        Case $Button1
            $User = GUICtrlRead($UserName)
            $iEnd = UBound($File) - 1
            $Noftimes = 0
            $sList = "|"
            local $AUser2
            GUICtrlSetData($Edit2, "")
            $Status = _AD_IsPasswordExpired($User)
            If $Status = 0 Then
                If @error = 1 Then
                    GUICtrlSetData($Edit1, "User " & $User & " does not exist!")
                    GUICtrlSetColor(-1, 0xFF0000)
                Else
                    $aPWInfo = _AD_GetPasswordInfo($User)
                    $iDays = _DateDiff("D",_NowCalc(),$aPWInfo[9])
                    GUICtrlSetColor(-1, 0x008B00)                   
                    GUICtrlSetData($Edit1, "Password is not expired. Will expire in " & $iDays & " days")
                EndIf
            Else
                $aPWInfo = _AD_GetPasswordInfo($User)
                $iDays = _DateDiff("D",_NowCalc(),$aPWInfo[9])
                GUICtrlSetData($Edit1, "Password is expired. Expired " & Abs($iDays) & " days ago")
                GUICtrlSetColor(-1, 0xFF0000)
            EndIf
            
        $aUser = _AD_GetUserGroups($User)
        If @error > 0 Then
        GUICtrlSetData($Edit2, "User " & $User & " has not been assigned to any group")
        Else
        _ArraySort($aUser, 0, 1)
        _ArrayDelete($aUser, 0)
        $AUser2 = _ArrayToString($aUser, ",")
        $aUser2 = StringReplace($aUser2, "CN=Users,", ",")
        $aUser2 = _StringBetween($aUser2,"CN=", ",")
        $AUser2 = _ArrayToString($aUser2, "|")
        GUICtrlSetData($Edit2, $aUser2)
        EndIf

            If Not _FileReadToArray($LogFile, $File) Then
                MsgBox(4096, "Error", " Error reading log to Array     error:" & @error)
            Exit
            EndIf

$iEnd = UBound($File) - 1

Do
    ; Look for a line containing $User
    $iIndex = _ArraySearch($File, "\" & $User & " ", 0, $iEnd, 0, 1, 0)
    ; If we found one then add it to the List
        If Not ($iIndex = -1) Then
            $sLine = $File[$iIndex]
            ; Now format it as we require
            $sLine = StringReplace($sLine, "Homedir: \\fs2\home$\IT-ADM~1\", "")
            $sLine = StringReplace($sLine, "Homedir: \\fs2\home$\STUDER~1\", "")
            $sLine = StringReplace($sLine, "Homedir: \\eamv-fs1\Privat$\Ansatte\", "")
            $sLine = StringReplace($sLine, "Homedir: \\fs6\privat$\Ansatte\", "") ; get rid of the path info
            $sLine = StringReplace($sLine, ".int", ".int -")
            $sLine = StringReplace($sLine, "(", "- ") ; change the opening ( into -
            $sLine = StringReplace($sLine, ")", "") ; remove the final )
            ; Now add to the List contents
            $sList &= $sLine & "|"
            ; Amend the last search element
            $iEnd = $iIndex - 1
            ; if we have reached the top line then exit the search
            If $iEnd = 0 Then ExitLoop
            ; Increase the count
            $Noftimes += 1
    Else
        ; If we found nothing then exit the search
        ExitLoop
    EndIf

Until $Noftimes = 15

; Put the data into the list
GUICtrlSetData($hList, $sList)

    EndSwitch
                    
WEnd
Edited by CartoonDragon

Share this post


Link to post
Share on other sites



Cartoondragon,

how to split the file in to [...] or array,

_FileReadToArray.

search for thies things

_ArraySearch - using the $iPartial parameter and looping through the file using an updated $iStart parameter each time you find a match.

how to split up the file

I presume you mean convert the lines into the required format, in which case StringReplace would seem to meet the bill.

I hope that gives you enough pointers. :blink:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Here is what code i've been able to come up with so far, but problem is, how do i pull the information out of the array and use the lines that i've picked out now?

#include <file.au3>
#Include <Array.au3>

Dim $File
Dim $FLines
$LogFile = "log-ans.txt"
$User = "pvj"

If Not _FileReadToArray($LogFile,$File) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf

_ArrayDisplay($File, $LogFile)

$iStart = 0
Do
$iIndex = _ArraySearch($File, $User, $iStart , 0, 0, 1, 1)
msgbox(0, "Array Search 2", $iIndex)
$iStart = $iIndex +1
Until $iStart = 0

Share this post


Link to post
Share on other sites

I'm no expert on autoit, but it seems that you need todo a for loop.

Share this post


Link to post
Share on other sites

I'm no expert on autoit, but it seems that you need todo a for loop.

that might very well be true, but seems i'm unable to figure out how to do a todo loop, which was why i changed it to this.

Share this post


Link to post
Share on other sites

I think you misunderstood what I wrote. You need a "FOR" loop.

Share this post


Link to post
Share on other sites

Cartoondragon,

Nice start - you were almost there! :P

See if you can follow this: :blink:

#include <GUIConstantsEx.au3>
#include <file.au3>
#include <Array.au3>

Global $File ; Use Global/Local instead of Dim

$LogFile = "log-ans.txt"
$User = "pvj"
$sList = "|"
$iStart = 0

If Not _FileReadToArray($LogFile, $File) Then
    MsgBox(4096, "Error", " Error reading log to Array     error:" & @error)
    Exit
EndIf

$hGUI = GUICreate("Test", 500, 500)

$hList = GUICtrlCreateList("", 10, 10, 480, 200)

GUISetState()

Do
    ; Look for a line containing $User
    $iIndex = _ArraySearch($File, $User, $iStart, 0, 0, 1, 1)
    ; If we found one then add it to the List
    If Not @error Then
        $sLine = $File[$iIndex]
        ; Now format it as we require
        $sLine = StringReplace($sLine, "Homedir: \\fs6\privat$\Ansatte\", "") ; get rid of the path info
        $sLine = StringReplace($sLine, "(", "- ") ; change the opening ( into -
        $sLine = StringReplace($sLine, ")", "") ; remove the final )
        ; Now add to the List contents
        $sList &= $sLine & "|"
    EndIf
    $iStart = $iIndex + 1

Until $iIndex = -1

; Put the data into the list
GUICtrlSetData($hList, $sList)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Please ask if you have any questions. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

hmm the script works per say, but when i let it lose on the log file, it will drop informaiton in at random.

My logfile goes from earliest date and to current date and time at the bottom, but when i run the script on it, it will show me:

Posted Image

does this make any sense?

Share this post


Link to post
Share on other sites

Cartoondragon,

does this make any sense?

What is random about that? It looks as if you have all the lines which include jsm in the format you asked for, which is what the script is supposed to do. :blink:

I see that your original post asked that the "output should be from the bottom of the file and up, and just the last 5-10 or so". So use the $iForward parameter in _ArraySearch to search from the end of the array and add a counter to limit the number of lines to find.

Give it a go yourself - you did pretty well last time. You know where we are if you run into problems. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Alright, i guess i've managed to figure out how to get only 10 outputs, but the output has been sorted, by the contense of the line. I need it to be sorted by the line it was on in the text document, any good idea how to do this?

When you look at the picture i posted above, you should be able to see that it has the time stamp at the beginning, and thats actually what it's been sorted by, by the hour, not the date.....which is the problem.

#include <GUIConstantsEx.au3>
#include <file.au3>
#include <Array.au3>

Global $File ; Use Global/Local instead of Dim

$LogFile = "\\fs11\log$\log-ans.txt"
;~ $LogFile = "log-ans.txt"
$User = "jsm"
$sList = "|"
$iStart = 0
$Noftimes = 0

If Not _FileReadToArray($LogFile, $File) Then
    MsgBox(4096, "Error", " Error reading log to Array     error:" & @error)
    Exit
EndIf

$hGUI = GUICreate("Test", 500, 500)

$hList = GUICtrlCreateList("", 10, 10, 480, 200)

GUISetState()

Do
    ; Look for a line containing $User
    $iIndex = _ArraySearch($File, $User, $iStart, 0, 0, 1, 1)
    ; If we found one then add it to the List
    If Not @error Then
        $sLine = $File[$iIndex]
        ; Now format it as we require
        $sLine = StringReplace($sLine, "Homedir: \\fs2\home$\IT-ADM~1\", "")
        $sLine = StringReplace($sLine, "Homedir: \\fs2\home$\STUDER~1\", "")
        $sLine = StringReplace($sLine, "Homedir: \\eamv-fs1\Privat$\Ansatte\", "")
        $sLine = StringReplace($sLine, "Homedir: \\fs6\privat$\Ansatte\", "") ; get rid of the path info
        $sLine = StringReplace($sLine, ".int", ".int -")
        $sLine = StringReplace($sLine, "(", "- ") ; change the opening ( into -
        $sLine = StringReplace($sLine, ")", "") ; remove the final )
        ; Now add to the List contents
        $sList &= $sLine & "|"
    EndIf
    $iStart = $iIndex + 1
    $Noftimes = $Noftimes + 1
Until $iIndex = -1 or $Noftimes = 10

; Put the data into the list
GUICtrlSetData($hList, $sList)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Edited by CartoonDragon

Share this post


Link to post
Share on other sites

Cartoondragon,

Lists are created with an automatic $LBS_SORT style. Just change this line to remove it:

$hList = GUICtrlCreateList("", 10, 10, 480, 200, BitOR($WS_BORDER, $WS_VSCROLL))

You should now get the list as you enter it. :blink:

If you do not understand styles that well, could I recommend the "Setting Styles" tutorial that I have just added to the Wiki? ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

I am afraid i need more help, i cannot figure out how to use the Array to turn it around, i understand that i use the $iForward function of the _ArraySearch, but when i change it, i end up with 5 times the same line, which really confuseses me because i asked for 10 times......

#include <GUIConstantsEx.au3>
#include <file.au3>
#include <Array.au3>

Global $File ; Use Global/Local instead of Dim

$LogFile = "\\fs11\log$\log-ans.txt"
$User = "coe"
$sList = "|"
$iStart = 1
$Noftimes = 0


If Not _FileReadToArray($LogFile, $File) Then
    MsgBox(4096, "Error", " Error reading log to Array     error:" & @error)
    Exit
EndIf

$hGUI = GUICreate("Test", 500, 210)

$hList = GUICtrlCreateList("", 10, 10, 480, 200, 1)

GUISetState()

Do
    ; Look for a line containing $User
    $iIndex = _ArraySearch($File, $User, $iStart, 0, 0, 1, 0)
    ; If we found one then add it to the List
    If Not @error Then
        $sLine = $File[$iIndex]
        ; Now format it as we require
        $sLine = StringReplace($sLine, "Homedir: \\fs2\home$\IT-ADM~1\", "")
        $sLine = StringReplace($sLine, "Homedir: \\fs2\home$\STUDER~1\", "")
        $sLine = StringReplace($sLine, "Homedir: \\eamv-fs1\Privat$\Ansatte\", "")
        $sLine = StringReplace($sLine, "Homedir: \\fs6\privat$\Ansatte\", "") ; get rid of the path info
        $sLine = StringReplace($sLine, ".int", ".int -")
        $sLine = StringReplace($sLine, "(", "- ") ; change the opening ( into -
        $sLine = StringReplace($sLine, ")", "") ; remove the final )
        ; Now add to the List contents
        $sList &= $sLine & "|"
    EndIf
     $iStart = $iIndex + 1
    $Noftimes = $Noftimes + 1
;~ Until $iIndex = -1 or $Noftimes = 10
Until $Noftimes = 10
; Put the data into the list
GUICtrlSetData($hList, $sList)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites

First of all, a HUGE thanks to Melba23 for keeping on helping me, that was very kind of you to keep helping me so much.

Having been unable to figure out my problem, i decided to make more possible problems for my self, and indeed i made more problems.

so i've added AD functions to it by abusing Active Directory UDF - by Water

By doing so, i end up with something that looks like this:

Posted Image

no matter how much i look around the forum, i cannot find examples of anyone who uses the array function like i'm and there for cannot figure out where i have gone wrong.

the functions that i've asked it to do, work, but here is what i still need help with doing any hints or examples of doing it would be very much apprisiated:

1.) Make the array give me the backwards information output, i know the $iForward function of it, but can't make it work.

2.) Clear the field/only write the newest inputs, because when i look up a new user, it just adds the information to the array.

#include <GUIConstantsEx.au3>
#include <AD.au3>
#include <String.au3>
#include <file.au3>


_AD_Open()

$LogFile = "\\fs11\log$\login information.Log"
Global $File
$sList = "|"
$iStart = 0
$Noftimes = 0

#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Password Checker", 806, 500, 192, 124)
$UserName = GUICtrlCreateInput("", 16, 32, 113, 21)
$Button1 = GUICtrlCreateButton("OK", 116, 465, 97, 25)
GUICtrlSetState(-1, $GUI_DEFBUTTON)
$Button2 = GUICtrlCreateButton("Close", 253, 465, 97, 25)
$Label1 = GUICtrlCreateLabel("Username", 16, 8, 107, 17)
$Label2 = GUICtrlCreateLabel("Status", 152, 8, 146, 17)
$Label3 = GUICtrlCreateLabel("User is a member of the following groups", 330, 8, 190, 17)
$Edit2 = GUICtrlCreateList("", 330, 32, 290, 200)
$Label3 = GUICtrlCreateLabel("User last logged on to:", 16, 238, 200, 17)
$hList = GUICtrlCreateList("", 16, 255, 780, 200, 1)
$Edit1 = GUICtrlCreateLabel("", 152, 30, 153, 25)

GUICtrlSetFont(-1, 8, 400, 0, "Verdana")
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###



While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $Button2
            _AD_Close()
            Exit
        Case $Button1
            $User = GUICtrlRead($UserName)
            $Status = _AD_IsPasswordExpired($User)
            If $Status = 0 Then
                If @error = 1 Then
                    GUICtrlSetData($Edit1, "User " & $User & " does not exist!")
                    GUICtrlSetColor(-1, 0xFF0000)
                Else
                    $aPWInfo = _AD_GetPasswordInfo($User)
                    $iDays = _DateDiff("D",_NowCalc(),$aPWInfo[9])
                    GUICtrlSetColor(-1, 0x008B00)                   
                    GUICtrlSetData($Edit1, "Password is not expired. Will expire in " & $iDays & " days")
                EndIf
            Else
                $aPWInfo = _AD_GetPasswordInfo($User)
                $iDays = _DateDiff("D",_NowCalc(),$aPWInfo[9])
                GUICtrlSetData($Edit1, "Password is expired. Expired " & Abs($iDays) & " days ago")
                GUICtrlSetColor(-1, 0xFF0000)
            EndIf
            
        $aUser = _AD_GetUserGroups($User)
        If @error > 0 Then
        GUICtrlSetData($Edit2, "User " & $User & " has not been assigned to any group")
        Else
        _ArraySort($aUser, 0, 1)
        _ArrayDelete($aUser, 0)
        $AUser2 = _ArrayToString($aUser, ",")
        $aUser2 = _StringBetween($aUser2,"CN=", ",")
        $AUser2 = _ArrayToString($aUser2, "|")
        GUICtrlSetData($Edit2, $aUser2)
        EndIf

            If Not _FileReadToArray($LogFile, $File) Then
                MsgBox(4096, "Error", " Error reading log to Array     error:" & @error)
            Exit
            EndIf
Do
    ; Look for a line containing $User
    $iIndex = _ArraySearch($File, "\" & $User & " ", $iStart, 0, 0, 1, 1)
    ; If we found one then add it to the List
    If Not @error Then
        $sLine = $File[$iIndex]
        ; Now format it as we require
        $sLine = StringReplace($sLine, "Homedir: \\fs2\home$\IT-ADM~1\", "")
        $sLine = StringReplace($sLine, "Homedir: \\fs2\home$\STUDER~1\", "")
        $sLine = StringReplace($sLine, "Homedir: \\eamv-fs1\Privat$\Ansatte\", "")
        $sLine = StringReplace($sLine, "Homedir: \\fs6\privat$\Ansatte\", "") ; get rid of the path info
        $sLine = StringReplace($sLine, ".int", ".int -")
        $sLine = StringReplace($sLine, "(", "- ") ; change the opening ( into -
        $sLine = StringReplace($sLine, ")", "") ; remove the final )
        ; Now add to the List contents
        $sList &= $sLine & "|"
    EndIf
    $iStart = $iIndex + 1
$Noftimes = ($Noftimes + 1)
Until $iIndex = -1 or $Noftimes = 15
;~ Until $iIndex = -1
; Put the data into the list
GUICtrlSetData($hList, $sList)

    EndSwitch
                    
WEnd

Share this post


Link to post
Share on other sites

Cartoondragon,

Here is the code to search the array in reverse order. I had actually never done it before (thanks for the question :P ) so I had to experiment a bit - which is why it took a while! :

As you can see, you need to change the $iEnd parameter, not $iStart: :blink:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <file.au3>
#include <Array.au3>

Global $File ; Use Global/Local instead of Dim

$LogFile = "log-ans.txt"
$User = "pvj"
$sList = "|"
$iStart = 1
$Noftimes = 0


If Not _FileReadToArray($LogFile, $File) Then
    MsgBox(4096, "Error", " Error reading log to Array     error:" & @error)
    Exit
EndIf

$hGUI = GUICreate("Test", 500, 210)

$hList = GUICtrlCreateList("", 10, 10, 480, 200,  BitOR($WS_BORDER, $WS_VSCROLL))

GUISetState()

$iEnd = UBound($File) - 1

Do
    ; Look for a line containing $User
    $iIndex = _ArraySearch($File, $User, 0, $iEnd, 0, 1, 0)
    ; If we found one then add it to the List
    If Not ($iIndex = -1) Then
        $sLine = $File[$iIndex]
        ; Now format it as we require
        $sLine = StringReplace($sLine, "Homedir: \\fs2\home$\IT-ADM~1\", "")
        $sLine = StringReplace($sLine, "Homedir: \\fs2\home$\STUDER~1\", "")
        $sLine = StringReplace($sLine, "Homedir: \\eamv-fs1\Privat$\Ansatte\", "")
        $sLine = StringReplace($sLine, "Homedir: \\fs6\privat$\Ansatte\", "") ; get rid of the path info
        $sLine = StringReplace($sLine, ".int", ".int -")
        $sLine = StringReplace($sLine, "(", "- ") ; change the opening ( into -
        $sLine = StringReplace($sLine, ")", "") ; remove the final )
        ; Now add to the List contents
        $sList &= $sLine & "|"
        ; Amend the last search element
        $iEnd = $iIndex - 1
        ; Increase the count
        $Noftimes += 1
    Else
        ; If we found nothing then exit the search
        ExitLoop
    EndIf

Until $Noftimes = 10

; Put the data into the list
GUICtrlSetData($hList, $sList)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

I know nothing about AD functions, so I am pulling out now. It might be better to start a new thread as people seldom enter long-running ones like this.

Good luck! ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Thanks a lot Melba23

That worked beautifully, but as to the AD? all the AD stuff works, it's this window i have a problem with, i need to empty the array/string to check another name.

So here, to not be confusing, i've removed the AD functions of the script.

What happens when i press the button the first time, is that it will give me the 10 last lines, so that works, but when i type in another name and press the button again, it will not clear the first info out, it will just add to the bottom, and it will ignore the 10 times limit that was put on.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <file.au3>
#include <Array.au3>

Global $File ; Use Global/Local instead of Dim

$LogFile = "\\fs11\log$\log-ans.txt"
Global $sList = "|"
Global $Noftimes = 0


If Not _FileReadToArray($LogFile, $File) Then
    MsgBox(4096, "Error", " Error reading log to Array     error:" & @error)
    Exit
EndIf
;~ $iStart = _FileCountLines($LogFile)
;~ msgbox(0,"the lines man!", $iStart)
$hGUI = GUICreate("Test", 500, 290)
$Label1 = GUICtrlCreateLabel("Username", 16, 8, 107, 17)
$UserName = GUICtrlCreateInput("", 16, 25, 113, 21)
$hList = GUICtrlCreateList("", 10, 80, 480, 150, 1)
$Button1 = GUICtrlCreateButton("OK", 16, 250, 97, 25)
GUICtrlSetState(-1, $GUI_DEFBUTTON)
$Button2 = GUICtrlCreateButton("Close", 153, 250, 97, 25)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $Button2
            Exit
        Case $Button1
            $User = GUICtrlRead($UserName)
            $iEnd = UBound($File) - 1
            Do
            ; Look for a line containing $User
            $iIndex = _ArraySearch($File, $User, 0, $iEnd, 0, 1, 0)
            ; If we found one then add it to the List
                If Not ($iIndex = -1) Then
                    $sLine = $File[$iIndex]
                    ; Now format it as we require
                    $sLine = StringReplace($sLine, "Homedir: \\fs2\home$\IT-ADM~1\", "")
                    $sLine = StringReplace($sLine, "Homedir: \\fs2\home$\STUDER~1\", "")
                    $sLine = StringReplace($sLine, "Homedir: \\eamv-fs1\Privat$\Ansatte\", "")
                    $sLine = StringReplace($sLine, "Homedir: \\fs6\privat$\Ansatte\", "") ; get rid of the path info
                    $sLine = StringReplace($sLine, ".int", ".int -")
                    $sLine = StringReplace($sLine, "(", "- ") ; change the opening ( into -
                    $sLine = StringReplace($sLine, ")", "") ; remove the final )
                    ; Now add to the List contents
                    $sList &= $sLine & "|"
                    ; Amend the last search element
                    $iEnd = $iIndex - 1
                    ; Increase the count
                    $Noftimes += 1
                Else
                    ; If we found nothing then exit the search
                    ExitLoop
                EndIf
            
            Until $Noftimes = 10
            GUICtrlSetData($hList, $sList)
    EndSwitch

WEnd
Edited by CartoonDragon

Share this post


Link to post
Share on other sites

Cartoondragon,

Just reset the search parameters before you start a new search: :blink:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <file.au3>
#include <Array.au3>

Global $File ; Use Global/Local instead of Dim

Global $LogFile = "log-ans.txt"
Global $sList
Global $Noftimes


If Not _FileReadToArray($LogFile, $File) Then
    MsgBox(4096, "Error", " Error reading log to Array     error:" & @error)
    Exit
EndIf
;~ $iStart = _FileCountLines($LogFile)
;~ msgbox(0,"the lines man!", $iStart)
$hGUI = GUICreate("Test", 500, 290)
$Label1 = GUICtrlCreateLabel("Username", 16, 8, 107, 17)
$UserName = GUICtrlCreateInput("", 16, 25, 113, 21)
$hList = GUICtrlCreateList("", 10, 80, 480, 150, 1)
$Button1 = GUICtrlCreateButton("OK", 16, 250, 97, 25)
GUICtrlSetState(-1, $GUI_DEFBUTTON)
$Button2 = GUICtrlCreateButton("Close", 153, 250, 97, 25)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $Button2
            Exit
        Case $Button1
            ; Reset search parameters
            $User = GUICtrlRead($UserName)
            $iEnd = UBound($File) - 1
            $Noftimes = 0
            $sList = "|"
            ; Run the search
            Do
            ; Look for a line containing $User
            $iIndex = _ArraySearch($File, $User, 0, $iEnd, 0, 1, 0)
            ; If we found one then add it to the List
                If Not ($iIndex = -1) Then
                    $sLine = $File[$iIndex]
                    ; Now format it as we require
                    $sLine = StringReplace($sLine, "Homedir: \\fs2\home$\IT-ADM~1\", "")
                    $sLine = StringReplace($sLine, "Homedir: \\fs2\home$\STUDER~1\", "")
                    $sLine = StringReplace($sLine, "Homedir: \\eamv-fs1\Privat$\Ansatte\", "")
                    $sLine = StringReplace($sLine, "Homedir: \\fs6\privat$\Ansatte\", "") ; get rid of the path info
                    $sLine = StringReplace($sLine, ".int", ".int -")
                    $sLine = StringReplace($sLine, "(", "- ") ; change the opening ( into -
                    $sLine = StringReplace($sLine, ")", "") ; remove the final )
                    ; Now add to the List contents
                    $sList &= $sLine & "|"
                    ; Amend the last search element
                    $iEnd = $iIndex - 1
                    ; if we have reached the top line then exit the search
                    If $iEnd = 0 Then ExitLoop
                    ; Increase the count
                    $Noftimes += 1
                Else
                    ; If we found nothing then exit the search
                    ExitLoop
                EndIf

            Until $Noftimes = 10
            GUICtrlSetData($hList, $sList)
    EndSwitch

WEnd

I also added another check to cover the final found item being on the first line. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

can you share the log file?

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  
Followers 0