Project: Security.Is.Running.As.Administrator



Check if the application is running by a user that is in the administrators role:
void Main()
{
	IsRunningAsAdmin().Dump();	
}

private bool IsRunningAsAdmin()
{
	var isAdmin = false;
	var currentIdentity = WindowsIdentity.GetCurrent();
	
	if (currentIdentity != null)
	{
		WindowsPrincipal pricipal = new WindowsPrincipal(currentIdentity);
		isAdmin = pricipal.IsInRole(WindowsBuiltInRole.Administrator);
		pricipal = null;
	}
	
	return isAdmin;
}

Last edited Apr 8, 2012 at 8:19 PM by teoarch, version 1

Comments

No comments yet.