Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 210
Christian Boler Avatar asked May 18 '26 00:05

Christian Boler


2 Answers

What do you mean programmatically? If you're refering to a variable, there is no standard variable for system32. However you could use %WINDIR%\system32 or %systemroot%\system32.

like image 59
Peter Noble Avatar answered May 19 '26 14:05

Peter Noble


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%
like image 22
Christian Boler Avatar answered May 19 '26 12:05

Christian Boler