How to run application as administrator in debug with Visual Studio?

I have a c# application where I have to have read/write access to the root of the C drive. I realize I can compile the code and run the executable as administrator and it works. But I need to debug it and I am unsure as to how one would start the app within Visual Studio.

I have tried adding:

<requestedExecutionLevel level="asInvoker" uiAccess="true" />

to my manifest but I still get access denied error.

Here is the line of code that fails:

MemoryMappedFile mmf = MemoryMappedFile.CreateFromFile(@"c:\somemapnamefile.data", System.IO.FileMode.OpenOrCreate, "somemapname", 1000);

For now I have a work around but I'd like to know for the future.


Just run visual studio itself as an administrator. Any program you debug from there will also be run as an administrator.


VS must be run with admin right. however, a more elegant way is in the requiredExecutionLevel in manifest should set to 'requireAdministrator'.

<requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />

When you open the project and try to debug, the VS2012 will warn about the admin right and restart itself to admin right. And also the exe file will be marked as requiring admin right at the first place therefore when deploy you don't need to configure admin right requirement in file properties.