Search code examples
pathenvironment-variablescommand-promptsystem32

Programatically get system32 path in command prompt


I'm using a command process in another program that for some odd reason does not have the system32 set in the path environment variable. I can use the %comspec% variable to get the path C:/windows/system32/cmd.exe, but I need to just have the folder by itself.

I am not overly familiar with command prompt programming; is there a way that I can just add the system32 (or equivalent) path programmatically?


Solution

  • While it appears that there is no environment variable for obtaining the system32 folder (or its equivalent) on a system, I did find a solution involving string manipulation. The following block of code will add the folder where the cmd.exe path is located:

    SET str=%ComSpec%
    SET str=%str:cmd.exe=%
    SET PATH=%PATH%;%str%