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 1000107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:27:33+00:00 2026-05-16T07:27:33+00:00

It seems like the elevation of privileges is a common thing most developers fight

  • 0

It seems like the elevation of privileges is a common thing most developers fight with as most of the time they simply do not have it. I for one do but am fighting with a massive Background Worker routine and I’m trying to keep my code local to the class that will be employing it. Given the amount of code and references my background worker makes once it finishes inside the ‘RunWorkerCompleted’ handler method its proving diffcult to accept this as a viable alternative:

HOMEWORK 1:

HOMEWORK 2:

HOMEWORK 3:

There is simply too much dependence on my MainForm class by my Background Worker for me to consider shipping out the entire solution into a seperate process with ‘Admin’ privs. This involves far too much chopping and changing.

Omega Coder:

Having read into CAS for the 70-536 exam, I am aware of most of the terms in this above example but I failed to see how and why it works? Could someone please explain why the permission is granted to ‘ManagersOnly’ method? As once the PrincipalPolicy is changed to WindowsPrincipal, the next two steps look like ordinary object instantiation statements as posed to something like:

System.AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal, IPrincipal, IIdentity);

Obviously, no such overload exists, but its very clear in what that overload does.

Question 1: How does OmegaCoders example achieve this effect? Because it definately works as my user is part of the ‘BUILTIN\Administrators’ group. I’m looking for a literature based answer so go to as much detail as you feel.

UPDATE 1:

Question 2: How would I revert the PrincipalPolicy back to what it was before … once the method returns I do not need the PrincipalPolicy still being set to ‘WindowsPrincipal’??? So that application can carry on running as a lower privileged user as I intended.

Question 3: Once the ‘ManagersOnly’ method returns, is the permission discarded? Is it scoped to the life of the Method?

System.AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.NoPrincipal);

*UPDATE 2: *

This is proving difficult, as on my Win7 Pro dev machine I can test and run anything but when I tried testing out some code on a simple Win7 Home laptop I found out that permissions were being denied. Which begs the questions changing the PrincipalPolicy to ‘WindowsPrincipal’ does not work for all vista and Win7 users as many wont even be part of the admin user group. So this option is useless… Sitting on this small laptop its becoming pretty obvious that is not the solution I need.

IGNORE PREVIOUS Qs – with my own researh I have done they are not feasible.

Question 4: how does one go about impersonating an administrator programmatically and temporarilly in code?

  • 1 1 Answer
  • 3 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-16T07:27:33+00:00Added an answer on May 16, 2026 at 7:27 am

    The short answer is NO.

    It seems like after all the digging round I have been doing there does not seem to be a progromattic way of elevating a method’s permissions as CAS compliments RBS so if the user is not part of the right group. Then there is no point is even accessing for admin rights as rbs tells cas that the user is not part of the group so the request is bounced and permission is denied. Resulting in an exception.

    If the user is part of the group you need i.e Administrators, then changing the Domains PrincipalPolicy will give you a temprary solution but it does not cater for users that are simply not part of the admin user groups. Thats where the above solution falls apart.

    The long answer is, ship out the problem prone code into a small seperate .exe file and run it seperately.

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

Sidebar

Related Questions

Seems like this is the kind of thing that would have already been answered
Seems like we could just have a normal statically checked assignment. I'm not sure
Seems like this would be a common question, though I could not find it
Seems like this should be a simple thing to do, but the date/time operations
Seems like i need some help with a project. I have a routine ,
Seems like in Perl this should be easy or a module, but I have
Seems like tooltips that you get from attribute title=test are not displayed inside the
Seems like I'd be able to find this, but can't turn up anything. Have
Seems like I may have missed something simple in the syntax, but I'd like
Seems like everyone always ignores the time part, but how would you compare two

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.