You need to use Security.Principal namespace to access WindowsIdentity namespace as
using System.Security.Principal;
and then you can use given function to check application is running in admin account or not.
public static bool isAdm()
{
WindowsIdentity identity = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(identity);
if (!principal.IsInRole(WindowsBuiltInRole.Administrator))
{
return false;
}
else
{
return true;
}
}
In Entry point of your application try to write given code
if (isAdm())
{
// Execute block when isAdmin return true
Application.Run(new Form1());
}
else
{
// Execute block when isAdmin return false
MessageBox.Show("You must run this application as Administrator");
Application.Exit();
}