Thursday, January 27, 2011

VBS - Find if logged on user is member of group

This script finds out if the logged on user is a member of a group. This is very handy for logon scripts.

' Find the user logged in
Set WSHShell = CreateObject("WScript.Shell")
UserLoggedIn = WshShell.ExpandEnvironmentStrings("%username%")

'Run the functions if the user is a member of the group
Set oGroup = getobject("WinNT://kbomb.local/" & "Domain Admins")
For Each oMember in oGroup.Members
If lcase(oMember.Name) = lcase(UserLoggedIn) Then
RunRegModifications()
RunFileModifications()
End If
Next

Function RunRegModifications()
wscript.echo "reg modification code here"
End Function

Function RunFileModifications()
wscript.echo "file modification code here"
End Function

2 comments:

  1. Thanks for sharing your info. I really appreciate your efforts and I will be waiting for your further write ups thanks once again.

    ReplyDelete
  2. nice, finding out if one is a member of a group can be pretty convenient
    thanks, Clint

    ReplyDelete