1

I want to write a .bat script which finds a folder for installed program (e.g. Acrobat\JavaScript) because the folder can have a different path on every computer. Then put a .js file and a imgfolder inside. The .js file and the imgfolder is in the same folder as the .bat script. How can I find the full path of Acrobat\JavaScript on drive C and save to variable in order to copy the .js inside?

Here is what I tried:

@echo off

REM  find the folder with my .bat file 

for /f %%i in ("%0") do set curpath=%%~dpi 
echo  %curpath% 

REM it fails on this place:

for /R "C:\Programm Files(x86)" /D %d in (*) 
  do @if "%~nd" == "Acrobat\JavaScript" 

REM  I want to save here the path "%d" to a variable  in order to use it for copying

echo "%d"  

pause

If it works, I'll use this to copy imgfolder and the .js file to the retrieved path:

XCOPY %curpath%\imgFolder %d

To copy a folder:

XCOPY %curpath%\script.js %d /i

UPDATE:

I checked in the register, I found HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Adobe Acrobat\ and then all the versions 9.0 - 11.0. As I understood the path is saved in the folder InstallPath, therefore I combined:

 "HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\Acrobat.exe" /v InstallPath') ... 

Is it right?

 set path=""

 for /f "tokens=1-2*" %%A in ('reg query   "HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\Acrobat.exe" /v InstallPath') do (
 set path="%%C\JavaScript"
 )

echo path
pause

Error:
W:\batScript>for /F "tokens=1-2*" %A in ('reg query "HKLM\Software
\Microsoft\Windows\CurrentVersion\App Paths\Acrobat.exe" /v InstallPath') do (se
t path="%C\VBoxManage.ex" )
'reg' is not recognized as an internal or external command, operable program or batch file.

I tried with reg.exe query, the same error. What I am doing wrong?

Alexito
  • 393
  • 1
  • 5
  • 14
  • For folder path containing the batch file look at [What does %~dp0 mean, and how does it work?](http://stackoverflow.com/questions/5034076) And instead of searching for the folder, it is better to use `reg.exe query` to get the installation folder for Acrobat from registry from `HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\Acrobat.exe`. Use `regedit.exe` to see how application path of Acrobat is recorded in registry and run `reg.exe query /?` in a command prompt window to get help on this command. – Mofi Aug 20 '14 at 05:22
  • `%%d`, not `%d` - like you did it with `%%i` already. (use single `%` only on command line outside of batchfiles) – Stephan Aug 20 '14 at 05:53
  • Thanks Mofi and Stephan for the tips, I am progressed, but not much. Could you check my UPDATE above to say what it wrong? – Alexito Aug 20 '14 at 06:17
  • don't use `%path%` as a user variable name. You overwrote the systemvariable `%PATH%` which tells windows, where to find it's applications. Therefore `reg.exe` is not found (because windows looks for it in the folders specified by `%PATH%`) – Stephan Aug 20 '14 at 06:58

1 Answers1

1

You get the error 'reg' is not recognized as an internal or external command, operable program or batch file. in your code, because you have overwritten your system path by using the code set path="". Never use a variable with the name path as it will mess up your default system path.

Try this piece of code to identify the adobe path.

@echo off
for /f "skip=2 tokens=*" %%i in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\AcroRd32.exe" /V path  2^>nul') do  (set "adobe_path=%%i")
set adobe_path=%adobe_path:path    REG_SZ    =%
echo %adobe_path%

Tested output -

D:\Scripts>type op.bat
@echo off
for /f "skip=2 tokens=*" %%i in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\AcroRd32.exe" /V path  2^>nul') do  (set "adobe_path=%%i")
set adobe_path=%adobe_path:path    REG_SZ    =%
echo %adobe_path%
D:\Scripts>
D:\Scripts>
D:\Scripts>op.bat
C:\Program Files (x86)\Adobe\Reader 11.0\Reader\

D:\Scripts>

Cheers, G

gbabu
  • 968
  • 9
  • 14