简体   繁体   中英

Why is my mapped network drive not appearing in Network Locations?

I'm using Windows 10. Here is my code to map the network drive.

System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.UseShellExecute = true;
p.StartInfo.Verb = "runas";
p.StartInfo.FileName = "net.exe";
p.StartInfo.Arguments = "use Z: " + dPath; //dPath has escaped characters
p.Start();

What I was trying to do was trying to run the command net.exe use Z: DPATH as administrator but the Z drive does not appear in File Explorer but when I run the exact same command using cmd with Admin rights, the Z drive appears correctly.


Proof of mapped drive

My Network drive is mapped as evidenced below (Encountered this error when trying to re-map it manually) just that it wasn't appearing under Network Locations in File Explorer > This PC.

尝试映射

This behaviour is caused by UAC (User Account Control). When logging on to Windows as an admin, there are two sessions created . One with admin rights and one without. When you map the drives programmatically, you are doing it with the session with admin rights.

However, when you use File Explorer to view the Network Locations, you are using standard rights. For mapped drives, the admin and standard rights are not shared. Hence, the admin is not able to view the mapped drive eventhough it was created with admin rights.

Solution 1

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

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

Point to New, and then click DWORD Value.

Type EnableLinkedConnections, and then press ENTER.

Right-click EnableLinkedConnections, and then click Modify.

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

Exit Registry Editor, and then restart the computer.

Solution 2

Run File Explorer as administrator

When making a right click on the Explorer and select "Run as administrator" it doesn't start the Windows Explorer with admin rights. The Windows Vista/7/8/10 Explorer includes a special function to block such requests.

To disable it, start regedit.exe and go to the following key:

HKEY_CLASSES_ROOT\\AppID{CDCBCFCA-3CDC-436f-A4E2-0E02075250C2}

make a right click on Permissions and set your user as owner of the key and give your current user writing permissions.

Next, delete or rename the value RunAs. Now the Elevated-Unelevated Explorer Factory is disabled and you can start the Explorer with admin rights.

Solution 3

If the above can't work, disable your UAC (User Account Control) by going into User Account Control Settings and moving the slider to Never notify

Also, if you have Professional, Enterprise, or Ultimate version of windows installed, you need to look into a program in Administrative tools called Local Security Policy and disable all the policies related to UAC in Security Settings > Local Policies > Security Options (Located in the bottom 15 policies of the list)

它帮助我通过任务管理器以管理员权限重新启动 explorer.exe。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM