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?
Why does this work from a command line but not from a batch file
Moderator: DosItHelp
Re: Why does this work from a command line but not from a batch file
I fail to see where %root1809% is defined as a variable
Re: Why does this work from a command line but not from a batch file
Windows typically forbids to create files in the root directory of system drives (typically "C:\"),
so you should place your "Backup.log" file somewhere else.
penpen
so you should place your "Backup.log" file somewhere else.
penpen
Re: Why does this work from a command line but not from a batch file
ughh! Sorry, that is my fault. It should say %RootDrv%... Typo.
The code is
"%RootDrv%\rar.exe" a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wG:\ -x"Kodi\userdata\Thumbnails" KodiPackage Kodi >>C:\Backup.log 2>&1
"%RootDrv%\rar.exe" a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wG:\ Kodi-x64 Kodi >>C:\Backup.log 2>&1
I've attached the script. As you can see, even though AppPath is defined it's not referenced because it doesn't work.
Code: Select all
@Echo Off
Rem =============================================================================================================================================
Rem = Exports registry settings, copies files and creates archives for back up for postinstall script =
Rem = =
Rem = v0.1.0 - 19/04/2020 - Initial Release: Caters only for Phillip and a few snippets of other uers (c) Phillip Morgan 2020 =
Rem = v0.1.1 - 25/04/2020 - Add G:\ Drive backup. Fix error in hhandbrake spelling. Skip macrium and openvpn for some users =
Rem = =
Rem =============================================================================================================================================
setlocal
Rem This script is run from H:\PostsInstall
set RootDrv=%cd%
set SRC=%cd:~0,2%
set sversion=0.1.1
set sDate=25/04/2020
Set UserPath=%RootDrv%\%USERNAME%
set AppPath=%UserPath%\Applications
set path=%path%;%RootDrv%
:L000
Rem =============================================================================================================================================
Rem = Phillip =
Rem =============================================================================================================================================
set MozPath=F:\Users\%USERNAME%\Profiles
set WinAero=H:\WinaeroTweaker
Rem =============================================================================================================================================
Rem = Test =
Rem =============================================================================================================================================
set MozPath=F:\Users\%USERNAME%\Profiles
set WinAero=H:\WinaeroTweaker
Rem =============================================================================================================================================
Rem = Corey =
Rem =============================================================================================================================================
set MozPath=%Appdata%\Mozilla\Firefox\Profiles
set WinAero=C:\WinaeroTweaker
Rem Write defaults to log file
Echo %time% === System Backup Script for PostInstall v%sVersion% %sDate% ========================================= >>C:\Backup.log 2>&1
Echo. >>C:\Backup.log 2>&1
Echo %time% Root Path - %RootDrv% >>C:\Backup.log 2>&1
Echo %time% User path - %UserPath% >>C:\Backup.log 2>&1
ECho %time% path = %path% >>C:\Backup.log 2>&1
Echo %time% Mozilla path - %MozPath% >>C:\Backup.log 2>&1
Echo %time% WinAero path - %WinAero% >>C:\Backup.log 2>&1
Echo %time% Registry files - %userpath%\Applications >>C:\Backup.log 2>&1
Echo. >>C:\Backup.log 2>&1
IF NOT EXIST "%UserPath%\" (
Echo %time% Folder %RootDrv%\%Username% not found >>C:\Backup.log 2>&1
GOTO L900
)
IF NOT EXIST "%Userpath%\Applications\" MD "%UserPath%\Applications" >>C:\Backup.log 2>&1
:L010
Echo Exporting registry entries
Echo %time% Exporting registry settings for applications >>C:\Backup.log 2>&1
IF /I NOT "%USERNAME%"=="Corey" (
REG EXPORT "HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Word\File MRU" "%userpath%\Applications\Word_file.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Word\Place MRU" "%userpath%\Applications\Word_Place.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Excel" "%userpath%\Applications\Excel.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\PowerPoint\File MRU" "%userpath%\Applications\PPT_File.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\PowerPoint\Place MRU" "%userpath%\Applications\PPT_Place.reg" /y >>C:\Backup.log 2>&1
)
IF /I "%USERNAME%"=="Corey" (
REG EXPORT "HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Word\File MRU" "%userpath%\Applications\Word_file.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Word\Place MRU" "%userpath%\Applications\Word_Place.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Excel" "%userpath%\Applications\Excel.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\PowerPoint\File MRU" "%userpath%\Applications\PPT_File.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\PowerPoint\Place MRU" "%userpath%\Applications\PPT_Place.reg" /y >>C:\Backup.log 2>&1
)
IF "%USERNAME%"=="Phillip" (
REG EXPORT "HKEY_CURRENT_USER\Software\AVStoDVD" "%userpath%\Applications\AVStoDVD.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_CURRENT_USER\Software\BDtoAVCHD" "%userpath%\Applications\BDtoAVCHD.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_CURRENT_USER\Software\DVDFab" "%userpath%\Applications\DVDFab11-1.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_CURRENT_USER\Software\MakeMKV" "%userpath%\Applications\MakeMKV.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_CURRENT_USER\Software\Network Optix" "%userpath%\Applications\tsMuxer.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_CURRENT_USER\Software\PopCap" "%userpath%\Applications\Bejeweled.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_CURRENT_USER\Software\Sysinternals" "%userpath%\Applications\SysInternals.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\Kodi" "%userpath%\Applications\kodi-x64.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_CURRENT_USER\Software\Network Optix" "%userpath%\Applications\tsMuxer.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Wildfire Studios" "%userpath%\Applications\BOS.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_LOCAL_MACHINE\SOFTWARE\Nikse" "%userpath%\Applications\SubtitleEdit.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_LOCAL_MACHINE\SOFTWARE\DVDFab" "%userpath%\Applications\DVDFab11-2.reg" /y >>C:\Backup.log 2>&1
)
IF "%USERNAME%"=="Test" (
REG EXPORT "HKEY_CURRENT_USER\Software\AVStoDVD" "%userpath%\Applications\AVStoDVD.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_CURRENT_USER\Software\BDtoAVCHD" "%userpath%\Applications\BDtoAVCHD.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_CURRENT_USER\Software\DVDFab" "%userpath%\Applications\DVDFab11-1.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_CURRENT_USER\Software\MakeMKV" "%userpath%\Applications\MakeMKV.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_CURRENT_USER\Software\Network Optix" "%userpath%\Applications\tsMuxer.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_CURRENT_USER\Software\PopCap" "%userpath%\Applications\Bejeweled.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_CURRENT_USER\Software\Sysinternals" "%userpath%\Applications\SysInternals.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\Kodi" "%userpath%\Applications\kodi-x64.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Wildfire Studios" "%userpath%\Applications\BOS.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_LOCAL_MACHINE\SOFTWARE\Nikse" "%userpath%\Applications\SubtitleEdit.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_LOCAL_MACHINE\SOFTWARE\DVDFab" "%userpath%\Applications\DVDFab11-2.reg" /y >>C:\Backup.log 2>&1
)
REG EXPORT "HKEY_CURRENT_USER\Software\Daum" "%userpath%\Applications\PotPlayer.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_CURRENT_USER\Software\ImgBurn" "%UserPath%\Imgburn.reg" /y >>C:\Backup.log 2>&1
IF NOT "%USERNAME%"=="MediaCenter" IF NOT "%USERNAME%"=="Bedroom" (
REG EXPORT "HKEY_CURRENT_USER\Software\Macrium" "%userpath%\Applications\Macrium1.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_LOCAL_MACHINE\SOFTWARE\Macrium" "%userpath%\Applications\Macrium2.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN" "%userpath%\Applications\OpenVPN.reg" /y >>C:\Backup.log 2>&1
)
REG EXPORT "HKEY_CURRENT_USER\Software\OpenShell" "%userpath%\Applications\OpenShell.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_CURRENT_USER\Software\ShellFolderFix" "%userpath%\Applications\ShellfolderFix.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_CURRENT_USER\Software\Winaero.com" "%userpath%\Applications\WinAero.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_CURRENT_USER\Software\WinRAR" "%userpath%\Applications\WinRAR1.reg" /y >>C:\Backup.log 2>&1
REG EXPORT "HKEY_LOCAL_MACHINE\SOFTWARE\WinRAR" "%userpath%\Applications\WinRAR2.reg" /y >>C:\Backup.log 2>&1
Rem =============================================================================================================================================
Rem Hearthstone Deck Tracker
Rem =============================================================================================================================================
:L020
IF NOT "%USERNAME%"=="Phillip" IF NOT "%USERNAME%"=="Peyton" GOTO L030
Echo %time% Hearthstone registry >>C:\Backup.log 2>&1
REG EXPORT "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\HearthstoneDeckTracker" "%userpath%\Applications\HSDT.reg" /y >>C:\Backup.log 2>&1
:L030
Rem =============================================================================================================================================
Rem Group Policy
Rem =============================================================================================================================================
Echo %time% Backing up Group Policy >>C:\Backup.log 2>&1
IF EXIST "%UserPath%\GroupPolicy\" (
IF EXIST "%UserPath%\GroupPolicy.old\" rd "%Userpath%\GroupPolicy.old" /q/s >>C:\Backup.log 2>&1
attrib "%UserPath%\GroupPolicy" -h >>C:\Backup.log 2>&1
ren "%UserPath%\GroupPolicy" GroupPolicy.old >>C:\Backup.log 2>&1
)
xcopy "%windir%\System32\GroupPolicy" "%UserPath%\GroupPolicy" /x/h/q/y/i/c/e >>C:\Backup.log 2>&1
attrib "%UserPath%\GroupPolicy" +H >>C:\Backup.log 2>&1
Rem =============================================================================================================================================
Rem Create drive archives D: - H:
Rem =================================r============================================================================================================
:L050
Echo Backing up drives
IF EXIST "%UserPath%\ddrive.rar" del "%UserPath%\ddrive.rar" /q >>C:\Backup.log 2>&1
IF EXIST "%UserPath%\edrive.rar" del "%UserPath%\edrive.rar" /q >>C:\Backup.log 2>&1
IF EXIST "%UserPath%\fdrive.rar" del "%UserPath%\fdrive.rar" /q >>C:\Backup.log 2>&1
IF EXIST "%UserPath%\gdrive.rar" del "%UserPath%\gdrive.rar" /q >>C:\Backup.log 2>&1
IF EXIST "%UserPath%\hdrive.rar" del "%UserPath%\hdrive.rar" /q >>C:\Backup.log 2>&1
Echo %time% Creating drive back ups >>C:\Backup.log 2>&1
rar a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wG:\ -x$recycle.bin -x"System Volume Information" -xgames -x"Program Files (X86)" "%UserPath%\ddrive" d:\*.* >>C:\Backup.log 2>&1
rar a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wG:\ "%UserPath%\ddrive" "d:\Program Files (x86)\Encore" >>C:\Backup.log 2>&1
rar a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wG:\ "%UserPath%\ddrive" "d:\Program Files (x86)\gog.com" >>C:\Backup.log 2>&1
rar a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wG:\ "%UserPath%\ddrive" "d:\Program Files (x86)\UbiSoft" >>C:\Backup.log 2>&1
rar a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wG:\ "%UserPath%\ddrive" "d:\Program Files (x86)\3DRealms" >>C:\Backup.log 2>&1
rar a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wG:\ "%UserPath%\ddrive" "d:\Program Files (x86)\Battle.net" >>C:\Backup.log 2>&1
rar a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wG:\ "%UserPath%\ddrive" "d:\Program Files (x86)\Hearthstone" >>C:\Backup.log 2>&1
rar a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wg:\ "%UserPath%\edrive" "e:\Test Files" >>C:\Backup.log 2>&1
rar a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wG:\ -x$recycle.bin -x"System Volume Information" -xvideo "%UserPath%\fdrive" F:\*.* >>C:\Backup.log 2>&1
rar a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wh:\ "%UserPath%\gdrive" "g:\Boot" >>C:\Backup.log 2>&1
rar a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wh:\ "%UserPath%\gdrive" "g:\Movie Label Databases" >>C:\Backup.log 2>&1
rar a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wh:\ "%UserPath%\gdrive" "g:\Documentation" >>C:\Backup.log 2>&1
rar a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wG:\ "%UserPath%\hdrive" "H:\7-zipPortable" >>C:\Backup.log 2>&1
rar a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wG:\ "%UserPath%\hdrive" "H:\aida64" >>C:\Backup.log 2>&1
rar a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wG:\ "%UserPath%\hdrive" "H:\decrypter" >>C:\Backup.log 2>&1
rar a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wG:\ "%UserPath%\hdrive" "H:\ffmpeg" >>C:\Backup.log 2>&1
Rem rar a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wG:\ "%UserPath%\hdrive" "H:\firefox" >>C:\Backup.log 2>&1
rar a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wG:\ "%UserPath%\hdrive" "H:\hostman" >>C:\Backup.log 2>&1
rar a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wG:\ "%UserPath%\hdrive" "H:\hwinfo" >>C:\Backup.log 2>&1
rar a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wG:\ "%UserPath%\hdrive" "H:\portqryUI" >>C:\Backup.log 2>&1
rar a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wG:\ "%UserPath%\hdrive" "H:\qb64" >>C:\Backup.log 2>&1
rar a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wG:\ "%UserPath%\hdrive" "H:\rufus" >>C:\Backup.log 2>&1
rar a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wG:\ "%UserPath%\hdrive" "H:\skins" >>C:\Backup.log 2>&1
rar a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wG:\ "%UserPath%\hdrive" "H:\tmm" >>C:\Backup.log 2>&1
rar a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wG:\ "%UserPath%\hdrive" "H:\tools" >>C:\Backup.log 2>&1
rar a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wG:\ "%UserPath%\hdrive" "H:\USBImage" >>C:\Backup.log 2>&1
rar a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wG:\ "%UserPath%\hdrive" "H:\UTubeDL" >>C:\Backup.log 2>&1
rar a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wG:\ "%UserPath%\hdrive" "H:\WinaeroTweaker" >>C:\Backup.log 2>&1
rar a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wG:\ -xh:\msmg95\iso -xh:\msmg95\dvd "%UserPath%\hdrive" "H:\MSMG95" >>C:\Backup.log 2>&1
Rem =============================================================================================================================================
Rem Latest copy of tools folder from C:\
Rem =============================================================================================================================================
:L060
IF EXIST "C:\Tools\" (
Echo Backing up Tools folder
Echo %time% Copying tools folder >>C:\Backup.log 2>&1
xcopy C:\Tools "%Root1Drv%\tools" /x/h/q/y/i/c/e >>C:\Backup.log 2>&1
)
IF NOT EXIST "C:\Tools\" (
Echo %time% *** C:\Tools folder is missing >>C:\Backup.log 2>&1
)
Rem =============================================================================================================================================
Rem Appdata folders
Rem =============================================================================================================================================
:L070
Echo Backing up application data and settings
Echo %time% Copying %APPDATA% folders >>C:\Backup.log 2>&1
IF EXIST "%APPDATA%\HearthstoneDeckTracker\" (
IF EXIST "%UserPath%\RAHSDT\" rd "%UserPath%\RAHSDT" /s/q >>C:\Backup.log 2>&1
xcopy "%APPDATA%\HearthstoneDeckTracker" "%UserPath%\RAHSDT" /x/h/q/y/i/c/e >>C:\Backup.log 2>&1
)
IF EXIST "%APPDATA%\Battle.Net\" (
IF EXIST "%UserPath%\RABattleNet\" rd "%UserPath%\RABattleNet" /s/q >>C:\Backup.log 2>&1
xcopy "%APPDATA%\Battle.Net" "%UserPath%\RABattleNet" /x/h/q/y/i/c/e >>C:\Backup.log 2>&1
)
IF EXIST "%APPDATA%\Hoyle\" (
IF EXIST "%UserPath%\Hoyle\" rd "%UserPath%\Hoyle" /s/q >>C:\Backup.log 2>&1
xcopy "%APPDATA%\Hoyle" "%UserPath%\Hoyle" /x/h/q/y/i/c/e >>C:\Backup.log 2>&1
)
IF EXIST "%APPDATA%\Handbrake\" (
IF EXIST "%UserPath%\Handbrake\" rd "%UserPath%\Handbrake" /s/q >>C:\Backup.log 2>&1
xcopy "%APPDATA%\Handbrake" "%UserPath%\Handbrake" /x/h/q/y/i/c/e >>C:\Backup.log 2>&1
)
IF EXIST "%APPDATA%\Notepad++\" (
IF EXIST "%UserPath%\Notepad++\" rd "%UserPath%\Notepad++" /s/q >>C:\Backup.log 2>&1
xcopy "%APPDATA%\Notepad++" "%UserPath%\Notepad++" /x/h/q/y/i/c/e >>C:\Backup.log 2>&1
)
IF EXIST "%APPDATA%\ShellfolderFix\" (
IF EXIST "%UserPath%\ShellDB\" rd "%UserPath%\ShellDB" /s/q >>C:\Backup.log 2>&1
xcopy "%APPDATA%\ShellfolderFix" "%UserPath%\ShellDB" /x/h/q/y/i/c/e >>C:\Backup.log 2>&1
)
IF EXIST "%APPDATA%\Subtitle Edit\" (
IF EXIST "%UserPath%\Subtitle Edit\" rd "%UserPath%\Subtitle Edit" /s/q >>C:\Backup.log 2>&1
xcopy "%APPDATA%\Subtitle Edit" "%UserPath%\Subtitle Edit" /x/h/q/y/i/c/e >>C:\Backup.log 2>&1
)
IF EXIST "%APPDATA%\DVDFab11\" (
IF EXIST "%UserPath%\DVDFab\DVDFab11\" rd "%UserPath%\DVDFab\DVDFab11" /s/q >>C:\Backup.log 2>&1
xcopy "%APPDATA%\DVDFab11" "%UserPath%\DVDFab\DVDFab11" /x/h/q/y/i/c/e >>C:\Backup.log 2>&1
)
IF EXIST "%APPDATA%\OpenShell\" (
IF EXIST "%UserPath%\OpenShell\Roaming_OpenShell\" rd "%UserPath%\OpenShell\Roaming_OpenShell" /s/q >>C:\Backup.log 2>&1
xcopy "%APPDATA%\OpenShell" "%UserPath%\OpenShell\Roaming_OpenShell" /x/h/q/y/i/c/e >>C:\Backup.log 2>&1
)
IF EXIST "%APPDATA%\PotPlayerMini64\" (
IF EXIST "%UserPath%\PotPlayerMini64\" rd "%UserPath%\PotPlayerMini64" /s/q >>C:\Backup.log 2>&1
xcopy "%APPDATA%\PotPlayerMini64" "%UserPath%\PotPlayerMini64" /x/h/q/y/i/c/e >>C:\Backup.log 2>&1
)
IF EXIST "%APPDATA%\Kodi\" (
Echo %time% Creating Kodi Back ups >>C:\Backup.log 2>&1
C:
CD "%APPDATA%"
Echo %time% Searching for existing Kodi data archives >>C:\Backup.log 2>&1
IF EXIST "%UserPath%\KodiPackage.rar" ren "%UserPath%\KodiPackage.rar" KodiPackage.old >>C:\Backup.log 2>&1
IF EXIST "%UserPath%\Kodi-x64.rar" ren "%UserPath%\Kodi-x64.rar" Kodi-x64.old >>C:\Backup.log 2>&1
Echo %time% Creating new Kodi data archive >>C:\Backup.log 2>&1
rar.exe a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wG:\ -x"Kodi\userdata\Thumbnails" KodiPackage Kodi >>C:\Backup.log 2>&1
copy KodiPackage.rar "%UserPath%" /y >>C:\Backup.log 2>&1
del KodiPackage.rar >>C:\Backup.log 2>&1
IF EXIST "%PROGRAMFILES%\Kodi\" (
CD "%PROGRAMFILES%"
Echo %time% Creating new Kodi Program archive >>C:\Backup.log 2>&1
rar.exe a -r -y -iddp -rr5 -ow -tsmcap -tl -dh -wG:\ Kodi-x64 Kodi >>C:\Backup.log 2>&1
copy Kodi-x64.rar "%UserPath%" /y >>C:\Backup.log 2>&1
del Kodi-x64.rar >>C:\Backup.log 2>&1
)
Echo %time% Cleaning up old Kodi archives >>C:\Backup.log 2>&1
IF EXIST "%UserPath%\KodiPackage.rar" del "%UserPath%\KodiPackage.old" /q /f >>C:\Backup.log 2>&1
IF EXIST "%UserPath%\Kodi-x64.rar" del "%UserPath%\Kodi-x64.old" /q /f >>C:\Backup.log 2>&1
IF NOT EXIST "%UserPath%\KodiPackage.rar" IF EXIST "%UserPath%\Kodipackage.old" ren "%UserPath%\KodiPackage.old" KodiPackage.rar >>C:\Backup.log 2>&1
IF NOT EXIST "%UserPath%\Kodi-x64.rar" IF EXIST "%UserPath%\Kodipackage.old" ren "%UserPath%\Kodi-x64.old" Kodi-x64.rar >>C:\Backup.log 2>&1
%SRC%
CD %RootDrv%
)
Rem =============================================================================================================================================
Rem Programdata folders
Rem =============================================================================================================================================
:L080
Echo %time% Copying %PROGRAMDATA% folders >>C:\Backup.log 2>&1
IF EXIST "%PROGRAMDATA%\Battle.Net\" (
IF EXIST "%UserPath%\PDBattleNet\" rd "%UserPath%\PDBattleNet" /q/s >>C:\Backup.log 2>&1
xcopy "%PROGRAMDATA%\Battle.Net" "%UserPath%\PDBattleNet" /x/h/q/y/i/c/e >>C:\Backup.log 2>&1
)
IF EXIST "%PROGRAMDATA%\Macrium\" (
IF EXIST "%UserPath%\Macrium\" rd "%UserPath%\Macrium" /q/s >>C:\Backup.log 2>&1
xcopy "%PROGRAMDATA%\Macrium" "%UserPath%\Macrium" /x/h/q/y/i/c/e >>C:\Backup.log 2>&1
)
IF EXIST "%PROGRAMDATA%\PopCap Games\" (
IF EXIST "%UserPath%\PopCap Games\" rd "%UserPath%\PopCap Games" /q/s >>C:\Backup.log 2>&1
xcopy "%PROGRAMDATA%\PopCap Games" "%UserPath%\PopCap Games" /x/h/q/y/i/c/e >>C:\Backup.log 2>&1
)
Rem =============================================================================================================================================
Rem LocalAppdata folders
Rem =============================================================================================================================================
:L090
Echo %time% Copying %LOCALAPPDATA% folders >>C:\Backup.log 2>&1
IF EXIST "%LOCALAPPDATA%\Battle.Net\" (
IF EXIST "%UserPath%\LABattleNet\" rd "%UserPath%\LABattleNet" /s/q >>C:\Backup.log 2>&1
xcopy "%LOCALAPPDATA%\Battle.Net" "%UserPath%\LABattleNet" /x/h/q/y/i/c/e >>C:\Backup.log 2>&1
)
IF EXIST "%LOCALAPPDATA%\Bunkus.org\" (
IF EXIST "%UserPath%\Bunkus.org\" rd "%UserPath%\Bunkus.org" /s/q
xcopy "%LOCALAPPDATA%\Bunkus.org" "%UserPath%\Bunkus.org" /x/h/q/y/i/c/e >>C:\Backup.log 2>&1
)
IF EXIST "%LOCALAPPDATA%\HearthstoneDeckTracker\" (
IF EXIST "%UserPath%\LAHSDT\" rd "%UserPath%\LAHSDT" /s/q >>C:\Backup.log 2>&1
xcopy "%LOCALAPPDATA%\HearthstoneDeckTracker" "%UserPath%\LAHSDT" /x/h/q/y/i/c/e >>C:\Backup.log 2>&1
)
IF EXIST "%LOCALAPPDATA%\OpenShell\" (
IF EXIST "%UserPath%\OpenShell\Local_OpenShell\" rd "%UserPath%\OpenShell\Local_OpenShell" /s/q >>C:\Backup.log 2>&1
xcopy "%LOCALAPPDATA%\OpenShell" "%UserPath%\OpenShell\Local_OpenShell" /x/h/q/y/i/c/e >>C:\Backup.log 2>&1
)
IF EXIST "%LOCALAPPDATA%\Popcap Games\" (
IF EXIST "%UserPath%\LA PopCap Games\" rd "%UserPath%\LA PopCap Games" /s/q >>C:\Backup.log 2>&1
xcopy "%LOCALAPPDATA%\PopCap Games" "%UserPath%\LA PopCap Games" /x/h/q/y/i/c/e >>C:\Backup.log 2>&1
)
IF EXIST "%LOCALAPPDATA%\S2\" (
IF EXIST "%userpath%\Applications\S2\" rd "%userpath%\Applications\S2" /s/q >>C:\Backup.log 2>&1
xcopy "%LOCALAPPDATA%\S2" "%userpath%\Applications\S2" /x/h/q/y/i/c/e >>C:\Backup.log 2>&1
)
Rem =============================================================================================================================================
Rem Mozilla Firefox and Thunderbird
Rem =============================================================================================================================================
:L100
Echo Backing up Mozilla Profiles
Echo %time% Backing up Mozilla Program data >>C:\Backup.log 2>&1
IF EXIST "%MozPath%\" (
IF EXIST "%UserPath%\Profiles.old\" rd "%UserPath%\Profiles.old" /s/q >>C:\Backup.log 2>&1
IF EXIST "%UserPath%\Profiles\" ren "%UserPath%\Profiles" Profiles.old >>C:\Backup.log 2>&1
xcopy "%MozPath%" "%UserPath%\Profiles" /x/h/q/y/i/c/e >>C:\Backup.log 2>&1
)
Rem =============================================================================================================================================
Rem Copy hosts file
Rem =============================================================================================================================================
:L110
Echo Backing up Hosts file
Echo %time% Copying Hosts file >>C:\Backup.log 2>&1
IF EXIST "%RootDrv%\Hosts.old" del "%RootDrv%\Hosts.old" /q >>C:\Backup.log 2>&1
IF EXIST "%RootDrv%\Hosts" ren "%RootDrv%\Hosts" Hosts.old >>C:\Backup.log 2>&1
copy "%windir%\system32\drivers\etc\hosts" "%RootDrv%" /y >>C:\Backup.log 2>&1
Rem =============================================================================================================================================
Rem Win Aero Tweaker
Rem =============================================================================================================================================
:L120
Echo Backing up Winaero
Echo %time% Copying Winaero folder >>C:\Backup.log 2>&1
IF EXIST "%SRC%\WinAeroTweaker\" (
IF EXIST "%RootDrv%\WinAeroTweaker\" rd "%RootDrv%\WinAeroTweaker" /s/q >>C:\Backup.log 2>&1
xcopy "%SRC%\WinAeroTweaker" "%RootDrv%\WinAeroTweaker" /x/h/q/y/i/c/e >>C:\Backup.log 2>&1
)
:L900
copy c:\backup.log "%RootDrv%\logs" /y >NUL
del c:\backup.log /q >NUL
Echo Finished
endlocal
Re: Why does this work from a command line but not from a batch file
Fair point, though, I've never had an issue writing file to c:\. Some applications even default to there (DVDFab's junk folders, WinAeroTweaker etc).
Re: Why does this work from a command line but not from a batch file
You have a space character after set AppPath=%UserPath%\Applications
and multiple spaces after set SRC=%cd:~0,2%
Try it with:
set "AppPath=%UserPath%\Applications"
set "SRC=%cd:~0,2%"
FWIW: My advice: organize per application instead of per system part. Makes it better readable and replacing application A with app B becomes much easier.
and multiple spaces after set SRC=%cd:~0,2%
Try it with:
set "AppPath=%UserPath%\Applications"
set "SRC=%cd:~0,2%"
FWIW: My advice: organize per application instead of per system part. Makes it better readable and replacing application A with app B becomes much easier.
Re: Why does this work from a command line but not from a batch file
OMG! How embarrassing. That fixed it.
thanks for the help.
thanks for the help.