# How can I add directories to the PATH only for instances of CMD.EXE in Windows 7?

I don't want to modify the system path in Windows 7, or the user path either.

But when I start up a Command Prompt (cmd.exe), I would like the path within the command prompt to be modified to include a couple of additional directories on the path that I would like searched for when I type in commands.

I thought earlier versions of Windows had the ability via a .pif file, and there used to be an ability to put variables in the autoexec.bat (though that might have set the variables for all windows apps and this I want to avoid.

-

## migrated from stackoverflow.comJan 6 '12 at 5:45

This question came from our site for professional and enthusiast programmers.

Interesting question. I just did some reverse engineering on VS Command Prompt, coz it does some thing similar. The short cut for this command prompt targets one batch file.

%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"" x86


Following is some sample script which gets called eventually

  @echo Setting environment for using Microsoft Visual Studio 2010 x86 tools.
@call :GetVSCommonToolsDir
@if "%VS100COMNTOOLS%"=="" goto error_no_VS100COMNTOOLSDIR

@call "%VS100COMNTOOLS%VCVarsQueryRegistry.bat" 32bit No64bit

@if "%VSINSTALLDIR%"=="" goto error_no_VSINSTALLDIR
@if "%FrameworkDir32%"=="" goto error_no_FrameworkDIR32
@if "%FrameworkVersion32%"=="" goto error_no_FrameworkVer32
@if "%Framework35Version%"=="" goto error_no_Framework35Version

@set FrameworkDir=%FrameworkDir32%
@set FrameworkVersion=%FrameworkVersion32%

@if not "%WindowsSdkDir%" == "" (
@set "PATH=%WindowsSdkDir%bin\NETFX 4.0 Tools;%WindowsSdkDir%bin;%PATH%"
@set "INCLUDE=%WindowsSdkDir%include;%INCLUDE%"
@set "LIB=%WindowsSdkDir%lib;%LIB%"
)


So you can have batch file similar to this, and every time to go to command prompt, you can use this.

Hope this helps you.

-
Yep, that will work, as long as I always launch the command prompt from my custom shortcut, which isn't a big deal. –  MarkS Jan 6 '12 at 15:54