Windows Groups and VBScript

Someone at work recently came up to me and asked if I would write up a quick VBScript file to display in a message box the list of Windows Groups a user is assigned to if the user ran it locally. This is what I came up with:

Dim WshShell, objDomain, objUserName, list, oGroup

Set WshShell = WScript.CreateObject("WScript.Shell")

objDomain = WshShell.ExpandEnvironmentStrings("%USERDOMAIN%")
objUserName = WshShell.ExpandEnvironmentStrings("%USERNAME%")

Set objUser = GetObject("WinNT://" & objDomain & "/" & objUserName & "")

On Error Resume Next
list = objUserName & " belongs to the following groups:" & vbCrLf & vbCrLf
For Each oGroup In objUser.Groups
list = list & vbCrLf & oGroup.Name
Next
Set WshShell = Nothing
MsgBox list


Related posts

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

December 5. 2008 03:53 AM

Twitter

    Search

    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2008