Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to create a "mini virtual environment" to run a program. The only difference between my normal environment and the virtual one would be the drive mappings.

  • I have an X: drive mapped to \\some\network\location
  • I have a program myapp.exe that expects the X: drive to be mapped to C:\local\path
  • I need to keep my X: drive mapped to \\some\network\location throughout the process

I would like to be able to run the following batch file and not have it affect the current environment:

subst X: C:\local\path
share|improve this question
One way to accomplish this is to use the runas command to execute the batch file. The downside to this approach is that you must supply the user password every time, even if you runas the current user. – mwolfe02 Dec 17 '12 at 16:20

If the path the application checks does not yet exist, you can temporarily make a symbolic link. The application will find the files it needs in the directory it expects, while the file system redirects operations almost transparently to the actual path. Use with caution; (un)expected bad stuff may happen if, for example, C:\local\path\ already exists.

By default, Windows only grants users in the Administrators group privileges to create symbolic links. Therefore, the following script would have to be run with elevation, or (Windows 7) the permissions would have to be set through the security policy (secpol.msc or Control Panel, Administrative Tools, Local Security Policy) in the section Local Policies, User Rights Assignment.

mklink /D C:\local\path X:\
rmdir C:\local\path
share|improve this answer
I prefer SUBST.exe to this method since, if you ever had to delete the symbolic link then it would SEEM to be very precarious. Using the "subst /d X:" command is much safer and less scary than using "rm -r X:\" . I know MKLINK is a symbolic link but i would still want to be careful "just in case" it was a hard link. – djangofan Dec 17 '12 at 17:01
Interesting approach, but several of the files I need on the local X: drive will also exist in the network X: drive. I am trying to set up automated testing using test data on my local X: drive. So the potential overlap of files is not only possible but it's kind of the whole point. That approach definitely has merit for other use cases, though. – mwolfe02 Dec 17 '12 at 17:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .