Jump to content
Sign in to follow this  

My get workgroups in arry script

Recommended Posts


I havn't programmed for a long time, but mayby i am dumb as well, anyway I need help with this

I am writing a script that should put my workgrops in array, so I end up with all named workgroups in my network

from my debug line

the 1st time my loop is run array 0 is empty and array 1 is the first finding of my stdoutread,

if I click ok the rest of my workgroups get in array 2, and frem there on every time i click ok there is a new array created with nothing

the script goes on until i terminate it, which mean i am stuck in my loop for some reason.

Here is my scrip:


$test = WG()

_ArrayDisplay( $test, "Workgroups" ) ; LIST WORKGROUPS

Func WG()

;$run = Run(@ComSpec & " /c net view /domain", @SystemDir, @SW_HIDE, 2 + 4) ; Run the command that finds the list of workgroups

$run = Run(@ComSpec & " /c FIND_WG.CMD ","c:\", @SW_HIDE, 2 + 4)

local $workgroups[1] ; Create the array for the workgroups

While not @error

$line = StdoutRead($run) ; Read every Line

_ArrayAdd( $workgroups, $line) ; add the line to the array of found workgroups

_ArrayDisplay( $workgroups, "Workgroups(DEBUG)" ) ;debugger



return $workgroups


and here is my cmd file I call from the script (FIND_WG.CMD)

@echo off

net view /domain | findstr . | find /v "---" | find /v "dom"

this script filters out the stuff I don't need in my stdoutread (when I use it dirictly in the script is goes heywire because of all the quotes, so this was a simple work around, but thats an other storry)

my workgroup array is never returned, because I am stuck in the loop, and the output from the "debugger" line is not quite what expected.

what I want is:

[0] = workgroup 1

[1] = workgroup 2

etz, etz.

I thaught whis would be simple, man I was wrong?!?

any help is appriciated, hope to hear from an array expert

Best Regards Mimo

Share this post

Link to post
Share on other sites

HA Got it, it was just a question of getting the correct way out of the loop.

Life is nice again :whistle:

This will put all your workgroups in an array.

The cmd was skipped so nothing else needed to run this

if anyone has some use for this feel free to use it

#include <array.au3>

$workgroups = domains()

$workgroups_count = UBound($workgroups) ;

MsgBox(0, "number of workgroups found:", $workgroups_count)

_ArrayDisplay($workgroups , "LIST OF WORKGROUPS:")

func domains()

$command = ' /c net view /domain | findstr . | find /v "---" | find /v "dom" | find /v "Command" '

$foo = Run(@ComSpec & $command, @workingdir, @SW_HIDE, 2)

local $array[1]

while 1

$line = StdoutRead($foo)

If @error Then ExitLoop

_ArrayAdd( $array, $line)


_ArrayDelete( $Array,0)

return $array


plz Give me feedback what you think about it, things can always get better...

Best Regards Mimo

Share this post

Link to post
Share on other sites

This allmost qualifys for spam, but my script is still in trouble.

Sometimes 2 or more workgroups are in the same array, like it jumps over a newline and reads on.

like this

0 = workgroup1

1 = workgroup2


2 = workgroup4

anyone help here?

suggestions, tips anything


Best Regards Mimo

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