1

I have a windows application launched from a taskbar shortcut that has an environment in which %COMSPEC% is not set.

This later creates a problem for this application when it tries to create a window with a shell in it, and cannot find cmd.exe.

Does Microsoft recommend a method for finding cmd.exe apart from relying on %COMSPEC%? (If so, what is that method?)

If %COMSPEC% is not set, when or why or how often will %systemroot%\system32\cmd.exe also be wrong?

Jerry Asher
  • 836
  • 2
  • 10
  • 23
  • 1
    `cmd.exe` should (always) be on the PATH - and if not, uhm, yeah. Most programs simply launch `cmd` and let it resolve as-it-will. – user2864740 Apr 02 '16 at 20:55
  • 5
    If COMSPEC is not set, you can declare the system as misconfigured. – Raymond Chen Apr 02 '16 at 20:57
  • Assuming that you're dealing with your own machines (or machines belonging to the person who contracted you to write this code) and that fixing the underlying problem isn't an option, I'd go with calling GetWindowsDirectory() and appending `system32\cmd.exe`. It doesn't need to work everywhere, after all, only on those particular machines. – Harry Johnston Apr 02 '16 at 23:45
  • I'm finding $COMSPEC not set within a Git bash script, on a Git instance installed with the experimental "no need for winpty" option. This seems to be [a more recent problem that affects other environment variables as well](https://stackoverflow.com/a/54188082/1048186). – Josiah Yoder Sep 22 '22 at 16:12
  • As a hacky patch on a single machine, the expected value of COMSPEC is usually "C:\WINDOWS\system32\cmd.exe." I hard-coded a system-wide environment variable to this value and it fixed my Git bash script. – Josiah Yoder Sep 23 '22 at 13:35

1 Answers1

0

%COMSPEC% is set but not able to install the postgreSQL version on my system

Shekhar
  • 19
  • 1