Search code examples
.netwindowsc++-cliprivileges

Current Directory as UNC when linked with 'requireAdministrator' privileges?


I recently modified an application by adding to manifest level='requireAdministrator'. From this app I call System::Environment::CurrentDirectory while being in a locally mapped folder. For example, I mapped a X:\ drive to C:\toto. Now that I require admin privileges, I always get the path as an UNC. But I want to have it as the mapped folder like I had before (I want to get X:\ rather than \\MyComputer\C\toto.)

This "new" behaviour leads to bug further in the application. I would like to have the old behaviour and I don't understand why it changed suddenly when I changed the requested privileges.

Note that my UAC is set to 0 (lowest level...). Also, note that System::IO::Directory::GetCurrentDirectory() gives the same result. I'm using Win7SP1.

Any idea? Thanks!


Solution

  • This is by design:

    When UAC is enabled, the system creates two logon sessions at user logon. Both logon sessions are linked to one another. One session represents the user during an elevated session, and the other session where you run under least user rights.

    When drive mappings are created, the system creates symbolic link objects ("DosDevices") that associate the drive letters to the UNC paths. These objects are specific for a logon session and are not shared between logon sessions.

    A end-user could set the EnableLinkedConnections registry value but as a application developer you should fix your bugs instead of changing the system configuration.