Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
myapp.exe
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

1 Answer 1

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:\
myapp.exe
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.