Hi guys,
I can get user and computer name from Environ,
How can i get Current user NT group?![]()
(Environ$("Username")) (Environ$("Computername"))
Thanks,
Hi guys,
I can get user and computer name from Environ,
How can i get Current user NT group?![]()
(Environ$("Username")) (Environ$("Computername"))
Thanks,
What do you wish when a user is member of many groups (this is usually the case!)?
No, i want something like this
example:
user 1 belongs to IT
user 2 belongs to marketing
user 3 belongs to production
when i get the username i want to have another field with the group.
I do not think you understood. A user often belongs to more than one group in Active Directory. In such a case what must the code return?
i want get the group of each user.
I try one more time. Imagine you have user named Ricardo. He may belong to many NT Groups - All users; Marketing; European colleagues; Systems Committee et cetera. What must the function return as answer?
If he belongs to marketing i want get marketing as his group
And how will the code know that you want Marketing as the answer and not one of the other groups? What is the logic?
That will return all the groups the user is part of to the Usr_groups object variable. I think that normally you would then test if a user is part of a certain group, rather than return which group the user is part of. As Izandol says you would normally be a member of many groups, for example, when I run that on my machine Usr_groups has 13 different items.![]()
Sub macro_groups() Dim objNetwork, objUser, Usr_groups Set objNetwork = CreateObject("WScript.Network") strUsername = objNetwork.UserDomain & "/" & objNetwork.Username strUsername = Replace(strUsername, "\", "/") Set objUser = GetObject("WinNT://" & strUsername & ",user") Set Usr_groups = objUser.groups End Sub
Thanks all,
my finish code
![]()
Dim objNetwork, strDomain, strUser, objUser, objGroup, strGroupMemberships Set objNetwork = CreateObject("WScript.Network") strDomain = objNetwork.UserDomain strUser = objNetwork.Username Set objUser = GetObject("WinNT://" & strDomain & "/" & strUser) For Each objGroup In objUser.Groups strGroupMemberships = strGroupMemberships & objGroup.Name & "," Next MsgBox strGroupMemberships
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks