# error MSB6004: The specified task executable location "C:\\WINDOWS\\system32\\cmd.exe" is invalid.

**URL:** https://discourse.cmake.org/t/error-msb6004-the-specified-task-executable-location-c-windows-system32-cmd-exe-is-invalid/6352
**Category:** Usage
**Tags:** os:windows, gen:vs
**Created:** [August 26, 2022, 12:28pm UTC](https://discourse.cmake.org/t/error-msb6004-the-specified-task-executable-location-c-windows-system32-cmd-exe-is-invalid/6352 "2022-08-26T12:28:20Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Pospelove](https://discourse.cmake.org/user_avatar/discourse.cmake.org/pospelove/32/2712_2.png) [@Pospelove](https://discourse.cmake.org/u/Pospelove)
#### Post date: [August 26, 2022, 12:28pm UTC](https://discourse.cmake.org/t/error-msb6004-the-specified-task-executable-location-c-windows-system32-cmd-exe-is-invalid/6352/1 "2022-08-26T12:28:20Z")

</div>

Hey! I’m running into an issue with CMake on my Windows machine (Visual Studio 2019 generator).

It seems this is specific to my system, but hope you have a clue on how to workaround. Non-cmake generated Visual Studio projects work fine. Before creating this issue, I was googling this error 2 days and didn’t succeed. Thanks for your attention!

My `CMakeLists.txt`:

```cmake
cmake_minimum_required(VERSION 3.22)
project(test)

```

Output:

```auto
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19042.
CMake Error at CMakeLists.txt:2 (project):
  Failed to run MSBuild command:

    C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/MSBuild/Current/Bin/MSBuild.exe

  to get the value of VCTargetsPath:

    Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET Framework
    Copyright (C) Microsoft Corporation. All rights reserved.

    Build started 26.08.2022 13:32:38.
    Project "C:\projects\test\build\CMakeFiles\3.24.1\VCTargetsPath.vcxproj" on node 1 (default targets).
    InitializeBuildStatus:
      Touching "x64\Debug\VCTargetsPath.tlog\unsuccessfulbuild".
    C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(155,5): error MSB6004: The specified task executable location "C:\WINDOWS\system32\cmd.exe" is invalid. [C:\projects\test\build\CMakeFiles\3.24.1\VCTargetsPath.vcxproj]
    Done Building Project "C:\projects\test\build\CMakeFiles\3.24.1\VCTargetsPath.vcxproj" (default targets) -- FAILED.

    Build FAILED.

    "C:\projects\test\build\CMakeFiles\3.24.1\VCTargetsPath.vcxproj" (default target) (1) ->
    (PostBuildEvent target) ->
      C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(155,5): error MSB6004: The specified task executable location "C:\WINDOWS\system32\cmd.exe" is invalid. [C:\projects\test\build\CMakeFiles\3.24.1\VCTargetsPath.vcxproj]

        0 Warning(s)
        1 Error(s)

    Time Elapsed 00:00:00.41

  Exit code: 1

-- Configuring incomplete, errors occurred!
See also "C:/projects/test/build/CMakeFiles/CMakeOutput.log".

```

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [August 26, 2022, 10:40pm UTC](https://discourse.cmake.org/t/error-msb6004-the-specified-task-executable-location-c-windows-system32-cmd-exe-is-invalid/6352/2 "2022-08-26T22:40:48Z")

</div>

- Where are you running CMake (i.e. what kind of shell or terminal)?
- What is the output of `msbuild -version` from that shell (I know it’s shown in your output above, but humor me)?
- What is the command line you’re using to run CMake?

---

<div class="post-metadata">

### Author: ![Pospelove](https://discourse.cmake.org/user_avatar/discourse.cmake.org/pospelove/32/2712_2.png) [@Pospelove](https://discourse.cmake.org/u/Pospelove)
#### Post date: [August 27, 2022, 7:43am UTC](https://discourse.cmake.org/t/error-msb6004-the-specified-task-executable-location-c-windows-system32-cmd-exe-is-invalid/6352/3 "2022-08-27T07:43:14Z")

</div>

- cmd.exe, windows powershell, vscode terminal. with the same results.
- cmd.exe: `'msbuild' is not recognized as an internal or external command, operable program or batch file.`
- `cmake ..` (current directory is \<source\_dir\>/build)

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [August 27, 2022, 11:00pm UTC](https://discourse.cmake.org/t/error-msb6004-the-specified-task-executable-location-c-windows-system32-cmd-exe-is-invalid/6352/4 "2022-08-27T23:00:25Z")

</div>

Please run CMake from an empty build directory (i.e. start from scratch). Show the full command you use to run CMake and the full output from that. Also, just to be sure, does `C:\WINDOWS\system32\cmd.exe` exist on your system (hard to see how it wouldn’t, but I have to ask)?

And one more thing to try, please do all this from a Visual Studio command prompt, not the ordinary one that comes with Windows. It shouldn’t matter if using the Visual Studio generator, but see if that makes any difference (it would make msbuild available as a command, if nothing else).

---

<div class="post-metadata">

### Author: ![Pospelove](https://discourse.cmake.org/user_avatar/discourse.cmake.org/pospelove/32/2712_2.png) [@Pospelove](https://discourse.cmake.org/u/Pospelove)
#### Post date: [August 28, 2022, 9:22am UTC](https://discourse.cmake.org/t/error-msb6004-the-specified-task-executable-location-c-windows-system32-cmd-exe-is-invalid/6352/6 "2022-08-28T09:22:23Z")

</div>

Thank you for your help!

I found that `C:\WINDOWS\SysWOW64\\cmd.exe` was missing.

Running `sfc /scannow` from Windows PowerShell (under Admin) and rebooting the system helped me.

I love how Windows works ha-ha

---

<div class="post-metadata">

### Author: ![EricGT](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/e/f1d935/32.png) [@EricGT](https://discourse.cmake.org/u/EricGT)
#### Post date: [August 28, 2022, 11:28am UTC](https://discourse.cmake.org/t/error-msb6004-the-specified-task-executable-location-c-windows-system32-cmd-exe-is-invalid/6352/7 "2022-08-28T11:28:48Z")

</div>

> [@Pospelove](#):
>
> Running `sfc /scannow`

When you [first](https://discourse.cmake.org/t/error-msb6004-the-specified-task-executable-location-c-windows-system32-cmd-exe-is-invalid/6352) posted this I was curious so Goolged `error MSB6004: The specified task executable location “C:\WINDOWS\system32\cmd.exe”`

One of the replies turned up this StackOverflow [answer](https://stackoverflow.com/a/33160855/1243762).

However that notes

> - In administrator command prompt, run `sfc /scannow`

Did you run `sfc /scannow` as a regular user or was it started with `Run as administrator`?

---

<div class="post-metadata">

### Author: ![Pospelove](https://discourse.cmake.org/user_avatar/discourse.cmake.org/pospelove/32/2712_2.png) [@Pospelove](https://discourse.cmake.org/u/Pospelove)
#### Post date: [August 28, 2022, 12:00pm UTC](https://discourse.cmake.org/t/error-msb6004-the-specified-task-executable-location-c-windows-system32-cmd-exe-is-invalid/6352/8 "2022-08-28T12:00:08Z")

</div>

yes
