\Microsoft was unexpected at this time

I just spent two days tracking this problem down.

I received my new development machine with Windows7 x64 only a week ago. It all was just pefect – quad core CPU could compile the world in almost no time, and brand new Visual Studio 2010 was just as good as it gets. By the way, I am the Linux guy and prefer vim, automake and gcc any other IDE, so if I call Visual Studio perfect, it means something.

Neverthless, everything good has an end. Yesterday I tried to build bcp.exe tool I needed to dissect boost, and I faced very nasty and very unclear problem. I simply could not. Every time I started the build process, it would fail with the most weird message I ever seen:

\Microsoft was unexpected at this time

Well, I mentioned I am the Linux guy, but I am not a religious fanatic. I just thought that there was a problem of some sort in the boost’s build script and used another machine to build bcp.

Next day I became really concerned. I realized that I could not use “Visual Studio Prompt” from VS 2010 and VS 2008. Every time I tried to start them, they would have that message about unexpected microsoft on them; and environment variables were not set. So I could not build anything! Sadly, this was rather a major problem for me as we had quite a few makefile projects and not being able to set the correct environment for build process was that kind of present I could happily live without.

I spent next four hours to find that this or similar problem was already mentioned several times; but nobody offered a solution that would work and nobody explained what was causing that. Some said that Windows SDK installation could break the batch file vcvars32.bat; some thought there was a bug in the batch file itself. Strangely, it all worked perfectly on the the neighbor’s machine. I even compared the files and found no difference at all.

The solution came at the end of the day when all my hopes were gone. One guy mentioned that the problem was caused by the parentheses in vcvars32.bat:

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

He mentioned that as he found out, one of the directories where SDK was had braces in the name as well, and that broke the statement above completely as batch processor would find nested parentheses in the folder’s name and consider them as the end of the statement.

Needless to mention, may machine had some paths that had braces in them. C:\Program Files (x86). And, needless to mention, it is exactly where Visual Studio is installed. And it also exists in %PATH% environment variable.

By itself, it does not break the script. As I mentioned, it worked perfectly on the other machine which was the biological twin of my PC. But, what if one of the PATH’s members is encolsed in double quotes? (to check how your PATH looks like, type echo %PATH% in command prompt). I checked and that’s what I found:

c:\winutils;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;
C:\Windows\System32\WindowsPowerShell\v1.0\;
c:\Program Files (x86)Microsoft SQL Server\100\Tools\Binn\;
c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;
c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;
"C:\Program Files (x86)Microsoft Visual Studio 9.0\Common7\IDE\";
C:\Program Files (x86)Microsoft Team Foundation Server 2010 Power Tools\;
C:\Program Files (x86)Microsoft Team Foundation Server 2010 Power Tools\Best Practices Analyzer\;
c:\cygwin\bin

Bingo! I found that one entry of PATH was indeed enclosed in double quotes. And, not surprisingly, it had that nasty (x86) in it. It was pointing somewhere inside VS 2008 installation tree, so I think one of VS 2008 tools I have installed recently indeed screwed this up.

So, I simply removed those double quotes. Immediately after that, both VS 2010 and VS 2008 command prompts were fixed.

So, the fist thing you should do if you’re having the same problem: look at your %PATH% environment variable and check if anything is enclosed in double quotes.

Finding this just cost me two days of work, and I hope it it helps you sorting it out much faster.

\Microsoft was unexpected at this time
Leave a comment ?

77 Comments.

  1. Saved me a whole lot of debug time..Thanks..

    Also figured out ‘PROGRA~2’ works in place of ‘Program Files (x86)’.

    There was an extra “\” in the path variable, removing it fixed the issue.

  2. Thanks for writing this! What a stupid bug.

  3. Thanks a lot, solved the problem instantly. 🙂

  4. You just saved me 2 days of works apparently ! 😀

    Thanks ❗

  5. Thanks! helped me as well.

  6. THANKS! This saved me a lot of time. I am glad my google searched returned your post. Thanks again.

  7. How will I remove the parenthesis in the %PATH% variable.

  8. Thank you very much. I was struggling with this too.

  9. Thanks a lot..!! It helped me.. 😛

  10. Thank you! I had the same problem and never would have guessed this as the cause!

  11. Thank you very much – this fixed my problem!

  12. Thanks helped me as well

  13. Thanks bro! This was baffling!!!

  14. Many thanks. Worked for me too.

  15. Thanks, It worked for me. I don’t have path defined in “”, but i removed that path as it’s not required for me and it’s worked. Actually we need to check both system and user PATH variables. 🙂

  16. Thank you for the post!

  17. Thanks a lot, worked for me.

  18. Thanks! This was what my problem was.

  19. thank you so much this is god like work 😯

  20. thanks a lot bro you are super

  21. Finally something that really works. Thanks

  22. A big thanks, you got the problem and saved my day.
    There was “” in some other environment variables other than %path%.
    It worked.

  23. A huge thanks for saving the day. its the “” for me 🙂

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

10 visitors online now
3 guests, 7 bots, 0 members
Max visitors today: 13 at 05:48 pm UTC
This month: 18 at 11-10-2017 02:59 pm UTC
This year: 50 at 02-12-2017 07:56 am UTC
All time: 130 at 10-22-2014 11:16 pm UTC