1

So my teachers were all big fans of the Command Prompt and we're always using it, so I got used to it, and now I can't live without it, it's always open, my mouse is just a secondary accessory. So today, I wanted to create a virtual drive and make it so that it initializes on startup. So I've created a shortcut for cmd.exe on my desktop, went into my Startup file, created a batch file containing the following: @echo off subst w: c:\Users\******\Documents\CodEnv

It works as expected, but now when I try to get into that virtual drive, using a simple "w:", it says "The system cannot find the specified drive", but it's there! So, can anyone shed some light on the matter?

E_net4
  • 27,810
  • 13
  • 101
  • 139
Maxwell
  • 101
  • 2
  • 10
  • I had a similar experience but fixed it by putting a delay just before the `SUBST` - no idea why and YMMV. – Mark Setchell Aug 05 '16 at 22:12
  • And by delay you mean? Just a white space? – Maxwell Aug 05 '16 at 22:16
  • `I've created a shortcut for cmd.exe on my desktop, went into my Startup file, created a batch file` Could you detail step by step what exactly you did. Having a `cmd` shortcut on the desktop isn't related to whatever batch file you created, and what's that `Startup file` you talk about. `subst`'ing a drive letter from a batch file certainly works from a properly set startup item, without any 3rd party utilities. – dxiv Aug 06 '16 at 00:39
  • The shortcut is just for ease of access, and when I run it, it's already set to my virtual drive folder. The Startup file, well, the file that initializes everything inside of it when you start your computer. I also added to the target of my shortcut "k/ c:\Users\******\Documents\CodEnv\misc\shell.bat" so that each time I run cmd, it runs the shell.bat by itself containing everything I need in my Development Environment! – Maxwell Aug 06 '16 at 00:51
  • `the file that initializes everything inside of it when you start your computer` Sorry, but I still have no idea what you mean by that. Where on disk is that file, and what's its name? – dxiv Aug 06 '16 at 02:27
  • Sorry i meant the Startup folder... – Maxwell Aug 06 '16 at 02:51
  • Placing a `.lnk` to `cmd /c whatever.cmd` (or `.bat`) shortcut in the `Startup` folder where `whatever.cmd` has the contents you quoted would work just fine. If it didn't for you (and the other software did) then there is something else missing from the story. – dxiv Aug 06 '16 at 04:52
  • Figured out the problem, I had run as admin set for my shortcut, so by default it takes you to the System32 folder, even if you set it to go elsewhere. Otherwise it works just as expected, thanks! – Maxwell Aug 06 '16 at 12:03

4 Answers4

1

This is because the subst command is permission specific, you can test this yourself if you try running it with an admin command prompt vs a standard one.

So if you were to open an admin cmd and run the command: The drive will only be accessible with admin permissions.

If you were to open a standard cmd and run the command: The drive will only be accessible with standard permissions.

Startup will run without admin permissions

Mrtea101
  • 11
  • 1
0

To answer my question, there's some issues where even if you try to initialize a batch file from the startup file, it won't always work. But there's a little program called VSubst that lets you create a virtual drive that persist at reboot. Some other solutions includes adding a key to the registry, more on this on that forum https://superuser.com/questions/29072/how-to-make-subst-mapping-persistent-across-reboots

So hope it helps someone!

Community
  • 1
  • 1
Maxwell
  • 101
  • 2
  • 10
0

The following snippet works well without a shortcut to create and work with a virtual drive, no Admin rights required:

@echo off 
subst w: %userprofile%\Documents\CodEnv
timeout 3 >nul
echo Hello > w:\test.txt
exit /b
sambul35
  • 1,058
  • 14
  • 22
0

Check here for Persistent Subst (PSubst) that survives the windows restart. It is open source batch file.

https://github.com/cyberponk/psubst

cyberponk
  • 1,585
  • 18
  • 19