Page 1 of 1 1
Topic Options
#158675 - 2006-03-10 02:18 AM How do you call and assign elements to a dynamic array?
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
say i just want to call an empty array at start; one that the number of elements it will hold is relavant to the the number of extra users in the local administrators group. how do i assign all of those excess account names to a that inital array so i can loop through them at the end to get them all on a single line when i write them to an output file?? This is what I've tried thus far.

Code:
$AllowedGroups	= "Administrator","Domain Admins"
$NetworkServer = "\\LogServer"
$NetworkShare = "ScriptLog"
$OutputFile = 'Unauthorized Accounts in local Administrators Group.log'
$handle = 1
$count = 0

Dim $unauthAccounts[]

;Attempt to account for file locking to write to one output file
$ = Open($handle,$NetworkServer+'\'+$NetworkShare+'\'+$OutputFile,5)
While @ERROR = -3 AND $count < 100
$ = Open($handle,$NetworkServer+'\'+$NetworkShare+'\'+$OutputFile,5)
If $handle = 10
$handle = 1
Else
$handle = $handle + 1
Endif
$count = $count + 1
Loop


$objComputer = GetObject("WinNT://"+@WKSTA)
$objComputer.Filter = "Group",""
For Each $objGroup in $objComputer
$Group = GetObject("WinNT://"+@WKSTA+"/"+$objGroup.Name)
If $objGroup.Name = 'Administrators'
For Each $Member in $Group.Members
If AScan($AllowedGroups,$objUser.Name) = -1
$unauthAccounts = $Member.Name
Endif
Next
; just trying to see if i'm even writing the correct info the the temp array
for each $x in $unauthAccounts
? $x
next
;$ = WriteLine($handle,@WKSTA+', '+$objUser.Name+', '+@DATE+', '+@TIME+@CRLF)
Endif
Next


$ = Close($handle)

'done'
get $



now i know i'm doing this wrong but how do you do it?

Top
#158676 - 2006-03-10 03:21 AM Re: How do you call and assign elements to a dynamic array?
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
First Item is that I think you should use FreeFileHandle() instead of looping.: Code:

FreeFileHandle( )

Action: Returns the first available file handle.

Syntax: FreeFileHandle ( )

Parameters: None.

Returns: 0 No file handle available.
> 0 Numeric file handle.

See Also: Open( ), Close( ), ReadLine( ), WriteLine( )

Example: $Handle = FreeFileHandle()
IF $Handle > 0
IF Open($Handle, @LDRIVE + "\CONFIG\SETTINGS.INI") = 0
;………
ENDIF
ENDIF



You should DIM your array as $array[0] (one element)

Then you should use UBound( ) to determine the avaialble subscript of the array.

If you need to add an element use ReDim preserve $Array[Ubound($Array)+1]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#158677 - 2006-03-10 03:48 AM Re: How do you call and assign elements to a dynamic array?
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
You da man Mr. Bullock. This is how I changed the code based off of your reccomendations. Let me know if this looks better please. I'm only asking because I like to code efficiently. Thanx again Mr. Bullock.

Code:
$AllowedGroups	= "Administrator",Domain Admins"

$NetworkServer = "\\LogServer"
$NetworkShare = "ScriptLog"
$OutputFile = 'Unauthorized Accounts in local Administrators Group.log'
$handle = FreeFileHandle()
$count = 0

Dim $unauthAccounts

$ = Open($handle,$NetworkServer+'\'+$NetworkShare+'\'+$OutputFile,5)
While @ERROR = -3 AND $count < 100
$ = Open($handle,$NetworkServer+'\'+$NetworkShare+'\'+$OutputFile,5)
$count = $count + 1
Loop

$objComputer = GetObject("WinNT://"+@WKSTA)
$objComputer.Filter = "Group",""
For Each $objGroup in $objComputer
$Group = GetObject("WinNT://"+@WKSTA+"/"+$objGroup.Name)
If $objGroup.Name = 'Administrators'
For Each $Member in $Group.Members
If AScan($AllowedGroups,$Member.Name) = -1
ReDim preserve $unauthAccounts[Ubound($unauthAccounts)+1]
$unauthAccounts[ubound($unauthAccounts)] = $Member.Name
Endif
Next
for each $x in $unauthAccounts
? $x
next
;$ = WriteLine($handle,@WKSTA+', '+$objUser.Name+', '+@DATE+', '+@TIME+@CRLF)
Endif
Next


$ = Close($handle)

'done'
get $


Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 871 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.049 seconds in which 0.023 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org