2

I have a .bat file in my startup folder that is creating a new drive via the command subst W: D:\WorkDrive

When I access a command prompt running as admin I cannot find the specified drive. While if I was to run the same command on a non-admin cmd I am able to locate the drive as shown here.

Administrator command prompt that is unable to locate virtual drive W: Administrator command prompt that is unable to locate virtual drive W:

Non-Admin command prompt that is able to locate virtual drive W: Non-Admin command prompt that is able to locate virtual drive W:

Neither of these command prompts are started with any options, these are just the base cmd one ran in admin and one not. I am unsure why this would be the case, but I would really like to be able to have admin permissions and be able to access drive W:

Cœur
  • 37,241
  • 25
  • 195
  • 267
Chris McCole
  • 59
  • 2
  • 15
  • Substititute and mapped drives are links to file paths (e.g. "W:" -> "\??\D:\WorkDrive") that get created in the object manager, either globally or locally per logon session. They get created globally for a SYSTEM logon and otherwise are created locally in a logon session. – Eryk Sun Apr 18 '20 at 16:05
  • 2
    With UAC, an administrator account is logged on with two logon sessions -- standard and elevated administrator. If you're creating the drive locally for just you, then you can use Task Scheduler to run `subst.exe W: D:\WorkDrive` twice, triggered at logon, once for the standard logon and once for the elevated logon session. Or run the command as SYSTEM at startup to define the drive globally. – Eryk Sun Apr 18 '20 at 16:07
  • `Subst` is part of MSDos 2 compatibility for MSDos 1 programs. So the problem it solved hasn't needed solving for 34 years. –  Apr 18 '20 at 21:28
  • 1
    @Mark, even in Windows 10 with long DOS paths enabled at the system level, most programs don't have the additional manifest setting that's required to enable long paths that exceed `MAX_PATH` (260) characters. They can only access long paths in "\\?\" extended form, which most programs, and even many system programs and API functions, do not support. One way to get around this, given a long base path in common, is to map the common path to a substitute drive, for which the target path can be up to about 2,000 characters. So substitute drives can still be useful. – Eryk Sun Apr 18 '20 at 21:48
  • @Mark, this problem also applies to mapped network drives. However, the code that maps network drives at startup supports a registry setting to automatically sync the standard and elevated logon-session devices. I don't think the setting is enabled by default, or at least it didn't used to be enabled by default, but at least it only has to get set once. Nothing synchronizes subst drives, but it would be possible to develop a system service that implements this -- if there were enough demand to warrant its development. – Eryk Sun Apr 18 '20 at 22:02
  • Running it through the task scheduler worked perfectly. Thank you, that was quite annoying, is there a way to run something from the starup folder as system? – Chris McCole Apr 19 '20 at 17:17

1 Answers1

1

As per Eryk Sun's comment:

With UAC, an administrator account is logged on with two logon sessions -- standard and elevated administrator. If you're creating the drive locally for just you, then you can use Task Scheduler to run subst.exe W: D:\WorkDrive twice, triggered at logon, once for the standard logon and once for the elevated logon session. Or run the command as SYSTEM at startup to define the drive globally.

Chris McCole
  • 59
  • 2
  • 15
  • 1
    On my system (Windows 10, 19041.572), this same issue was resolved with a single batch file run as a Task. The trigger was set to `At startup`, and uses the `SYSTEM` user account. Now the `subst` drive is visible in both standard and Admin command prompts. – AlainD Nov 17 '20 at 12:21