Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
137 views
in Technique[技术] by (71.8m points)

Lists in VBScript

I'm trying to create a simple list in a VBscript, but I'm unable to find something similar.

Basically, I'm working on Active directory, and I need to get all the groups a user is a member of for all the users within a domain. Now, every user might be a member of a different number of groups, so I plan to use a dictionary, with the key being the SAMID for the user, and the value being a list of all the groups he/she is a member of.

I can do this with a static array, but then I have to declare a random large size for the array which is not nice. What I would ideally like to do is have a python-like list, where I can simple do something like myList.Add and don't have to worry about sizing.

I tried using System.Collection.ArrayList, but I get an error when I run it:

PS C:mp> cscript.exe .foo.vbs
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.

C:mpfoo.vbs(1, 1) (null): 0x80131700

how can I accomplish this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Get rid of the dictionary and unleash the power of an ArrayList.

Option Explicit

dim list
Set list = CreateObject("System.Collections.ArrayList")
list.Add "Banana"
list.Add "Apple"
list.Add "Pear"

list.Sort
list.Reverse

wscript.echo list.Count                 ' --> 3
wscript.echo list.Item(0)               ' --> Pear
wscript.echo list.IndexOf("Apple", 0)   ' --> 2
wscript.echo join(list.ToArray(), ", ") ' --> Pear, Banana, Apple

EDIT: I see you already tried the ArrayList, but got an error. It seems your installation of the dotnet framework is not correct (System.Collections.ArrayList is part of that). Microsoft has an article about how to solve that: http://answers.microsoft.com/en-us/windows/forum/windows_7-performance/error-code-0x80131700/3add8d80-00e0-4355-a994-8630d01c18f5


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...