Click here to Skip to main content
15,891,881 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to get Elevated Privileges on windows 7 programatically.
Actually i want to edit hosts file programatically but it gives error Access Denied to path.
Posted

1 solution

You can't - not just like that. If you could, it would kind of defeat the purpose wouldn't it?!

The preferred way is to create a manifest file set to requireAdministrator for your application -

http://stackoverflow.com/questions/4084585/how-to-embed-a-manifest-file-at-compile-time-in-visual-studio-2010[^]

http://stackoverflow.com/questions/2818179/how-to-force-my-net-app-to-run-as-administrator-on-windows-7[^]

Otherwise, you'd still need to perform some sort of imperstonation, which would result in a dialog to retrieve user name \ password credentials with which to perform the impersonation, which is essentially what you're doing with the manifest.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900