Why does this work from a command line but not from a batch file
Posted: 24 Apr 2020 21:18
I have a batch file that backs up various files and settings on my PC for when I clean reinstall Windows.
The following variables are set;
set RootDrv=%cd%
set SRC=%cd:~0,2%
Set UserPath=%RootDrv%\%USERNAME%
set AppPath=%UserPath%\Applications
I write the contents of those to a log file which shows...
12:51:37.14 Root Path - H:\PostInstall
12:51:37.14 User path - H:\PostInstall\Phillip
12:51:37.14 Registry files - H:\PostInstall\Phillip\Applications
When run from a command line, these work fine;
REG EXPORT "HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Word\File MRU" "%AppPath%\Word_file.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Word\Place MRU" "%AppPath%\Word_Place.reg" /y >>C:\Backup.log 2>&1
"%Root1809%\rar.exe" a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wG:\ -x"Kodi\userdata\Thumbnails" KodiPackage Kodi >>C:\Backup.log 2>&1
"%Root1809%\rar.exe" a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wG:\ Kodi-x64 Kodi >>C:\Backup.log 2>&1
This also fails:
IF NOT EXIST "%AppPath%\" MD "%AppPath%" >>C:\Backup.log 2>&1
with
The filename, directory name, or volume label syntax is incorrect.
The reg exports report ERROR: Unable to write to the file. There may be a disk or file system error.
The rar command report
'"\rar.exe"' is not recognized as an internal or external command,
operable program or batch file.
The syntax of the command is incorrect.
It seems as if the value of %apppath% and %root1809% are nul.
For the registry exports, if I use
REG EXPORT "HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Word\File MRU" "%UserPath%\Applications\Word_file.reg" /y
It works fine.
EDIT: I've tried with enabledelayedexpansion and replaced %apppath% with !apppath! but that didn't help.
https://stackoverflow.com/questions/143 ... 1#14347131
Why is this failing?
The following variables are set;
set RootDrv=%cd%
set SRC=%cd:~0,2%
Set UserPath=%RootDrv%\%USERNAME%
set AppPath=%UserPath%\Applications
I write the contents of those to a log file which shows...
12:51:37.14 Root Path - H:\PostInstall
12:51:37.14 User path - H:\PostInstall\Phillip
12:51:37.14 Registry files - H:\PostInstall\Phillip\Applications
When run from a command line, these work fine;
REG EXPORT "HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Word\File MRU" "%AppPath%\Word_file.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Word\Place MRU" "%AppPath%\Word_Place.reg" /y >>C:\Backup.log 2>&1
"%Root1809%\rar.exe" a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wG:\ -x"Kodi\userdata\Thumbnails" KodiPackage Kodi >>C:\Backup.log 2>&1
"%Root1809%\rar.exe" a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wG:\ Kodi-x64 Kodi >>C:\Backup.log 2>&1
This also fails:
IF NOT EXIST "%AppPath%\" MD "%AppPath%" >>C:\Backup.log 2>&1
with
The filename, directory name, or volume label syntax is incorrect.
The reg exports report ERROR: Unable to write to the file. There may be a disk or file system error.
The rar command report
'"\rar.exe"' is not recognized as an internal or external command,
operable program or batch file.
The syntax of the command is incorrect.
It seems as if the value of %apppath% and %root1809% are nul.
For the registry exports, if I use
REG EXPORT "HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Word\File MRU" "%UserPath%\Applications\Word_file.reg" /y
It works fine.
EDIT: I've tried with enabledelayedexpansion and replaced %apppath% with !apppath! but that didn't help.
https://stackoverflow.com/questions/143 ... 1#14347131
Why is this failing?