@echo off&set FileName=%~n0&shift :: ============================================= :: AutoHelp PlugLab Concept: 2006 by Reatogo :: ============================================= :: Help Info: :: ======================= set Routine_Type=3 :: 1=Getting Data 2=Prompts 3=Getting Files 4=Creating Files 5=General set Routine_Vers=1 set Routine_Date=2007-02-15 set RoutineName=GetProgPath set RoutineAuthor=Siegfried set Using_work_from=MartinR set Example_call_1=%%GetProgPath%% "HKLM\Software\PowerQuest\PartitionMagic\8.0\UserInfo" "Install Path" set Example_call_2=%%GetProgPath%% "HKEY_LOCAL_MACHINE\SOFTWARE\Acronis\DiskDirector\Settings" "ExePath" set Example_call_3=%%GetProgPath%% set text_01=Searches the registry for the installation path of a program and returns the result to the calling script in a variable %%ProgPath%%. set text_02=My extended ProgPath routine is based on the original ProgPath script by MartinR. It adds an addl. attempt to find the path by searching for the MainExe in ProgramFiles if everything else failed. Authors having problems to find a suitable registry entry for the ProgPath can now just use "%%GetProgPath%%" and will get a result. It may just take a while to search for the path that way. set text_03=. set text_04=%%GetProgPath%% like in example 3 will already find the ProgPath in the registry for some programs like Nero, which store the path in the standard location in registry. set text_05=The definition of the main exe in autoHelp.cmd is used for this attempt as well as for the MainExe search in ProgramFiles. set text_06=. set text_07=If ProgPath is "NotFound" after the search in registry, a last try will be made searching the entire %%ProgramFiles%% directory for the %%MainEXE%%. set text_08=If that fails too, ProgPath will be returned as "NotFound". If successful, the %%ProgPath%% is returned without a trailing backslash. set text_09=. set text_10=NOTE: it is essential that you define %%MainEXE%% in your AutoHelp.cmd as it is needed to check the success of the various attempts to find the ProgPath. if "%~1" == "GetHelp" goto :EOF echo.&echo %* :: ============================================= set MyRegKey=%~1 set MyRegVal=%~2 set ProgPath= if "%SubDir_Of_MainEXE%" == "" goto SkipBackSl if not "%SubDir_Of_MainEXE:~-1%" == "\" set SubDir_Of_MainEXE=%SubDir_Of_MainEXE%\ set tempSubd=\%SubDir_Of_MainEXE:~0,-1% :SkipBackSl "%APPs%\xFUNCs.exe" "ProgPath" "%MyRegKey%" "%MyRegVal%" set MyRegKey= set MyRegVal= if exist "%temp%\TempLab.cmd" ( call "%temp%\TempLab.cmd" del "%temp%\TempLab.cmd" ) set ProgPath=%result% if not "%ProgPath%" == "NotFound" goto _end if "%MainExe%" == "" goto _end :: last try: echo ProgPath is "NotFound" in the registry. echo Now searching in "%%ProgramFiles%%" for "%MainExe%" ... pushd "%ProgramFiles%" for /f "tokens=*" %%a in ('dir /n /b /s %MainExe%') do set tempProgPath=%%~dpa popd if "%tempProgPath%" == "" goto _end if "%tempProgPath:~-1%" == "\" set tempProgPath=%tempProgPath:~0,-1% if "%SubDir_Of_MainEXE%" == "" goto NoSubDir SETLOCAL ENABLEDELAYEDEXPANSION set tempSubd=%tempSubd%NoOtherLikeThisInPath set tempProgPath=%tempProgPath%NoOtherLikeThisInPath echo set tempProgPath=!tempProgPath:%tempSubd%=!> "%temp%\TempLab.cmd" ENDLOCAL if exist "%temp%\TempLab.cmd" ( call "%temp%\TempLab.cmd" del "%temp%\TempLab.cmd" ) :NoSubDir if exist "%tempProgPath%\%SubDir_Of_MainEXE%%MainExe%" set ProgPath=%tempProgPath%&goto _end :_end call :Correct_Orig_ProgDir set tempProgPath= echo ProgPath is "%ProgPath%" goto :EOF :: ============================================= :Correct_Orig_ProgDir :: ======================= if not defined MainExe goto :EOF if not exist "%ProgPath%\%SubDir_Of_MainEXE%%MainExe%" goto :EOF :: echo set Normal_tempOrig_ProgDir=!ProgPath:%ProgramFiles%=!>> "%temp%\TempLab.cmd" SETLOCAL ENABLEDELAYEDEXPANSION echo set Normal_tempOrig_ProgDir=!ProgPath:%ProgramFiles%\=!>> "%temp%\TempLab.cmd" echo set Dos_tempOrig_ProgDir=!ProgPath:%Dos_ProgramFiles%\=!>> "%temp%\TempLab.cmd" ENDLOCAL if exist "%temp%\TempLab.cmd" ( call "%temp%\TempLab.cmd" del "%temp%\TempLab.cmd" ) if exist "%ProgramFiles%\%Normal_tempOrig_ProgDir%\%SubDir_Of_MainEXE%%MainExe%" ( set Orig_ProgDir=%Normal_tempOrig_ProgDir% ) if exist "%ProgramFiles%\%Dos_tempOrig_ProgDir%\%SubDir_Of_MainEXE%%MainExe%" ( set Orig_ProgDir=%Dos_tempOrig_ProgDir% ) set Normal_tempOrig_ProgDir= set Dos_tempOrig_ProgDir= goto :EOF