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?
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