where /R "C:\Program Files (x86)\Microsoft Visual Studio" csc.exe > tmpFile SET /p CSPATH= < tmpFile DEL tmpFile if defined CSPATH ( echo file1:"%CSPATH:~0,-8%" ) else ( where /R "C:\Program Files\Microsoft Visual Studio" csc.exe > tmpFile SET /p CSPATH= < tmpFile DEL tmpFile if defined CSPATH ( echo file2:"%CSPATH:~0,-8%" ) else ( where /R "C:\\" csc.exe > tmpFile SET /p CSPATH= < tmpFile DEL tmpFile if defined CSPATH ( echo file2:"%CSPATH:~0,-8%" ) else ( echo File not found ) ) ) if defined CSPATH ( for %%p in (csc.exe) do set "progpath=%%~$PATH:p" if not defined progpath ( C:\Windows\System32\setx.exe PATH "%CSPATH:~0,-8%;%PATH%" /M ) )