Question

I cannot work this one out!

Create a VS2010 windows application that just does a FileInfo("Y:/test.txt") and when debugging the FileInfo works fine.

Do exactly the same thing via VS2013 and it reports file not found.

So there is some kind of trust or impersonation issue, this is a windows application though and i'm running VS2013 as administrator.

It's driving me nuts - anyone got any ideas?

thanks Paul

Was it helpful?

Solution

When UAC is enabled in Windows and you are a member of the Administrators group, you actually end up with two logon sessions - one as a regular user and one as an administrator. Your mapped drives are only associated with your regular user logon session, so when you run a program as administrator it does not see the mapped drives.

This link provides more details and a work-around (that I haven't tried myself!) that involves changing the registry:

To work around this problem, configure the EnableLinkedConnections registry value. This value enables Windows Vista and Windows 7 to share network connections between the filtered access token and the full administrator access token for a member of the Administrators group. After you configure this registry value, LSA checks whether there is another access token that is associated with the current user session if a network resource is mapped to an access token. If LSA determines that there is a linked access token, it adds the network share to the linked location. To configure the EnableLinkedConnections registry value

  1. Click Start, type regedit in the Start programs and files box, and then press ENTER.

  2. Locate and then right-click the registry subkey HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System.

  3. Point to New, and then click DWORD Value.

  4. Type EnableLinkedConnections, and then press ENTER.

  5. Right-click EnableLinkedConnections, and then click Modify.

  6. In the Value data box, type 1, and then click OK.

  7. Exit Registry Editor, and then restart the computer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top