How to give ArcMap add-ins temporary elevated priviledges?

Discussion created by Me2 on Apr 10, 2014

Thanks for your interest.

Is there an easy way within an ArcMap add-in (built with VB.NET) to have users give Windows elevated rights to the add-in/ArcMap so that it can create a subfolder and copy a file into that subfolder?

I have an ArcMap extension that requires a keycode. The application was initiated many years ago when Windows UAC (User Account Control) and ArcMap add-ins didn't exist. So, when a keycode would be discovered in the user "My Documents" folder, the extension would move it to a final location that was accessible by all users of a PC; somewhere in the Windows recommended location at the time: C:\ProgramData\...

Since Windows VISTA and UAC, this folder is a protected folder and Windows requires processes to gain elevated rights/permission to create a subfolder and copy the keycode there.

This can be achieved by having users start ArcMap with elevated rights (ArcMap icon > Run as administrator). Yet, as many of us don't read registration instructions, this has been an issue. I have kept this legacy setup so far as I don't want to confuse my existing customers. I could of course have each user of a PC (or Citrix server) save the key into a folder owned by that user. But before making any decision, I would like to know if it's possible easily bring up the Windows UAC dialog from within my add-in to gain elevated privileges punctually when needed.

From my quick research, it appears that after asking for credentials, one could:
- Force ArcMap to restart with elevated rights
- Make Win32 elevated calls to create the folders and then copy the keycode file.

Any easier and faster .NET managed solution?