With previous versions of VS you could query the registry to determine the installation directory for VS:
HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\Visu
We have only 3 Visual Studio editions.
As such we can simplify everything a bit.
Here some tested CMD script.
@SET env_all_vs2017_root=%ProgramFiles(x86)%\Microsoft Visual Studio\2017
@SET env_vs2017_path="%env_all_vs2017_root%\Professional"
@IF NOT EXIST %env_vs2017_path% SET env_vs2017_path="%env_all_vs2017_root%\Community"
@IF NOT EXIST %env_vs2017_path% SET env_vs2017_path="%env_all_vs2017_root%\Enterprise"
@REM Let's fail laudly
@IF NOT EXIST %env_vs2017_path% SET "env_vs2017_path=Visual Studio 2017 install path was not found by %~nx0"
@REM You may want to remove quotes
@SET unquoted=%env_vs2017_path:"=%
@REM And now let's see the result and PAUSE
@ECHO VS 2017 install path is
@ECHO %unquoted%
@PAUSE