Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Administrator mode in Windows 10

Not really sure of my exact question, but here is the situation:

I have an application (WinForms, C# .Net) that I am developing in Visual Studio 2012. It does a lot of things but the important bit is that it needs to read files from a certain location.

In this case, the location of the files is on a server and my machine has a mapped network drive setup for accessing the files. I can manually navigate to the files with Windows Explorer fine.

I have the following line in my code which is highlighting the issue:

System.IO.File.Exists("X:\\A Folder\\a_file.txt");

And that file does exist in that location. However this is where the problem occurs: if I build the solution and run the .exe directly from the "bin" folder (double-click). The code is fine, and it finds the file. But if I run it with visual studio then I get a "file not found" exception.

I am putting this down to the fact that Visual Studio is running in "Administrator" mode (I forget why I needed this, but I do). Now this makes sense if you consider that the "administrator" account does not have the "X:\" drive mapped. However, this has never been a problem until I upgraded to Windows 10 last week.

So my question is:

Does Visual Studio Administrator mode work differently in Windows 10? In this case, does it handle mapped network drives differently?

It's worth noting I upgraded from Windows 7, so I cannot confirm if this issue is also present in 8 and 8.1 or not.

And before anyone asks, let's just say it has to be a mapped drive. No UNC paths allowed!

like image 814
musefan Avatar asked Sep 16 '15 14:09

musefan


People also ask

Why do I need Visual Studio as administrator?

Without Administrative permissions Visual Studio is not able to write to the hard drive outside of your specific user account privileges. This severely limits what can be done to build custom ArcGIS based applications.

How do I open Visual Studio in non admin mode?

Right click on the Visual Studio icon. Choose Properties. Select the Compatibility tab. Unchecked Run this program as an administrator inside the Privilege Level group box.

How do I run as administrator?

Press and hold down the SHIFT key while you right-click the executable file or the icon for the application, and then select Run as. Select The following user. In the User name and Password boxes, type the administrator account and password, and then select OK.


1 Answers

So I have found a solution/workaround. Kind of seems like a wasted bounty now, so if someone has other suggestions that are better then please post and I will review them and award as applicable. Or even if somebody can make a more detailed version of my solution then I will award that one.


The issue is probably not specific to Visual Studio, but would occur with any application running with elevated privileges. Anyway, the solution I found is to add a registry key that enables the same shared drives to be accessible when running in administrator mode.

The registry key location is:

HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/Policies/System

And the key to add is called:

EnableLinkedConnections

And should be created as a DWORD with a value of 1 (0x00000001)

I checked with the machines running Windows 7 and they do NOT have this key, yet they still work fine. So I expect this isn't the only solution, but it does seem to work (no side effects noted yet). I would assume that Windows 10 has a specific setting somewhere that by default prevents mapped drives from automatically being available with "run as administrator".

For reference, I found this information here.

In fact, here is a more "official" recommendation for using this reg key.

like image 59
musefan Avatar answered Oct 28 '22 08:10

musefan