Question

I'm developing windows explorer namespace extension. My application is a dynamic library loaded and used by explorer.exe at some time. I need my DLL to create files in C:\ and sometimes in other locations which need elevation to perform such operations.

How can I perform such elevation and create file at C:\ for example ?

Was it helpful?

Solution

If your code runs inside another process it is at the mercy of the elevation state of that process. If that process does not run elevated, and explorer does not, then your code in your DLL cannot execute elevated.

Your solution therefore is to create another process to perform the tasks which require elevation. Do that using one of these methods:

  • Specify the requireAdministrator option for requestedExecutionLevel in the application manifest.
  • Start the process using ShellExecuteEx with the runas verb.
  • Put the code to be elevated in a COM object and use the COM elevation moniker.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top