This one is "inspired" from http://www.oreillynet.com/windows/bl...groups_of.html
c# Code:
using System;
using System.Linq;
using System.Security.Principal;
using System.Collections.Generic;
namespace CheckWindowsSecurityGroup
{
class FindGroups
{
static void Main(string[] args)
{
var myGroups = GetWindowGroupsFromToken();
foreach (var myGroup in myGroups)
{
Console.WriteLine(myGroup);
}
}
private static IEnumerable<string> GetWindowGroupsFromToken()
{
var id = WindowsIdentity.GetCurrent();
if (id == null)
{
return null;
}
else
{
if (id.Groups != null)
{
var irc = id.Groups.Translate(typeof (NTAccount));
return (from NTAccount acc in irc select acc.Value.ToUpper()).ToList();
}
}
}
}
}