Elevated batch file cannot access mapped network drives

0

I know... this question has been asked before many times, but not in a way that adequately addresses my problem.

Long story short, I had problems running a batch file as administrator, that in turn ended up changing registry keys that required administrator privileges. I make all my other changes in separate batch files for keys that don't require admin rights. When I ran as administrator, a command window opened for a split second and then disappeared.

As described in numerous answers, such as this one, I enabled the EnableLinkedConnections setting; in fact, I created another batch script for it:

@echo off
reg add "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v "EnableLinkedConnections" /t REG_DWORD /d 0x00000001 /f
net stop LanmanWorkstation
net start LanmanWorkstation

Of course, I then couldn't execute that script either. I had to copy it to the computer and then run as administrator. That worked, since it was basically a one liner that didn't make any calls to external scripts on other mapped drives. Annoying, but I could live with this, if it worked, which it didn't!

In an elevated command prompt, typing net use displayed no connections, even after I restarted the computer (which I shouldn't have had to as my script restarted the relevant service). But I did, and it still didn't work. I manually opened the Registry Editor and confirmed that the change had been made.

Back to searching again, and I searched for "Windows 10 mapped drives don't display even with EnabledLinkedConnections".

The answer linked above states:

Microsoft has acknowledged a case where EnableLinkedConnections will fail to work. This will occur if UAC requires a password before running an elevated program (ie running as admin).

But I know that isn't the case for me, as this account is already an administrator account. To run something as administrator, as the default Admin Approval Mode settings dictate, I only need to click Yes/No; I don't need to enter a password.

In which case, the "bug" with EnabledLinkedConnections should not even apply to my system. Yet, it is not working.

I have a lot of stuff that I need to execute that makes references to fully specified paths (starting with the drive letter, like Z:\Scripts\etc...). Copying over scripts from a network location to the computer to execute them is not practical at all.

Considering that I have EnableLinkedConnections set to 1 and I am not prompted for a password by UAC, in theory, I should have no issues, but still my mapped network locations don't show up from the elevated instance of my account.

Why is this, and how can I fix it?


If it's any help, I just discovered that if I manually run some of the batch commands to map drives, a password is not required as it is in the initial mapping. The drive will just map. Then I can close the elevated command prompt and open another one, and the mapping is still there. However, I still had to manually open cmd.exe as administrator to accomplish this; and there is still not an elegant way to make sure it's mapped for both tokens when the logon script runs, unless I called the mapping part twice.

Also, this does not appear to be helpful, as though when running net use in this case, I do see the drives, but encounter a ERROR: Error opening the file. There may be a disk or file system error. message every time a call is made to another batch script on a mapped drive. This does not occur in regular non-admin scripts that call other files, nor for commands that directly modify system files without using a child helper file.

windows-10
batch
uac
mapped-drive
asked on Super User Aug 12, 2019 by InterLinked • edited Aug 12, 2019 by InterLinked

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0