Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check whether user is in user group

Status
Not open for further replies.

arst06d

Programmer
Joined
Nov 29, 2002
Messages
324
Hi
I need a script, runnable by all users, to simply display a list of all user groups they are a member of. Here's what I have been playing with so far:

Code:
Dim X
set X = createobject("WSCRIPT.Network")
dim U
U=x.UserName
MsgBox "Logged In User is: " & U

Set objNetwork = CreateObject("WScript.Network")
sDomain = objNetwork.UserDomain
MsgBox "sDomain: " & sDomain
sUser = objNetwork.UserName
MsgBox "sUser: " & sUser
'Set oUser = GetObject("WinNt://" & sDomain & "/" & sUser & ",user")
set oUser = GetObject("WinNT://" & sDomain & "/" & strUser)
MsgBox oUser
dim sGroups
For Each oGroup In oUser.Groups
	sGroups = sGroups & oGroup.Name & vbcrlf
	'End if
Next

MsgBox sGroups

I get displayed the userid & the domain but it throws an error on the GetObject line:
Code:
Script:     h:\getcurrentuser.vbs
Line:       13
Char:       1
Error:      0x80005000
Code:       80005000
Source:     (null)

It will be run on XP machines.

Can anyone shed any light on this, or suggest a different approach?

Thanks

 
curiouser and curiouser ...

the following runs OK:

Code:
dim objNetwork
dim sDomain, sGroup, sUser
dim objGroup, objUser
dim bMember


Set objNetwork = CreateObject("WScript.Network")
sDomain = objNetwork.UserDomain
MsgBox "sDomain: " & sDomain
sUser = objNetwork.UserName
MsgBox "sUser: " & sUser


set objUser = GetObject("WinNT://" & sDomain & "/" & sUser)

for each oGroup in objUser.Groups
	sGroups = sGroups & oGroup.Name & vbcrlf
Next

msgbox sGroups
 
>curiouser and curiouser ...
Why do you say it is curious? [1] Your first script strUser is not defined. [2] Your commented line with WinNt:// is incorrect as it is case sensitive (WinNT://). [3] You have msgbox oUser. You have to be more precise on which property you want to show. Or I miss something!
 
OK - you got me. I'm an idiot.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top