Jump to content
Sign in to follow this  
kevinward13

Array Question

Recommended Posts

kevinward13

Current code....not all of it mind you

$x = 1 to $FileList[0]
     $t = FileGetTime("\\" & $Wname & "\C$\Documents And Settings\" & $FileList[$x], 0)
     $varTimeStamp = $t[0] & "/" & $t[1] & "/" & $t[2] & " " & $t[3] & ":" & $t[4] & ":" & $t[5]

     $varTimeDifference = _DateDiff ("D", $varTimeStamp, _NowCalc())
     MsgBox (0, "Time Difference", "It's been " & $varTimeDifference & ' days since the profile "' & $FileList[$x] & '" was last accessed.')

        If $FileList[$x] = 'Administrator' Then
            Sleep(100)
        ElseIf $FileList[$x] = 'localservice' Then
            Sleep(100)
        ElseIf $FileList[$x] = 'networkservice' Then
            Sleep(100)

When the script cycles through the array and get it gets to the point of the Administrator, if i added the line, _ArrayDelete($FileList, $x) it would remove the entry from the array correct?

Share this post


Link to post
Share on other sites
water

If you loop through an array while removing entries it is best to do it from the end to the beginning:

For $x = $FileList[0] to 1 Step -1
    ; Here goes your code
Next

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
kevinward13

woo! that worked perfectly!

Now, on to a second issue with arrays and strings..

With the above code it go through and checks for the administrator account and local service and then removes those from the array.

However we have admin accounts that are needing to be ignored and removed from the array as well. Only thing is that i dont want to enter in ALL the account names.

But we do have an easy way to determine which are admin and which arent. Our admin accounts have an extra set to chars at the end of the user names. so for example (imanadmin-adm)

How would i get the code to see the -adm and then remove that entire entry out of the array?

would i use stringinstr? or something else?

Share this post


Link to post
Share on other sites
monoscout999

Sorry i don`t get the entire context, but maybe something like this

For $i = 0 to Ubound($array) - 1
if stringright($array[$i], 4) = "-adm" then
;your code
Next
Edited by monoscout999

Share this post


Link to post
Share on other sites
kevinward13

ok might need to be more clear. sorry if it was confusing

Above code

If $FileList[$x] = 'Administrator' Then
            _ArrayDelete($FileList, $x)
            Sleep(100)
        ElseIf $FileList[$x] = 'localservice' Then
            Sleep(100)
        ElseIf $FileList[$x] = 'networkservice' Then
            Sleep(100)

What i would like to see is this.

If $FileList[$x] = 'user123-adm' then
            _ArrayDelete($FileList, $x)
            Sleep(100)

But the issue I am running into is that user123 changes between the different administrative accounts. The only constant that will determine the admin account vs the non-admin account is the -adm.

so how would i find the 5, 10, 15, or 50 admin accounts that have -adm on the tail end of them and remove that string from the array? without having to hard code every -adm account name int othe program?

user123-adm

123user-adm

1234567-adm

Share this post


Link to post
Share on other sites
smartee

If StringRight($FileList[$x],4)="-adm" Then..

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  

×