Users and Groups 
Author Message
 Users and Groups

I'm quite new to VB Script, so pardon me. I need to write a script that
checks for a given user on a NT 4 Domain and lists all of the groups that
the user is associated with. I need this script for NT 4 Server &
Workstation. I've tried using ADSI but it does not seem to work. If there is
any one out there who can help me, please do. Thanks

DM O'Toole



Sun, 04 Mar 2001 03:00:00 GMT  
 Users and Groups
strDomain="MACHINENAME"
strUser="jdoe"

Set oUser = GetObject("WinNT://" & strDomain & "/" & strUser)
set oGroups = oUser.Groups

For Each Group In oGroups
list = list & Group.Name
next

oUser=Nothing
oGroup=Nothing

msgbox list

That should work. I also have a script on my site that should do the trick.

--
Check it out
http://cwashington.netreach.net

Win32 bit scripting, lots of sample scripts, downloads,
reference files, and technical support via an online discussion forum.


Quote:
>I'm quite new to VB Script, so pardon me. I need to write a script that
>checks for a given user on a NT 4 Domain and lists all of the groups that
>the user is associated with. I need this script for NT 4 Server &
>Workstation. I've tried using ADSI but it does not seem to work. If there
is
>any one out there who can help me, please do. Thanks

>DM O'Toole



Sun, 04 Mar 2001 03:00:00 GMT  
 Users and Groups
Thanks Clarence, but I have already tried that, it seems that, at least on
NT 4, the oUser.Groups attribute is not there. When running the script I get
a runtime error saying
Variable not set,
Using debugging code I have come to the above conclusion that the .groups
attibute is not available.

Thank you for your time

Quote:

>strDomain="MACHINENAME"
>strUser="jdoe"

>Set oUser = GetObject("WinNT://" & strDomain & "/" & strUser)
>set oGroups = oUser.Groups

>For Each Group In oGroups
>list = list & Group.Name
>next

>oUser=Nothing
>oGroup=Nothing

>msgbox list

>That should work. I also have a script on my site that should do the trick.

>--
>Check it out
>http://cwashington.netreach.net

>Win32 bit scripting, lots of sample scripts, downloads,
>reference files, and technical support via an online discussion forum.



>>I'm quite new to VB Script, so pardon me. I need to write a script that
>>checks for a given user on a NT 4 Domain and lists all of the groups that
>>the user is associated with. I need this script for NT 4 Server &
>>Workstation. I've tried using ADSI but it does not seem to work. If there
>is
>>any one out there who can help me, please do. Thanks

>>DM O'Toole



Sun, 04 Mar 2001 03:00:00 GMT  
 Users and Groups
That exact same code works fine for me on my machine. NT Workstation SP3. No
problems

--
Check it out
http://cwashington.netreach.net

Win32 bit scripting, lots of sample scripts, downloads,
reference files, and technical support via an online discussion forum.

Quote:

>strDomain="MACHINENAME"
>strUser="jdoe"

>Set oUser = GetObject("WinNT://" & strDomain & "/" & strUser)
>set oGroups = oUser.Groups

>For Each Group In oGroups
>list = list & Group.Name
>next

>oUser=Nothing
>oGroup=Nothing

>msgbox list

>That should work. I also have a script on my site that should do the trick.

>--
>Check it out
>http://cwashington.netreach.net

>Win32 bit scripting, lots of sample scripts, downloads,
>reference files, and technical support via an online discussion forum.



>>I'm quite new to VB Script, so pardon me. I need to write a script that
>>checks for a given user on a NT 4 Domain and lists all of the groups that
>>the user is associated with. I need this script for NT 4 Server &
>>Workstation. I've tried using ADSI but it does not seem to work. If there
>is
>>any one out there who can help me, please do. Thanks

>>DM O'Toole



Sun, 04 Mar 2001 03:00:00 GMT  
 Users and Groups
