Testing if a user exists in a domain 
Author Message
 Testing if a user exists in a domain

Hi,

I need to test if a username already exists within a domain as part of a
user management script I am writing. At the moment, I am doing it with a
code snippet like this one:
.....
Dim objDomain ' an ADSI domain object, initialised elsewhere in my code
Dim objUser ' an ADSI user object
Dim blnExists ' does the user exist?

blnExists = False
objDomain.Filter = Array("user")
for each objUser in objDomain
  wscript.echo objUser.name
  if objUser.name = strUsername then blnExists = True : exit for
  next
.....
So, if the user exists, blnExists will be True. However, this method means
that in the worst case I have to enumerate the entire list of domain users
in order to find out if just one user exists, which seems less than
efficient. :)

Is there a way I can quickly test for the existance of just one user in the
domain? (Something rather than "user" as the filter, maybe?)

Thanks,
Zack
--

User Support Officer
Lancaster City Council, UK



Fri, 18 May 2001 03:00:00 GMT  
 Testing if a user exists in a domain

This depends on how many users you will be looking for. If you are checking for just one user the method you use is fine. If you will need to check for the existence of several users I would enumerate the domain collection and place the results in an array. Then filter the array for searches.
Check it out
http://cwashington.netreach.net

Win32 bit scripting. Everything you need to get up and running,
A script repository containing almost 100 sample scripts,
downloads, reference files, and technical support via an
online discussion forum.

(Pursuant to US Code, Title 47, Chapter 5, Subchapter II, 227, any and all
unsolicited commercial E-mail sent to this address is subject to a download
and archival fee in the amount of $1000 US.  E-mailing denotes acceptance of
these terms.)

Hi,

I need to test if a username already exists within a domain as part of a
user management script I am writing. At the moment, I am doing it with a
code snippet like this one:
.....
Dim objDomain ' an ADSI domain object, initialised elsewhere in my code
Dim objUser ' an ADSI user object
Dim blnExists ' does the user exist?

blnExists = False
objDomain.Filter = Array("user")
for each objUser in objDomain
  wscript.echo objUser.name
  if objUser.name = strUsername then blnExists = True : exit for
  next
.....
So, if the user exists, blnExists will be True. However, this method means
that in the worst case I have to enumerate the entire list of domain users
in order to find out if just one user exists, which seems less than
efficient. :)

Is there a way I can quickly test for the existance of just one user in the
domain? (Something rather than "user" as the filter, maybe?)

Thanks,
Zack
--

User Support Officer
Lancaster City Council, UK



Fri, 18 May 2001 03:00:00 GMT  
 Testing if a user exists in a domain

Quote:
Clarence Washington Jr. writes:
> If you are checking for just one user the method you use is fine.
[but...]
> If you will need to check for the existence of several users I would
> enumerate the domain collection and place the results in an array.
> Then filter the array for searches.

Surely that's what I _am_ doing? I was looking for an alternative so I
didn't have the overhead of pulling all the objects into an array - after
all I'm only interested in ONE of the objects.

Zack



Sat, 19 May 2001 03:00:00 GMT  
 Testing if a user exists in a domain

Quote:
>Surely that's what I _am_ doing?

Man!!??.... Sorry if I insulted you.... That wasn't the intent.... People with a variety of experience post to the newsgroup. You can't take anything for granted...

The only OTHER way that I know of, aside from using ADO which would be MORE of a headache, is to attempt to create the user and if you receive an error perform an alternate task.

Set Domain = GetObject("WinNT://your_domain")

on error resume next
Set NewUser = Domain.Create("user",UserNameVar)
NewUser.SetInfo

If err.number <> 0 then
    'The user exist do something here
else
    'The user does not exist, chug along
End If

Clarence

Quote:

Clarence Washington Jr. writes:
> If you are checking for just one user the method you use is fine.
[but...]
> If you will need to check for the existence of several users I would
> enumerate the domain collection and place the results in an array.
> Then filter the array for searches.

Surely that's what I _am_ doing? I was looking for an alternative so I
didn't have the overhead of pulling all the objects into an array - after
all I'm only interested in ONE of the objects.

Zack



Sat, 19 May 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Test if a user exists in a domain through script

2. How to check if a user account exists in a Domain

3. Add and remove existing users to-from existing groups

4. How to track a user session when user leaves my domain

5. How to track a user when user leaves my domain

6. Getting full list of Domain Users is not working properly - some users missing

7. Add Domain Users Group to Powe Users Group in Script

8. Getting full list of Domain Users is not working properly - some users missing

9. Does an enhanced public domain postscript interpreter exist ?

10. Test if window already exists?

11. Testing if a function exists

12. how to test if an address .html exist ?

 

 
Powered by phpBB® Forum Software