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

For some reason, I have decided to try out Windows 8 on my development machine. So far, so good, until I try to start up Powershell that has some customizations, including pulling the PATH changes out of vcvars32.bat, so I have access to all of the various development tools.

Initially, the script was pulled from here with some changes to allow it to run within a x64 Powershell instance, so it ended up looking like this:

function Get-Batchfile($file) 
    $theCmd = "`"$file`" & set" 
    cmd /c $theCmd | Foreach-Object {
        $thePath, $theValue = $_.split('=')
        Set-Item -path env:$thePath -value $theValue

function VsVars32($version = "10.0")
    $theKey = "HKLM:SOFTWARE\Wow6432Node\Microsoft\VisualStudio\" + $version
    $theVsKey = get-ItemProperty $theKey
    $theVsInstallPath = [System.IO.Path]::GetDirectoryName($theVsKey.InstallDir)
    $theVsToolsDir = [System.IO.Path]::GetDirectoryName($theVsInstallPath)
    $theVsToolsDir = [System.IO.Path]::Combine($theVsToolsDir, "Tools")
    $theBatchFile = [System.IO.Path]::Combine($theVsToolsDir, "vsvars32.bat")
    write-host $theBatchFile
    Get-Batchfile $theBatchFile
    [System.Console]::Title = "Visual Studio " + $version + " Windows Powershell"


And it worked perfectly fine under Windows 7. Now, under Windows 8, I get the following back:

'C:\Program' is not recognized as an internal or external command, operable program or batch file.

Upon further examination, it appears something changed with how cmd /c works. As just running the cmd line on its own, results in this:

PS> cmd /c "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\vsvars32.bat"
'C:\Program' is not recognized as an internal or external command, operable program or batch file.

Has anyone encountered a similar issue, and hopefully a workaround?


As mentioned in an answer below, there could be a quoting problem. I did attempt this even before posting, and got this for my trouble:

PS> cmd /c ""C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\vsvars32.bat""
x86 : The term 'x86' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:28
+ cmd /c ""C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\vsvar ...
+                            ~~~
    + CategoryInfo          : ObjectNotFound: (x86:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

A few different permutations of quoting:

Double wrapped in single quotes:

PS> echo '"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\vsvars32.bat"'
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\vsvars32.bat"

PS> cmd /c '"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\vsvars32.bat"'
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

Escaped double quotes:

PS> echo "`"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\vsvars32.bat`""
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\vsvars32.bat"

PS> cmd /c "`"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\vsvars32.bat`""
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

Once again: Exact same script worked under Windows 7.

share|improve this question
I think there is a space problem "C:\progrma files(x86)\" or not? – avirk Oct 24 '12 at 18:28
Maybe you need to escape the brackets? It looks like it's treating them as a variable. – George Duckett Oct 24 '12 at 18:31
Invoke-CmdScript.ps1 does something similar, but seems slightly cleaner. Maybe give it a try: – Jay Bazuzi Oct 25 '12 at 2:50

If you are using Windows Power Shell, you have to use "" (double double-quotes) if you have spaces in your path.

""C:\Program Files""

Example: cmd /c ""start cd 'C:\Program Files'"" opens a new command prompt with current directory as C:\Program Files . If its not enclosed in double quotes, it would throw an error because of the enclosed space ' '.

Edit: It works with double single-quotes as well.

Edit: Optionally, you can escape the space using the ` character (back-quote/back-tick).

cmd /c start cd C:\Program` Files
share|improve this answer
The thing is, I was just running it on it's own as a test. The command line that's passed into cmd /c gets built up into a variable, and it does escape quotes there. Additionally, as stated, this same script worked fine under Win7. – Matt Sieker Oct 24 '12 at 18:19
Yes i get it.. Is it possible to enclose the command line being passed in double quotes? so that it would hopefully get re-enclosed when passed? – AbhishekGirish Oct 24 '12 at 18:44

From reading this question: on stack overflow it looks like the cmd should be of the form

cmd.exe /c "`"$_cmd`""

Note the two double quotes on the end, you only have one.

In the line:

cmd /c "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\vsvars32.bat"

Maybe its treating the argument that's in quotes as a string C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\vsvars32.bat with no qoutes, so maybe it should be

cmd /c """C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\vsvars32.bat"""

i.e. "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\vsvars32.bat" as a string, which would be the above.

share|improve this answer
Not sure about why it would've worked in 7 but not 8 if this is the case though. If not I'll delete. – George Duckett Oct 24 '12 at 19:02
The same thing threw me a bit when I first looked at the snippet. It's actually running vsvars, and then running set right after with &, so the whole command that gets passed in is "[path to vsvars.bat] & set", then it parses what comes out of set. – Matt Sieker Oct 24 '12 at 19:14
See edit for another go – George Duckett Oct 24 '12 at 19:19
This is also interesting: powershell stripping double quotes from command line arguments – George Duckett Oct 24 '12 at 19:23

I was just about to update the question with some more information, with it echoing the command it was going to run on both Win7 and Win8. In the process of doing so, I noticed something. My Windows 7 PC had both VS2010 and VS2012 installed, with the Win8 box only having VS2012.

Changing the $Version default value in the VsVars32 funciton to 11.0 made everything work again. Now, as for why it wasn't printing out the full path, which would have made this issue much easier to troubleshoot, is a very good question.

share|improve this answer

You must log in to answer this question.

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