#include "stdafx.h"
using namespace System;
using namespace System::Security;
using namespace System::Security::Principal;
using namespace System::Threading;
void main()
{
AppDomain::CurrentDomain->SetPrincipalPolicy(PrincipalPolicy::WindowsPrincipal);
WindowsPrincipal ^wPrinc = (WindowsPrincipal^)Thread::CurrentPrincipal;
Console::WriteLine("Is an Administrator?: {0}", wPrinc->IsInRole(WindowsBuiltInRole::Administrator));
Console::WriteLine("Is a Hacker?: {0}", wPrinc->IsInRole("Hacker"));
WindowsIdentity ^wIdent = (WindowsIdentity^)wPrinc->Identity;
array<String^>^ rolesArray = {"Hacker"};
Thread::CurrentPrincipal = gcnew GenericPrincipal(gcnew GenericIdentity("John Doe"), rolesArray);
GenericPrincipal ^gPrinc = (GenericPrincipal^)Thread::CurrentPrincipal;
Console::WriteLine("Is an Administrator?: {0}",
gPrinc->IsInRole("BUILTIN\\Administrator"));
Console::WriteLine("Is a Hacker?: {0}", gPrinc->IsInRole("Hacker"));
GenericIdentity ^gIdent = (GenericIdentity^)gPrinc->Identity;
Console::WriteLine("\nUser Name: {0}", gIdent->Name);
Console::WriteLine("Is Authenticated: {0}\n", gIdent->IsAuthenticated);
}
|