I needed to generate a list of folders and their subfolders, I used a simple command for dir command and slapped into a text file.
Below replaced
1 | dir /b /s /a:d "<Location>\*" > <TextFile> |
Credit: SS64
I needed to generate a list of folders and their subfolders, I used a simple command for dir command and slapped into a text file.
Below replaced
1 | dir /b /s /a:d "<Location>\*" > <TextFile> |
Credit: SS64
The following command requests a detailed display of the tasks on the local computer. It uses the /v parameter to request a detailed (verbose) display and the /fo LIST parameter to format the display as a list for easy reading. You can use this command to verify that a task you created has the intended recurrence pattern.
Before running increase the command prompts screen buffer (Right click the Window, go to properties, go to Layout and set the Screen Buffer Height to 9999). If this is not done you will find due to the amount of Windows scheduled tasks, that the tasks you want are cleared from thje screen buffer.
1 | schtasks /query /fo LIST /v |
SchTasks.exe displays a detailed property list for all tasks. I normally will then copy everything into the clipboard (Ctrl + A) and pout it into a text editor, I then delete anything after “Folder: \Microsoft” so I then only have my list of scheduled tasks.
Credit: Technet
For backing up old files I tend to sort into lots of different folders, anything I am finished with I put in a 7zip Archive
The following batch makes use of a For loop in the batch, uses 7-zip with Ultra Compression and names the archive the same as the folder.
1 2 | for /D %%X in (*) do "c:\Program Files\7-Zip\7z.exe" a -mx9 "%%X.7z" "%%X\" pause |
Credits: SS64
We have an issue where on a rare occasion a scan from V1 DBScanner to DBCapture can corrupt the queue and cause DBCapture Admin to state it is unable to open a document rendering the whole application unusable.
I have a batch script to perform some maintenance. Over time I have commented out lines which are not required. I have left my change drive to d script as this is normally where server applications are installed. I have replaced our port with
After the queue is rebuilt the program actually starts the server as normal, in my batch the program is executed in a seperate process and then killed off after 400 seconds (As long as the rebuild is complete then V1 is fine with this, if running line by line press Ctrl + C to close the program instead). Depending on the amount of documents in the queue it may need to be increased.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | ECHO ********************************* ECHO * Restarting DBCapture Services * ECHO ********************************* ECHO ********************************* ECHO * Change to drive D * ECHO ********************************* d: ECHO ********************************* ECHO * Stopping V1 Services * ECHO ********************************* REM net stop DbADepServer REM net stop DbCSArchiveServer-<port> REM net stop DbADepServer-<port> REM net stop DbCSAuthServer-<port> net stop DbCapComms-<port> net stop DbCapOCRServer REM net stop DbCapturePDFFileWatcher net stop DbCSCaptureServer net stop DbCSCaptureServerExport REM net stop DbCheckFilewatcher REM net stop DbLoginServer REM net stop DbWebQLiveCacheClean REM net stop DbArchiveCacheClean ECHO ********************************* ECHO * Rebuild DBCapture Queue * ECHO ********************************* start "DBCapture" "<path to dbcapture communications server>\dbcapcomms.exe" -debug <port> -queueupdate ECHO ********************************* ECHO * Waiting 400 seconds * ECHO ********************************* rem Credit For lower CPU usage, instead of using WAIT use Ping as suggested on http://ss64.com/nt/timeout.html PING -n 401 127.0.0.1>nul ECHO ********************************* ECHO * Kill of DBCapture program * ECHO ********************************* Taskkill /IM "DbCapComms.exe" /F ECHO ********************************* ECHO * Starting V1 Services * ECHO ********************************* REM net start DbLoginServer REM net start DbCapComms-<port> REM net start DbCheckFilewatcher REM net start DbWebQLiveCacheClean REM net start DbArchiveCacheClean REM net start DbADepServer-<port> REM net start DbCSArchiveServer-<port> REM net start DbCSAuthServer-<port> net start DbCapComms-<port> net start DbCapOCRServer REM net start DbCapturePDFFileWatcher net start DbCSCaptureServer net start DbCSCaptureServerExport ECHO ********************************* ECHO * Complete Exiting * ECHO ********************************* EXIT |
Credits:
SS64 for recommending Ping instead of Wait – SS64
Datel Support for providing the command to rebuild the queue – Datel
A while ago we added error trapping to the batch file called by a SQL script, this was to ensure if a program failed the rest of the process would not run:
After ensuring the program would return an error level if something went wrong we then I then used the ErrorLevel and an if statement. If the error level is equal to or greater than 1, I make it go to the end of the file and exit with code 1 (By default its zero which normally means the batch or program executed as expected)
1 2 3 4 5 6 7 8 9 | rem Batch Code here must support returning errors otherwise it will be assumed to have run without issue echo Error Level %ERRORLEVEL% IF ERRORLEVEL GEQ 1 GOTO EOF rem add any further Batch Code here echo Error Level 0 so closing exit :EOF echo Reached End of file due to program error exit /b 1 |
We then modified our existing code in SQL to ensure the batch program is run and the exit code is captured in a variable. It can then be dealt with and the example below can easily be changed to suit whatever is required.
1 2 3 4 5 6 7 8 9 10 11 12 | ---------------------------------------------------------------------------------------------------------- print 'Running Windows Batch Script' ---------------------------------------------------------------------------------------------------------- --Capture the exit code into @result and run the batch script DECLARE @result int EXEC @result = xp_cmdshell '<Patch_to_Batch_Script>' --Only one command can be run in this if statement if more than one required consider a GOTO command! IF (@result = 0) --Run if program ran fine EXEC xp_cmdshell '<Patch_to_Batch_Script>' --Run if program did not run fine ELSE '<Patch_to_Batch_Script>' |
Credits:
SS64
Microsoft MSDN (Example Set C)
I needed to run a scheduled batch job and kill it off after a certain amount of time, this was because the program would run what it needed and then run as normal (If it exists then there is no reason to use start or timeout). As it actually ran as a service I didn’t want to leave it running in this way.
As I use Taskkill on the programs exe name, obviously don’t use it if it will be run on a server where it is running other executables with the same program name.
I replaced timeout with ping as the process launched fully utilises the CPU cores.
1 2 3 4 5 6 7 | ECHO Running the program with start allows the batch script to move on to the next line start "DBCapture" "d:\myprogram.exe" -runparameter1 -runparameter2 ECHO Waiting 120 seconds before killing off the task ECHO Credit For lower CPU usage, instead of using WAIT use Ping as suggested on http://ss64.com/nt/timeout.html PING -n 121 127.0.0.1>nul ECHO Kill the program Taskkill /IM "myprogram.exe" /F |
Credits: I replaced my use of timeout based on a suggestion on SS64.com
This code was used to speed up the setup of SyncToy 2.1 (I see no reason to backup the entire user profile folder, but I hate having to setup multiple sync jobs). As Microsoft has not updated SyncToy it may not work on anything other than Windows 7.
The script expects SyncToy 2.1 is installed and that the destination is always the H drive (For whatever reason I am not using a variable for the main location, I may update this at some point as code to select another path is already in).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | rem Batch Script to setup Synctoy 2.1. Tested on Windows 7 for standard Users. rem Additional Credits https://groups.google.com/forum/#!topic/alt.msdos.batch.nt/kOsN-QIOYEY for on the fly generation of VBS code rem Amended 2/4/2014 to use Contribute instead of Synchronise to prevent unexpected deletions for users being moved servers with an out of date backup. REM Check Windows Version is 7 ver | findstr /i "6\.1\." > nul IF %ERRORLEVEL% EQU 0 goto sub_begincheck goto sub_wrongos :sub_begincheck rem Show Home Drive for troubleshooting purposes rem set homedrive rem show profile directory for troubleshooting purposes rem set userprofile rem If Homedrive is H begin copy if "%homedrive%"=="H:" then Set backupdir=%homedrive% goto :sub_synctoysetup Else rem If Homedrive is not H: ask for new filepath goto :BrowseFolder :sub_synctoysetup rem Create Directories on H: mkdir "H:\LaptopBackup\" mkdir "H:\LaptopBackup\Desktop" mkdir "H:\LaptopBackup\Favorites" mkdir "H:\LaptopBackup\Documents" mkdir "H:\LaptopBackup\Downloads" mkdir "H:\LaptopBackup\Music" mkdir "H:\LaptopBackup\Pictures" mkdir "H:\LaptopBackup\Videos" rem Change drive to C to action copy C: rem Change Directory to Synctoy CD %ProgramFiles%\SyncToy 2.1 rem Setup SyncToy Folders for Windows 7 SyncToy.exe SyncToy.exe -d(left="%USERPROFILE%\Desktop",right="H:\LaptopBackup\Desktop",name=Desktop,operation=Echo) SyncToy.exe -d(left="%USERPROFILE%\Favorites",right="H:\LaptopBackup\Favorites",name=Favorites,operation=Echo) SyncToy.exe -d(left="%USERPROFILE%\Documents",right="H:\LaptopBackup\Documents",name=Docs,operation=Echo) SyncToy.exe -d(left="%USERPROFILE%\Downloads",right="H:\LaptopBackup\Downloads",name=Downloads,operation=Echo) SyncToy.exe -d(left="%USERPROFILE%\Music",right="H:\LaptopBackup\Music",name=Music,operation=Echo) SyncToy.exe -d(left="%USERPROFILE%\Pictures",right="H:\LaptopBackup\Pictures",name=Pictures,operation=Echo) SyncToy.exe -d(left="%USERPROFILE%\Videos",right="H:\LaptopBackup\Videos",name=Videos,operation=Echo) rem Clear Screen to make it easier to view next message CLS rem Copy Complete Echo and Pause ECHO Setup of SyncToy is now Complete. Files are setup to be backed up to H:\LaptopBackup\. Please open SyncToy and run a backup now. PAUSE EXIT :BrowseFolder rem Set Temporary files rem Below is the Visual Basic Script, do not indent! set vbs=%temp%\_.vbs set tmp=%temp%\_.cmd > "%vbs%" echo set WshShell=WScript.CreateObject("WScript.Shell") >>"%vbs%" echo set shell = WScript.CreateObject("Shell.Application") >>"%vbs%" echo set folder=shell.BrowseForFolder(0,"Select Backup Location",0) >>"%vbs%" echo if typename(folder)="Nothing" Then >>"%vbs%" echo wscript.echo "set backupdir=Dialog Cancelled" >>"%vbs%" echo WScript.Quit(1) >>"%vbs%" echo end if >>"%vbs%" echo set folderItems=folder.Items() >>"%vbs%" echo set folderItem=folderItems.Item() >>"%vbs%" echo pathname=folderItem.Path >>"%vbs%" echo wscript.echo "set backupdir="^& chr(34) ^& pathname ^& chr(34) rem Run the script with WSH cscript //nologo "%vbs%" > "%tmp%" rem Read the output file and set Path as Env variable %backupdir% for /f "delims=" %%a in (%tmp%) do %%a rem Clear up DEL %VBS% DEL %TMP% rem Finished now go to copy goto :sub_synctoysetup :sub_wrongos rem Wrong Operating System Detected, echo and exit CLS ECHO This script is only supported on Windows 7. You are running ver PAUSE EXIT :EOF rem End of File Catch for Errors ECHO End of file called! PAUSE EXIT |
Back when my workplace migrated from Windows XP to Windows 7, I became lazy and automated backing up and restoring a users profiles important files in a batch script.
Here I backup to the drive H, this drive is pretty much our standard user drive. If the user does not have a H drive some pretty neat code from https://groups.google.com/forum/#!topic/alt.msdos.batch.nt/kOsN-QIOYEY displays a folder selection box (As annoyingly some users didn’t have their home drive set as H). Although I have set the filepath as LaptopBackup I have used it on Desktops as well.
The code deliberately terminates if it detects it isn’t on Windows 7, this is purely because I haven’t tested this in a network environment on other OS’s!
Known faults are pinned shortcuts in the taskbar don’t appear and printer settings don’t migrate (I never got around to correcting it).
This section of code is to backup to %backupdir%\LaptopBackup\
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | Echo Off rem Batch Script to Copy certain folders for the convenience of Users. The batch file backs up to the H drive, which is a standard drive for user folders. Tested on Windows 7 for standard Users. rem Changed backup folder location to something that is more suitable. Removed printer backup as it doesnt work and added Signature Backup 10/03/2015. rem Additional Credits https://groups.google.com/forum/#!topic/alt.msdos.batch.nt/kOsN-QIOYEY for on the fly generation of VBS code REM Check Windows Version is 7 ver | findstr /i "6\.1\." > nul IF %ERRORLEVEL% EQU 0 goto sub_begincheck goto sub_wrongos :sub_begincheck rem If Homedrive is H begin copy if "%homedrive%"=="H:" goto sub_sethomedrive rem If Homedrive is not H: ask for new filepath ECHO Please select a location to backup the profile, it must be contained in a folder even if on an external drive due to a limiation in this script!!! PAUSE goto BrowseFolder :sub_sethomedrive rem Setup Backupdir variable to homedrive Set backupdir=%homedrive% :sub_begincopy rem Create Directory Structure ECHO Creating Directories mkdir "%backupdir%\LaptopBackup\" mkdir "%backupdir%\LaptopBackup\Desktop" mkdir "%backupdir%\LaptopBackup\Favorites" mkdir "%backupdir%\LaptopBackup\Recent" mkdir "%backupdir%\LaptopBackup\Documents" mkdir "%backupdir%\LaptopBackup\Downloads" mkdir "%backupdir%\LaptopBackup\Outlook" mkdir "%backupdir%\LaptopBackup\Outlook\Application Data" mkdir "%backupdir%\LaptopBackup\Links" mkdir "%backupdir%\LaptopBackup\Music" mkdir "%backupdir%\LaptopBackup\Pictures" mkdir "%backupdir%\LaptopBackup\Videos" mkdir "%backupdir%\LaptopBackup\Contacts" mkdir "%backupdir%\LaptopBackup\SyncToy" mkdir "%backupdir%\LaptopBackup\Sticky Notes" mkdir "%backupdir%\LaptopBackup\OfficeQuickAccess" mkdir "%backupdir%\LaptopBackup\ShortcutsPinned" rem Added Signatures mkdir "%backupdir%\LaptopBackup\Signatures" rem Change drive to C to action copy C: rem Use robocopy to copy specific folders and Echo Folder Copies, amended December 2013 so smaller files copied first and setup on new machine can be started earlier, amended March 2014 to include Quick Access and Pinned Shortcuts ECHO Copying Files and Folders from %LOCALAPPDATA%\Local\Microsoft\Office robocopy "%LOCALAPPDATA%\Microsoft\Office" "%backupdir%\LaptopBackup\OfficeQuickAccess" *.officeUI /MT:6 /R:1 /V /W:1 ECHO Copying Files and Folders from %AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned robocopy "%AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned" "%backupdir%\LaptopBackup\ShortcutsPinned" /S /MT:6 /R:1 /V /W:1 ECHO Copying Files and Folders from %LOCALAPPDATA%\microsoft\synctoy\2.0 robocopy "%LOCALAPPDATA%\microsoft\synctoy\2.0" "%backupdir%\LaptopBackup\SyncToy" /S /MT:6 /R:1 /V /W:1 ECHO Copying Files and Folders from %USERPROFILE%\Application Data\Microsoft\Outlook robocopy "%AppData%\Microsoft\Outlook" "%backupdir%\LaptopBackup\Outlook\Application Data" /S /MT:6 /R:1 /V /W:1 ECHO Copying Files and Folders from %USERPROFILE%\Links robocopy "%USERPROFILE%\Links" "%backupdir%\LaptopBackup\Links" /S /MT:6 /R:1 /V /W:1 ECHO Copying Files and Folders from "%AppData%\Microsoft\Sticky Notes" robocopy "%AppData%\Microsoft\Sticky Notes" "%backupdir%\LaptopBackup\Sticky Notes" /S /MT:6 /R:1 /V /W:1 ECHO Copying Files and Folders from %USERPROFILE%\Favorites robocopy "%USERPROFILE%\Favorites" "%backupdir%\LaptopBackup\Favorites" /S /MT:6 /R:1 /V /W:1 ECHO Copying Files and Folders from %USERPROFILE%\Recent robocopy "%USERPROFILE%\Recent" "%backupdir%\LaptopBackup\Recent" /S /MT:6 /R:1 /V /W:1 ECHO Copying Files and Folders from %AppData%\Microsoft\Signatures robocopy "%AppData%\Microsoft\Signatures" "%backupdir%\LaptopBackup\Signatures" /S /MT:6 /R:1 /V /W:1 ECHO Copying Files and Folders from %USERPROFILE%\Desktop robocopy "%USERPROFILE%\Desktop" "%backupdir%\LaptopBackup\Desktop" /E /MT:6 /R:1 /V /W:1 ECHO Copying Files and Folders from %USERPROFILE%\Documents robocopy "%USERPROFILE%\Documents" "%backupdir%\LaptopBackup\Documents" /E /MT:6 /R:1 /V /W:1 ECHO Copying Files and Folders from %USERPROFILE%\Downloads robocopy "%USERPROFILE%\Downloads" "%backupdir%\LaptopBackup\Downloads" /E /MT:6 /R:1 /V /W:1 ECHO Copying Files and Folders from %USERPROFILE%\Music robocopy "%USERPROFILE%\Music" "%backupdir%\LaptopBackup\Music" /E /MT:6 /R:1 /V /W:1 ECHO Copying Files and Folders from %USERPROFILE%\Pictures robocopy "%USERPROFILE%\Pictures" "%backupdir%\LaptopBackup\Pictures" /E /MT:6 /R:1 /V /W:1 ECHO Copying Files and Folders from %USERPROFILE%\My Videos robocopy "%USERPROFILE%\Videos" "%backupdir%\LaptopBackup\Videos" /E /MT:6 /R:1 /V /W:1 ECHO Saving Printer Settings doesnt work commented out. rem "%windir%\System32\spool\tools\PrintBrm.exe" -B -F %backupdir%\LaptopBackup\Printers.cab rem Clear Screen to make it easier to view next message CLS rem Copy Complete Echo and Pause ECHO Backup copy now complete, please check and ensure your files have been copied in the folder %backupdir% PAUSE EXIT :BrowseFolder rem Set Temporary files rem Below is the Visual Basic Script, do not indent! set vbs=%temp%\_.vbs set tmp=%temp%\_.cmd > "%vbs%" echo set WshShell=WScript.CreateObject("WScript.Shell") >>"%vbs%" echo set shell = WScript.CreateObject("Shell.Application") >>"%vbs%" echo set folder=shell.BrowseForFolder(0,"Select Backup Location",0) >>"%vbs%" echo if typename(folder)="Nothing" Then >>"%vbs%" echo wscript.echo "set backupdir=Dialog Cancelled" >>"%vbs%" echo WScript.Quit(1) >>"%vbs%" echo end if >>"%vbs%" echo set folderItems=folder.Items() >>"%vbs%" echo set folderItem=folderItems.Item() >>"%vbs%" echo pathname=folderItem.Path >>"%vbs%" echo wscript.echo "set backupdir="^& chr(34) ^& pathname ^& chr(34) rem Run the script with WSH cscript //nologo "%vbs%" > "%tmp%" rem Read the output file and set Path as Env variable %backupdir% for /f "delims=" %%a in (%tmp%) do %%a rem Clear up DEL %VBS% DEL %TMP% rem Finished now go to copy goto :sub_begincopy :sub_wrongos rem Wrong Operating System Detected, echo and exit CLS ECHO This script is only supported on Windows 7. You are running rem Use ver command ver PAUSE EXIT :EOF rem End of File Catch for Errors ECHO End of file called! PAUSE EXIT |
This section of code is to restore from %backupdir%\LaptopBackup\
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | Echo Off rem Batch Script to Copy certain folders for the convenience of Users. Tested on Windows 7 for standard Users. rem Removed printer restore as it doesnt work and added Signature Restore 10/03/2015. rem Additional Credits https://groups.google.com/forum/#!topic/alt.msdos.batch.nt/kOsN-QIOYEY for on the fly generation of VBS code REM Check Windows Version is 7 ver | findstr /i "6\.1\." > nul IF %ERRORLEVEL% EQU 0 goto sub_begincheck goto sub_wrongos :sub_begincheck rem If Homedrive is H begin copy if "%homedrive%"=="H:" goto :sub_sethomedrive rem If Homedrive is not H: ask for new filepath ECHO Please select a location to backup the profile, it must be contained in a folder even if on an external drive due to a limiation in this script!!! PAUSE goto BrowseFolder :sub_sethomedrive rem Setup Backupdir variable to homedrive Set backupdir=%homedrive% :sub_begincopy rem Change drive to C to setup local folders C: rem Create Directory Structure mkdir "%AppData%\Microsoft" mkdir "%AppData%\Microsoft\Outlook" mkdir "%AppData%\Microsoft\Signatures" mkdir "%LOCALAPPDATA%\microsoft\synctoy" mkdir "%LOCALAPPDATA%\microsoft\synctoy\2.0" rem Added Sticky Notes 09/09/2013 mkdir "%AppData%\Microsoft\Sticky Notes" rem Added Quick Access and pinned Shortcuts 03/03/2014 mkdir "%LOCALAPPDATA%\Microsoft\Office" mkdir "%AppData%\Microsoft\Internet Explorer" mkdir "%AppData%\Microsoft\Internet Explorer\Quick Launch" rem Use robocopy to copy specific folders and Echo Folder Copies, changed copy order in December 2013 to help get smaller files required for user setup done first. Changed March 2013 to include Office Quick Access and Quick Launch ECHO Copying Files and Folders to %LOCALAPPDATA%\Local\Microsoft\Office robocopy "%backupdir%\LaptopBackup\OfficeQuickAccess" "%LOCALAPPDATA%\Microsoft\Office" *.officeUI /MT:6 /R:1 /V /W:1 ECHO Copying Files and Folders to %AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned robocopy "%backupdir%\LaptopBackup\ShortcutsPinned" "%AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned" /S /MT:6 /R:1 /V /W:1 ECHO Copying Files and Folders to %LOCALAPPDATA%\microsoft\synctoy\2.0 robocopy "%backupdir%\LaptopBackup\SyncToy" "%LOCALAPPDATA%\microsoft\synctoy\2.0" /E /MT:6 /R:2 /V /W:1 ECHO Copying Files and Folders to %USERPROFILE%\Favorites robocopy "%backupdir%\LaptopBackup\Favorites" "%USERPROFILE%\Favorites" /E /MT:6 /R:2 /V /W:1 ECHO Copying Files and Folders to %USERPROFILE%\Links robocopy "%backupdir%\LaptopBackup\Links" "%USERPROFILE%\Links" /E /MT:6 /R:2 /V /W:1 ECHO Copying Files and Folders to %USERPROFILE%\Application Data\Microsoft\Outlook robocopy "%backupdir%\LaptopBackup\Outlook\Application Data" "%AppData%\Microsoft\Outlook" /E /MT:6 /R:2 /V /W:1 ECHO Copy Files and Folder to "%AppData%\Microsoft\Sticky Notes" robocopy "%backupdir%\LaptopBackup\Sticky Notes" "%AppData%\Microsoft\Sticky Notes" /E /MT:6 /R:2 /V /W:1 ECHO Copying Files and Folders from %AppData%\Microsoft\Signatures robocopy "%backupdir%\LaptopBackup\Signatures" "%AppData%\Microsoft\Signatures" /S /MT:6 /R:1 /V /W:1 ECHO Copying Files and Folders to %USERPROFILE%\Desktop robocopy "%backupdir%\LaptopBackup\Desktop" "%USERPROFILE%\Desktop" /E /MT:6 /R:2 /V /W:1 ECHO Copying Files and Folders to %AppData%\Microsoft\Windows\Recent robocopy "%backupdir%\LaptopBackup\Recent" "%AppData%\Microsoft\Windows\Recent" /E /MT:6 /R:2 /V /W:1 ECHO Copying Files and Folders to %USERPROFILE%\Documents robocopy "%backupdir%\LaptopBackup\Documents" "%USERPROFILE%\Documents" /E /MT:6 /R:2 /V /W:1 ECHO Copying Files and Folders to %USERPROFILE%\Downloads robocopy "%backupdir%\LaptopBackup\Downloads" "%USERPROFILE%\Downloads" /E /MT:6 /R:2 /V /W:1 ECHO Copying Files and Folders to %USERPROFILE%\My Music robocopy "%backupdir%\LaptopBackup\Music" "%USERPROFILE%\Music" /E /MT:6 /R:2 /V /W:1 ECHO Copying Files and Folders to %USERPROFILE%\Pictures robocopy "%backupdir%\LaptopBackup\Pictures" "%USERPROFILE%\Pictures" /E /MT:6 /R:2 /V /W:1 ECHO Copying Files and Folders to %USERPROFILE%\Videos robocopy "%backupdir%\LaptopBackup\Videos" "%USERPROFILE%\Videos" /E /MT:6 /R:2 /V /W:1 REM Added Sticky Notes and Printer Restore rem ECHO Restoring Printer Settings, this may take a while! rem "%windir%\System32\spool\tools\PrintBrm.exe" -R -F %backupdir%\LaptopBackup\Printers.cab rem Clear Screen to make it easier to view next message CLS rem Copy Complete Echo and Pause ECHO Your files from your previous machine have now been restored. ECHO Please ensure you see all your files. PAUSE EXIT :BrowseFolder rem Set Temporary files rem Below is the Visual Basic Script, do not indent! set vbs=%temp%\_.vbs set tmp=%temp%\_.cmd > "%vbs%" echo set WshShell=WScript.CreateObject("WScript.Shell") >>"%vbs%" echo set shell = WScript.CreateObject("Shell.Application") >>"%vbs%" echo set folder=shell.BrowseForFolder(0,"Select Backup Location",0) >>"%vbs%" echo if typename(folder)="Nothing" Then >>"%vbs%" echo wscript.echo "set backupdir=Dialog Cancelled" >>"%vbs%" echo WScript.Quit(1) >>"%vbs%" echo end if >>"%vbs%" echo set folderItems=folder.Items() >>"%vbs%" echo set folderItem=folderItems.Item() >>"%vbs%" echo pathname=folderItem.Path >>"%vbs%" echo wscript.echo "set backupdir="^& chr(34) ^& pathname ^& chr(34) rem Run the script with WSH cscript //nologo "%vbs%" > "%tmp%" rem Read the output file and set Path as Env variable %backupdir% for /f "delims=" %%a in (%tmp%) do %%a rem Clear up DEL %VBS% DEL %TMP% rem Finished now go to copy goto :sub_begincopy :sub_wrongos rem Wrong Operating System Detected, echo and exit CLS ECHO This script is only supported on Windows 7. You are running ver PAUSE EXIT :EOF rem End of File Catch for Errors ECHO End of file called! PAUSE EXIT |
Update August 2017. I have found Windows 10 Sticky Notes needs to be moved to a different location so data can be imported, the below has been added as where I work is currently planning to migrate from Windows 7 to Windows 10.
Further amendments may be needed and obviously the backup script above doesn’t account for the new data location for Sticky Notes.
Corrected restore location of restore script April 2018 (Whoops)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | Echo Off rem Checked to work against Windows 10, stickynotes amended to account for changes rem Additional Credits https://groups.google.com/forum/#!topic/alt.msdos.batch.nt/kOsN-QIOYEY for on the fly generation of VBS code REM Check Windows Version is 10 ver | findstr /i "10\.0\." > nul IF %ERRORLEVEL% EQU 0 goto sub_begincheck goto sub_wrongos :sub_begincheck rem If Homedrive is H begin copy if "%homedrive%"=="H:" goto :sub_sethomedrive rem If Homedrive is not H: ask for new filepath ECHO Please select a location to backup the profile, it must be contained in a folder even if on an external drive due to a limiation in this script!!! PAUSE goto BrowseFolder :sub_sethomedrive rem Setup Backupdir variable to homedrive Set backupdir=%homedrive% :sub_begincopy rem Change drive to C to setup local folders C: rem Create Directory Structure mkdir "%AppData%\Microsoft" mkdir "%AppData%\Microsoft\Outlook" mkdir "%AppData%\Microsoft\Signatures" mkdir "%LOCALAPPDATA%\microsoft\synctoy" mkdir "%LOCALAPPDATA%\microsoft\synctoy\2.0" rem Added Sticky Notes 09/09/2013 rem mkdir "%AppData%\Microsoft\Sticky Notes" rem http://www.winhelponline.com/blog/recover-backup-sticky-notes-data-file-windows-10/ mkdir "%LocalAppData%\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState\Legacy" rem Added Quick Access and pinned Shortcuts 03/03/2014 mkdir "%LOCALAPPDATA%\Microsoft\Office" mkdir "%AppData%\Microsoft\Internet Explorer" mkdir "%AppData%\Microsoft\Internet Explorer\Quick Launch" rem Use robocopy to copy specific folders and Echo Folder Copies, changed copy order in December 2013 to help get smaller files required for user setup done first. Changed March 2013 to include Office Quick Access and Quick Launch ECHO Copying Files and Folders to %LOCALAPPDATA%\Local\Microsoft\Office robocopy "%backupdir%\LaptopBackup\OfficeQuickAccess" "%LOCALAPPDATA%\Microsoft\Office" *.officeUI /MT:6 /R:1 /V /W:1 ECHO Copying Files and Folders to %AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned robocopy "%backupdir%\LaptopBackup\ShortcutsPinned" "%AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned" /S /MT:6 /R:1 /V /W:1 ECHO Copying Files and Folders to %LOCALAPPDATA%\microsoft\synctoy\2.0 robocopy "%backupdir%\LaptopBackup\SyncToy" "%LOCALAPPDATA%\microsoft\synctoy\2.0" /E /MT:6 /R:2 /V /W:1 ECHO Copying Files and Folders to %USERPROFILE%\Favorites robocopy "%backupdir%\LaptopBackup\Favorites" "%USERPROFILE%\Favorites" /E /MT:6 /R:2 /V /W:1 ECHO Copying Files and Folders to %USERPROFILE%\Links robocopy "%backupdir%\LaptopBackup\Links" "%USERPROFILE%\Links" /E /MT:6 /R:2 /V /W:1 ECHO Copying Files and Folders to %USERPROFILE%\Application Data\Microsoft\Outlook robocopy "%backupdir%\LaptopBackup\Outlook\Application Data" "%AppData%\Microsoft\Outlook" /E /MT:6 /R:2 /V /W:1 ECHO Copy Files and Folder to "%LocalAppData%\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState\Legacy" rem Modified for Windows 10 where the folder has changed and the file must bhe imported via a Legavy Folder copy "%backupdir%\LaptopBackup\Sticky Notes\StickyNotes.snt" "%LocalAppData%\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState\Legacy\ThresholdNotes.snt" /MT:6 /R:2 /V /W:1 ECHO Copying Files and Folders from %AppData%\Microsoft\Signatures robocopy "%backupdir%\LaptopBackup\Signatures" "%AppData%\Microsoft\Signatures" /S /MT:6 /R:1 /V /W:1 ECHO Copying Files and Folders to %USERPROFILE%\Desktop robocopy "%backupdir%\LaptopBackup\Desktop" "%USERPROFILE%\Desktop" /E /MT:6 /R:2 /V /W:1 ECHO Copying Files and Folders to %AppData%\Microsoft\Windows\Recent robocopy "%backupdir%\LaptopBackup\Recent" "%AppData%\Microsoft\Windows\Recent" /E /MT:6 /R:2 /V /W:1 ECHO Copying Files and Folders to %USERPROFILE%\Documents robocopy "%backupdir%\LaptopBackup\Documents" "%USERPROFILE%\Documents" /E /MT:6 /R:2 /V /W:1 ECHO Copying Files and Folders to %USERPROFILE%\Downloads robocopy "%backupdir%\LaptopBackup\Downloads" "%USERPROFILE%\Downloads" /E /MT:6 /R:2 /V /W:1 ECHO Copying Files and Folders to %USERPROFILE%\My Music robocopy "%backupdir%\LaptopBackup\Music" "%USERPROFILE%\Music" /E /MT:6 /R:2 /V /W:1 ECHO Copying Files and Folders to %USERPROFILE%\Pictures robocopy "%backupdir%\LaptopBackup\Pictures" "%USERPROFILE%\Pictures" /E /MT:6 /R:2 /V /W:1 ECHO Copying Files and Folders to %USERPROFILE%\Videos robocopy "%backupdir%\LaptopBackup\Videos" "%USERPROFILE%\Videos" /E /MT:6 /R:2 /V /W:1 REM Added Sticky Notes and Printer Restore rem ECHO Restoring Printer Settings, this may take a while! rem "%windir%\System32\spool\tools\PrintBrm.exe" -R -F %backupdir%\LaptopBackup\Printers.cab rem Clear Screen to make it easier to view next message CLS rem Copy Complete Echo and Pause ECHO Your files from your previous machine have now been restored. ECHO Please ensure you see all your files. PAUSE EXIT :BrowseFolder rem Set Temporary files rem Below is the Visual Basic Script, do not indent! set vbs=%temp%\_.vbs set tmp=%temp%\_.cmd > "%vbs%" echo set WshShell=WScript.CreateObject("WScript.Shell") >>"%vbs%" echo set shell = WScript.CreateObject("Shell.Application") >>"%vbs%" echo set folder=shell.BrowseForFolder(0,"Select Backup Location",0) >>"%vbs%" echo if typename(folder)="Nothing" Then >>"%vbs%" echo wscript.echo "set backupdir=Dialog Cancelled" >>"%vbs%" echo WScript.Quit(1) >>"%vbs%" echo end if >>"%vbs%" echo set folderItems=folder.Items() >>"%vbs%" echo set folderItem=folderItems.Item() >>"%vbs%" echo pathname=folderItem.Path >>"%vbs%" echo wscript.echo "set backupdir="^& chr(34) ^& pathname ^& chr(34) rem Run the script with WSH cscript //nologo "%vbs%" > "%tmp%" rem Read the output file and set Path as Env variable %backupdir% for /f "delims=" %%a in (%tmp%) do %%a rem Clear up DEL %VBS% DEL %TMP% rem Finished now go to copy goto :sub_begincopy :sub_wrongos rem Wrong Operating System Detected, echo and exit CLS ECHO This script is only supported on Windows 10. You are running ver PAUSE EXIT :EOF rem End of File Catch for Errors ECHO End of file called! PAUSE EXIT |