Batch files!
Hey all,
Yes, about 15 years behind everyone else, recently I have discovered batch files!
I recall doing one a few months ago, but now I seem stuck...
All I want to do is copy the bookmark.html file:
"C:\Documents and Settings\Owner1\Application Data\Mozilla\Profiles\default\eh0f12ts.slt\bookmark.html"
From its current location to a new location, say the route of a different hdd, like D: (or pretty much anywhere)
In cmd prompt:
C:\Documents and Settings\Owner1>xcopy "C:\Documents and Settings\Owner1\Application Data\Mozilla\Profiles\default\eh0f12ts.slt\bookmark.html" c:\test\ffmarks
Works fine, so as I understand it, batch files are basically this in notepad with the ext of .bat ?
What else do i need to do in notepad to make it work!!?!
Yes, about 15 years behind everyone else, recently I have discovered batch files!
I recall doing one a few months ago, but now I seem stuck...
All I want to do is copy the bookmark.html file:
"C:\Documents and Settings\Owner1\Application Data\Mozilla\Profiles\default\eh0f12ts.slt\bookmark.html"
From its current location to a new location, say the route of a different hdd, like D: (or pretty much anywhere)
In cmd prompt:
C:\Documents and Settings\Owner1>xcopy "C:\Documents and Settings\Owner1\Application Data\Mozilla\Profiles\default\eh0f12ts.slt\bookmark.html" c:\test\ffmarks
Works fine, so as I understand it, batch files are basically this in notepad with the ext of .bat ?
What else do i need to do in notepad to make it work!!?!
0
Comments
Yes, that is backing up my firefox bookmarks.
Ill give that tool a look.
This was more a 'can i do this using a batch file' kinda thing, as im sure being a part time sys admin, batch files will come in useful for me!
Ill defo investigate it on a 'slow' day though
Thanks again Thrax
1. Close MS Outlook (IF it is open)
2. Copy Outlook.pst from local machine to network drive
3. Have this automatically run on shutdown
http://www.publicshareware.com/public-share-outlook-utilities.html
so presumably once that runs i can run a simple batch to copy .pst....
now i need to see how i can get this to run at shutdown (and midnight for those who don't turn their pc's off...)
:START COLOR 09 COPY \\XXXXXXXXX\UPDATE$\SLEEP.EXE C:\Windows\System32 /Y COPY \\XXXXXXXXX\UPDATE$\robocopy.EXE C:\Windows\System32 /Y @ECHO OFF CLS Title Windows Migration Automoton v1.5 ECHO. ECHO What is your EUID? FOR /F "tokens=5* delims= " %%A IN ('VOL C: ^| FIND "drive C"') DO SET OLDLABEL=%%B FOR /F "TOKENS=*" %%? IN ('LABEL C: 2^>NUL') DO SET EUID=%%? SET %EUID LABEL C: %OLDLABEL% ECHO. ECHO. ECHO. ECHO This will Select the server you wish to use. ECHO type the name of the server [NO \\]. Example: ES2USMT01 ECHO. FOR /F "tokens=5* delims= " %%A IN ('VOL C: ^| FIND "drive C"') DO SET OLDLABEL=%%B ECHO What is the destination server?: FOR /F "TOKENS=*" %%? IN ('LABEL C: 2^>NUL') DO SET server=%%? SET %server LABEL C: %OLDLABEL% ECHO. ECHO. ECHO. ECHO This will Select the share you wish to use. ECHO type the name of the servers full path to the share. Example: usmt$ ECHO. FOR /F "tokens=5* delims= " %%A IN ('VOL C: ^| FIND "drive C"') DO SET OLDLABEL=%%B ECHO What is the destination server share?: FOR /F "TOKENS=*" %%? IN ('LABEL C: 2^>NUL') DO SET share=%%? SET %share LABEL C: %OLDLABEL% ECHO. ECHO. ECHO. ECHO This will create the destination folder. ECHO Enter the Destination Folder name [NO SPACES] ECHO. FOR /F "tokens=5* delims= " %%A IN ('VOL C: ^| FIND "drive C"') DO SET OLDLABEL=%%B ECHO What is the Destination Folder: FOR /F "TOKENS=*" %%? IN ('LABEL C: 2^>NUL') DO SET Folder=%%? SET %Folder LABEL C: %OLDLABEL% ECHO. ECHO. Echo your list of available drives to back up are: Echo ------------------------------------------------- IF EXIST C:\ Echo C drive available IF EXIST D:\ Echo D drive available IF EXIST E:\ Echo E drive available IF EXIST F:\ Echo F drive available IF EXIST G:\ Echo G drive available IF EXIST I:\ Echo H drive available ECHO. Echo ---Drives below here may be network drves--- ECHO. IF EXIST J:\ Echo J drive available IF EXIST K:\ Echo K drive available IF EXIST L:\ Echo L drive available IF EXIST M:\ Echo M drive available IF EXIST N:\ Echo N drive available IF EXIST O:\ Echo O drive available IF EXIST P:\ Echo P drive available IF EXIST Q:\ Echo Q drive available IF EXIST R:\ Echo R drive available IF EXIST S:\ Echo S drive available IF EXIST T:\ Echo T drive available IF EXIST U:\ Echo U drive available IF EXIST V:\ Echo V drive available IF EXIST W:\ Echo W drive available IF EXIST X:\ Echo X drive available IF EXIST Y:\ Echo Y drive available IF EXIST Z:\ Echo Z drive available Echo ------------------------------------------------- ECHO. ECHO This will backup the specific drive. ECHO All that is required is the Drive Letter ECHO. FOR /F "tokens=5* delims= " %%A IN ('VOL C: ^| FIND "drive C"') DO SET OLDLABEL=%%B ECHO What is the Users EUID?: FOR /F "TOKENS=*" %%? IN ('LABEL C: 2^>NUL') DO SET DRIVE=%%? SET %DRIVE LABEL C: %OLDLABEL% ECHO. ECHO. IF EXIST Q:\ GOTO :MAPEXIST IF NOT EXIST Q:\ GOTO :MAPNOTEXIST :MAPNOTEXIST ECHO ---------------------------------------- net use Q: \\%server%\%share% ECHO ---------------------------------------- ECHO. sleep 7 IF EXIST Q:\ goto :Continue IF NOT EXIT Q:\ goto :Mispell :Continue IF EXIST "Q:\%FOLDER%\%DRIVE%_Backup" GOTO :EXIST IF NOT EXIST "Q:\%FOLDER%\%DRIVE%_Backup\%DRIVE%_Backup" GOTO :COPY :COPY CD %drive%:\ REM MD "Q:\%FOLDER%\%DRIVE%_Backup\ROOT" MD "Q:\%FOLDER%\%DRIVE%_Backup\Documents and Settings" robocopy.exe "%drive%:\Documents and Settings" "Q:\%FOLDER%\%DRIVE%_Backup\Documents and Settings" /ETA /A-:H /S /E /XX /LOG+:"Q:\%FOLDER%\%DRIVE%_Backup\ROBO-LOG.TXT" /TEE /R:5 /W:2 /XF NTUSER*.* *.OST USRCLASS*.* /XD "%drive%:\Documents and Settings\Administrator" "%drive%:\Documents and Settings\All Users" "%drive%:\Documents and Settings\LocalService" "%drive%:\Documents and Settings\NetworkService" "%drive%:\Documents and Settings\Default User" "%drive%:\Documents and Settings\SiteOps" "%drive%:\Documents and Settings\siteops.COF" "%drive%:\Documents and Settings\Setup" "%drive%:\Documents and Settings\vud611\Local Settings\Temp " robocopy.exe "%DRIVE%:" "Q:\%FOLDER%\%DRIVE%_Backup" /ETA /S /A-:H /E /XX /LOG+:"Q:\%FOLDER%\%DRIVE%_Backup\ROBO-LOG.TXT" /TEE /R:5 /W:2 /XF NTUSER*.* *.COM *.BOT *.DAT NTLDR *.BAT "%drive%:\pagefile.sys" "hiberfil.sys" *.sys /XD "%drive%:\Documents and Settings" "%drive%:\SWSetup" "%drive%:\Program Files" "%drive%:\Windows" "%drive%:\Drivers" "%drive%:\RECYCLER" "%drive%:\System Volume Information" "%drive%:\Temp" "%drive%:\Config.Msi" GOTO :QA :QA IF EXIST "\\XXXX\QA$\%EUID%_%DRIVE%_Backup.TXT" GOTO :YES IF NOT EXIST "\\XXXXX\QA$\%EUID%_%DRIVE%_Backup.TXT" GOTO :NO :YES DATE /T >> "\\XXXX\QA$\%EUID%_%DRIVE%_Backup.TXT" TIME /T >> "\\XXXX\QA$\%EUID%_%DRIVE%_Backup.TXT" ECHO %server%\%SHARE%\%DRIVE%_Backup >> "\\XXXX\QA$\%EUID%_%DRIVE%_Backup.TXT" ECHO _______________ >> "\\XXXX\QA$\%EUID%_%DRIVE%_Backup.TXT" GOTO :END :NO DATE /T > "\\XXXX\QA$\%EUID%_%DRIVE%_Backup.TXT" TIME /T >> "\\XXXX\QA$\%EUID%_%DRIVE%_Backup.TXT" ECHO %server%\%SHARE%\%DRIVE%_Backup >> "\\XXXX\QA$\%EUID%_%DRIVE%_Backup.TXT" ECHO _______________ >> "\\XXXX\QA$\%EUID%_%DRIVE%_Backup.TXT" GOTO :END :EXIST Echo. Echo The EUID folder already exists. type nul>%temp%\~YesOrNo.tmp Echo. Echo Do you wish to continue to copy? Echo This could add files to unwanted locations (Y/N). del /p %temp%\~YesOrNo.tmp>nul if not exist %temp%\~YesOrNo.tmp goto :Yes Echo Selected "No" del %temp%\~YesOrNo.tmp goto :end :Yes GOTO :COPY :end call Q:\%FOLDER%\%DRIVE%_Backup\ROBO-LOG.TXT net use Q: /delete LABEL C: Local Disk exit :MAPEXIST Echo. Echo There is a conflict with the drive mapping. Echo The drive letter used by this program to copy Echo Q:\ is already mapped to a location. Echo The Drive letter is taken. type nul>%temp%\~YesOrNo.tmp Echo. Echo Do you wish to continue to use the Q:\ as the file destination? Echo This could add files to unwanted locations (Y/N). del /p %temp%\~YesOrNo.tmp>nul if not exist %temp%\~YesOrNo.tmp goto ::MAPNOTEXIST Echo Selected "No" del %temp%\~YesOrNo.tmp goto :QUITQEXIST :Mispell color 17 Echo. Echo Something entered was incorrect and must be re-entered in order to continue. Echo Please restart the copy program, and ensure that the %drive%:\ is accessable Echo. LABEL C: Local Disk pause exit :QUITQEXIST REM call Q:\%FOLDER%\%DRIVE%_Backup\ROBO-LOG.TXT REM net use Q: /delete LABEL C: Local Disk exitheres a sample of my latest creation, still not at 100%, what it does is first copies the required files to the local machine from my machine. then it asks for an EUID ( aka login name, some unique identifier ) then it asks what machine you want to back data up to, then it asks for the machines share folder name, then the big list there will show you the available drives on the local machine you can choose to backup to the servers share point. it will go to the servers share point and create a folder with the variable %FOLDER% and dredge the hard drive or any files that dont meet the exclude criteria. it creates a log file with it, then after that it contacts another one of my servers and creates a quality assurance file with the user who ran it, when, and where the data was copied to.
i designed it to copy all of your files ther are not currently open, to a server, inside of windows. im still tinkering with it.
\\edit\\ heh there are a few typos in there, ill repost it when i have it done.
Thats pretty damn impressive looking Armo...
A whole world apart from what I could/can do!
:START COLOR A0 @ECHO OFF COPY \\XXXX\UPDATE$\SLEEP.EXE C:\Windows\System32 /Y COPY \\XXXX\UPDATE$\robocopy.EXE C:\Windows\System32 /Y CLS Title Windows Migration Automoton v1.5 ECHO. ECHO What is your EUID? FOR /F "tokens=5* delims= " %%A IN ('VOL C: ^| FIND "drive C"') DO SET OLDLABEL=%%B FOR /F "TOKENS=*" %%? IN ('LABEL C: 2^>NUL') DO SET EUID=%%? SET %EUID LABEL C: %OLDLABEL% ECHO. ECHO. ECHO. ECHO This will Select the server you wish to use. ECHO type the name of the server [NO \\]. Example: ES2USMT01 ECHO. FOR /F "tokens=5* delims= " %%A IN ('VOL C: ^| FIND "drive C"') DO SET OLDLABEL=%%B ECHO What is the destination server?: FOR /F "TOKENS=*" %%? IN ('LABEL C: 2^>NUL') DO SET server=%%? SET %server LABEL C: %OLDLABEL% ECHO. ECHO. ECHO. ECHO This will Select the share you wish to use. ECHO type the name of the shared folder only. Example: usmt$ ECHO. FOR /F "tokens=5* delims= " %%A IN ('VOL C: ^| FIND "drive C"') DO SET OLDLABEL=%%B ECHO What is the destination server share?: FOR /F "TOKENS=*" %%? IN ('LABEL C: 2^>NUL') DO SET share=%%? SET %share LABEL C: %OLDLABEL% ECHO. ECHO. ECHO. ECHO This will create the destination folder. ECHO Enter the Destination Folder name [NO SPACES] ECHO. FOR /F "tokens=5* delims= " %%A IN ('VOL C: ^| FIND "drive C"') DO SET OLDLABEL=%%B FOR /F "TOKENS=*" %%? IN ('LABEL C: 2^>NUL') DO SET Folder=%%? SET %Folder LABEL C: %OLDLABEL% ECHO. ECHO. Echo your list of available drives to back up are: Echo ------------------------------------------------- IF EXIST C:\ Echo C drive available IF EXIST D:\ Echo D drive available IF EXIST E:\ Echo E drive available IF EXIST F:\ Echo F drive available IF EXIST G:\ Echo G drive available IF EXIST I:\ Echo H drive available ECHO. Echo ---Drives below here may be network drves--- ECHO. IF EXIST J:\ Echo J drive available IF EXIST K:\ Echo K drive available IF EXIST L:\ Echo L drive available IF EXIST M:\ Echo M drive available IF EXIST N:\ Echo N drive available IF EXIST O:\ Echo O drive available IF EXIST P:\ Echo P drive available IF EXIST Q:\ Echo Q drive available IF EXIST R:\ Echo R drive available IF EXIST S:\ Echo S drive available IF EXIST T:\ Echo T drive available IF EXIST U:\ Echo U drive available IF EXIST V:\ Echo V drive available IF EXIST W:\ Echo W drive available IF EXIST X:\ Echo X drive available IF EXIST Y:\ Echo Y drive available IF EXIST Z:\ Echo Z drive available Echo ------------------------------------------------- ECHO. ECHO This will backup all of the contents of a specific drive. ECHO All that is required is the Drive Letter ECHO. FOR /F "tokens=5* delims= " %%A IN ('VOL C: ^| FIND "drive C"') DO SET OLDLABEL=%%B ECHO What Drive do you wish to backup?: FOR /F "TOKENS=*" %%? IN ('LABEL C: 2^>NUL') DO SET DRIVE=%%? SET %DRIVE LABEL C: %OLDLABEL% ECHO. ECHO. IF EXIST Q:\ GOTO :MAPEXIST IF NOT EXIST Q:\ GOTO :MAPNOTEXIST :MAPNOTEXIST ECHO ---------------------------------------- net use Q: \\%server%\%share% ECHO ---------------------------------------- ECHO. sleep 7 :MAPNOTEXIST1 IF EXIST Q:\ goto :Continue IF NOT EXIT Q:\ goto :Mispell :Continue IF EXIST "Q:\%FOLDER%\%DRIVE%_Backup" GOTO :EXIST IF NOT EXIST "Q:\%FOLDER%\%DRIVE%_Backup\%DRIVE%_Backup" GOTO :CHECKC :CHECKC IF /I %DRIVE% == C goto :COPY IF NOT %DRIVE% == C goto :COPYROOT :COPY CD %drive%:\ REM MD "Q:\%FOLDER%\%DRIVE%_Backup\ROOT" MD "Q:\%FOLDER%\%DRIVE%_Backup\Documents and Settings" GOTO :COPYC :COPYROOT CD %drive%:\ MD "Q:\%FOLDER%\%DRIVE%_Backup" GOTO :COPYROOT1 :COPYC robocopy.exe "%drive%:\Documents and Settings" "Q:\%FOLDER%\%DRIVE%_Backup\Documents and Settings" /ETA /A-:H /S /E /XX /LOG+:"Q:\%FOLDER%\%DRIVE%_Backup\ROBO-LOG.TXT" /TEE /R:5 /W:2 /XF NTUSER*.* *.OST USRCLASS*.* /XD "%drive%:\Documents and Settings\Administrator" "%drive%:\Documents and Settings\All Users" "%drive%:\Documents and Settings\LocalService" "%drive%:\Documents and Settings\NetworkService" "%drive%:\Documents and Settings\Default User" "%drive%:\Documents and Settings\SiteOps" "%drive%:\Documents and Settings\siteops.COF" "%drive%:\Documents and Settings\Setup" "%drive%:\Documents and Settings\vud611\Local Settings\Temp" GOTO :COPYROOT :COPYROOT1 robocopy.exe "%DRIVE%:" "Q:\%FOLDER%\%DRIVE%_Backup" /ETA /S /A-:H /E /XX /LOG+:"Q:\%FOLDER%\%DRIVE%_Backup\ROBO-LOG.TXT" /TEE /R:5 /W:2 /XF NTUSER*.* *.COM *.BOT *.DAT NTLDR *.BAT "%drive%:\pagefile.sys" "hiberfil.sys" *.sys /XD "%drive%:\Documents and Settings" "%drive%:\SWSetup" "%drive%:\Program Files" "%drive%:\Windows" "%drive%:\Drivers" "%drive%:\RECYCLER" "%drive%:\System Volume Information" "%drive%:\Temp" "%drive%:\Config.Msi" GOTO :QA :QA IF EXIST "\\XXXX\QA$\%EUID%_%DRIVE%_Backup.TXT" GOTO :YES IF NOT EXIST "\\XXXX\QA$\%EUID%_%DRIVE%_Backup.TXT" GOTO :NO :YES DATE /T >> "\\XXXX\QA$\%EUID%_%DRIVE%_Backup.TXT" TIME /T >> "\\XXXX\QA$\%EUID%_%DRIVE%_Backup.TXT" ECHO %server%\%SHARE%\%DRIVE%_Backup >> "\\tp2repair\QA$\%EUID%_%DRIVE%_Backup.TXT" ECHO _______________ >> "\\tp2repair\QA$\%EUID%_%DRIVE%_Backup.TXT" GOTO :END :NO DATE /T > "\\XXXX\QA$\%EUID%_%DRIVE%_Backup.TXT" TIME /T >> "\\XXXX\QA$\%EUID%_%DRIVE%_Backup.TXT" ECHO %server%\%SHARE%\%DRIVE%_Backup >> "\\XXXX\QA$\%EUID%_%DRIVE%_Backup.TXT" ECHO _______________ >> "\\XXXX\QA$\%EUID%_%DRIVE%_Backup.TXT" GOTO :END :EXIST Echo. Echo The EUID folder already exists. type nul>%temp%\~YesOrNo.tmp Echo. Echo Do you wish to continue to copy? Echo This could add files to unwanted locations (Y/N). del /p %temp%\~YesOrNo.tmp>nul if not exist %temp%\~YesOrNo.tmp goto :Yes Echo Selected "No" del %temp%\~YesOrNo.tmp goto :end :Yes GOTO :CHECKC :end call Q:\%FOLDER%\%DRIVE%_Backup\ROBO-LOG.TXT net use Q: /delete LABEL C: Local Disk sleep 2 exit :MAPEXIST Echo. Echo There is a conflict with the drive mapping. Echo The drive letter used by this program to copy Echo Q:\ is already mapped to a location. Echo The Drive letter is taken. type nul>%temp%\~YesOrNo.tmp Echo. Echo Do you wish to continue to use the Q:\ as the file destination? Echo This could add files to unwanted locations (Y/N). del /p %temp%\~YesOrNo.tmp>nul if not exist %temp%\~YesOrNo.tmp goto :MAPNOTEXIST1 Echo Selected "No" del %temp%\~YesOrNo.tmp goto :QUITQEXIST :Mispell color 17 Echo. Echo You have either mistyped a variable name, or do not have rights to it. Echo Please restart the copy program, and ensure that the %drive%:\ is accessable Echo. LABEL C: Local Disk pause exit :QUITQEXIST REM call Q:\%FOLDER%\%DRIVE%_Backup\ROBO-LOG.TXT REM net use Q: /delete LABEL C: Local Disk exitok i finnally finished. now it maps the drive its going to copy to AFTER yu choose what drive you want to back up, lol. Its smart enough to determine if its the C:\ or a diffrent drive, so it wont create folders that are out of place. It can determine if theres already a drive mapped to the letter the program uses to copy to a server. XXXX represents PC names that i dont want to give out. but if you want to play with it, get a copy of SLEEP.EXE and ROBOCOPY.EXE and put them in C:\windows\System32and be careful to what server and share name you use. it will completly close out with out warning if you try to copy to a location to dont have rights to.