This is a known behavior in Windows related to User Account Control (UAC). When UAC is enabled, the system creates two separate logon sessions: one with standard user privileges and another with full administrator privileges. Drives mapped in the standard user session are not visible in the elevated (administrator) session.
The reason for this behavior
When you map a network drive, a symbolic link is created that associates a drive letter with a UNC path (e.g., Z: to \\server\share). These symbolic links are created within the specific user logon session where the drive was mapped.
Standard session: When you log in, your standard user session is started. Any mapped drives are created here.
Elevated session: When you run a program "as administrator," Windows starts a new, separate logon session for that elevated process. The symbolic links from your standard user session are not carried over, so the mapped drives are unavailable.
How to fix the problem
Method 1: Change a registry setting
This is the most common and persistent solution, as it enables Windows to link the standard and elevated logon sessions, allowing mapped drives to be shared between them.
- Press Windows Key + R to open the Run dialog.
- Type regedit and press Enter. Click Yes on the UAC prompt.
- Navigate to the following registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System - Right-click on the System folder in the left pane, go to New, and select DWORD (32-bit) Value.
- Name the new value EnableLinkedConnections.
- Double-click EnableLinkedConnections and change the Value data to 1.
- Click OK and restart your computer for the change to take effect.
Method 2: Remap the drive in the elevated session
You can manually remap the network drive within the elevated session. This is a good solution if you only need temporary access or don't want to modify the registry.
- Open an elevated Command Prompt or PowerShell by right-clicking it and selecting Run as administrator.
- Use the net use command to map the drive. For example, to map a share to drive Z:
net use Z: \\ServerName\ShareName - You can then run your program from this elevated command prompt, and it will have access to the newly mapped drive.
Method 3: Use the UNC path
Instead of using a drive letter, you can have the program access the shared folder directly via its Universal Naming Convention (UNC) path, such as \\ServerName\ShareName.
- If your program allows you to browse for a location, you can navigate directly to the network location.
- You can also have the program run a script that uses the UNC path.
This is a robust method as it bypasses the issue of drive mappings entirely and does not require any system modifications.