Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6622201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:22:34+00:00 2026-05-25T21:22:34+00:00

How to check is my application starts with admin rights? I use this code

  • 0

How to check is my application starts with admin rights? I use this code now:

public static bool IsUserAdministrator()
        {
            //bool value to hold our return value
            bool isAdmin;
            try
            {
                //get the currently logged in user
                WindowsIdentity user = WindowsIdentity.GetCurrent();
                WindowsPrincipal principal = new WindowsPrincipal(user);
                isAdmin = principal.IsInRole(WindowsBuiltInRole.Administrator);
            }
            catch (UnauthorizedAccessException ex)
            {
                isAdmin = false;
            }
            catch (Exception ex)
            {
                isAdmin = false;
            }
            return isAdmin;
        }

This code checks user rights, I need to check the rights that application has. For example, I’m not the administrator but when the application starts with admin rights this code returns false. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:22:34+00:00Added an answer on May 25, 2026 at 9:22 pm

    That’s the correct approach to performing the check, I use it myself in my PowerShell profile to distinguish elevated sessions.

    I suspect you’re not taking into account the effect of User Access Control (UAC). When a user logs in they get a security token object allocated. This contains both their own security id (SID), the SIDs of groups they belong to and a list of privileges they have (and whether those privileges are enabled).

    With UAC enabled, when you do an interactive login if you have certain privileges or are a member of the local administrators you get two tokens: one with everything and a second with administrative access SIDs and privileges removed. The latter token is used with each launched process, unless launched elevated when the former token is used.

    Thus an administrator cannot exercise their full power without an extra step – this helps prevent malware from being started with full control of the system.

    The best tool for seeing this in action is Process Explorer. The Security tab of the process properties dialogue shows the contents of the process’s security token (and adding the "Integrity Level" column to the main display will show what processes are elevated) – run Process Explorer elevated to see the full information.

    So your code will only return true for a process run by an administrator that is also elevated (run as administrator).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to check memory performance of my application, I have solved Leaks now
If my application starts, I check first if there is already an instance of
I would like check the device WiFi connection availability while my application starts. So
When an MFC application starts, is it possible to check for the Visual C++
I was trying to run my application and check for some output on the
I have a Inno Setup project that I want to check if the application
t-sql, sql server 2008 My application must check connection status to database every 5
If Java application requires certain JRE version then how can I check its availability
I'm doing a check in an iPhone application - int var; if (var !=
I have an application that needs to check a website feed every second. Sometimes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.