I presume you have ADSI v2 not v1. Try this...
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WSHNetwork = WScript.CreateObject("WScript.Network")
While strUser = ""
  strUser = WSHNetwork.UserName
Wend
strDomain = "MyDomain"

Set oADSI= GetObject("WinNT://" & strDomain & "/" & strUser)
For Each Group In oADSI.groups
  Select Case Group.Name
   Case "Domain Admins"
    WshShell.popup "Domain Administrator"
   Case "UserGroup1"
    WshShell.popup "User Group 1"
 End Select

This is exactly how my logon script runs. Full sample is on my web site.
Regards,
Ian Morrish
http://wsh.glazier.co.nz WSHFAQ
http://ils.glazier.co.nz (NetMeeting)
http://www.glazier.co.nz

Quote:

>Thanks Clarence, but I have already tried that, it seems that, at least on
>NT 4, the oUser.Groups attribute is not there. When running the script I
get
>a runtime error saying
>Variable not set,
>Using debugging code I have come to the above conclusion that the .groups
>attibute is not available.

>Thank you for your time


>>strDomain="MACHINENAME"
>>strUser="jdoe"

>>Set oUser = GetObject("WinNT://" & strDomain & "/" & strUser)
>>set oGroups = oUser.Groups

>>For Each Group In oGroups
>>list = list & Group.Name
>>next

>>oUser=Nothing
>>oGroup=Nothing

>>msgbox list

>>That should work. I also have a script on my site that should do the
trick.

>>--
>>Check it out
>>http://cwashington.netreach.net

>>Win32 bit scripting, lots of sample scripts, downloads,
>>reference files, and technical support via an online discussion forum.



>>>I'm quite new to VB Script, so pardon me. I need to write a script that
>>>checks for a given user on a NT 4 Domain and lists all of the groups that
>>>the user is associated with. I need this script for NT 4 Server &
>>>Workstation. I've tried using ADSI but it does not seem to work. If there
>>is
>>>any one out there who can help me, please do. Thanks

>>>DM O'Toole



Mon, 05 Mar 2001 03:00:00 GMT  
 Users and Groups
Tried it and still does not work. (sigh) What is the problem? I am running
the script on a Windows NT4 workstation with Service Pack 3, ADSI 2, and WSH
installed. The workstation is running of a NT4 Server with SP3 installed as
well. Can some one please tell me what I'm doing wrong. Ian, I copied you
script and just substituted the domain and user names with my own. It ran
and nothing happend. It did not crash, it just exited. The oADSI object is
being created because if I add the line
msgbox oADIS.FullName
It comes back with the full name of the user, I just can't get at the
oADSI.groups attribute. This is quite frustrating.
Thanks for your help.
Quote:

>I presume you have ADSI v2 not v1. Try this...
>Set WshShell = WScript.CreateObject("WScript.Shell")
>Set WSHNetwork = WScript.CreateObject("WScript.Network")
>While strUser = ""
>  strUser = WSHNetwork.UserName
>Wend
>strDomain = "MyDomain"

>Set oADSI= GetObject("WinNT://" & strDomain & "/" & strUser)
>For Each Group In oADSI.groups
>  Select Case Group.Name
>   Case "Domain Admins"
>    WshShell.popup "Domain Administrator"
>   Case "UserGroup1"
>    WshShell.popup "User Group 1"
> End Select



Mon, 05 Mar 2001 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Enumerate users and groups that belong to a group

2. Adding multiple users or groups to local groups

3. Is User in Group? Add/Delete user from group?

4. Domain User and Group Creation

5. "add users and groups" interface

6. "add users and groups" interface

7. Add User to Group on Computers

8. HELP: (ASP VBscript) adding user to group not responding

9. if folder exist, add user into group at active directory by vbscript

10. Add USERS local group to drive c:\ with all permissions

11. Add User to group

12. Removing user from group

 

 
Powered by phpBB® Forum Software