Batch Command useing Else IF to terminate program before bak

January 1, 2013 at 12:09:21
Specs: Windows XP

Hey All, (web found) how to make a Batch For backing up a director (ie. Chrome).
I'm using the native Windows Schedule Task Mgr. to ping, run the file (working great).
However, if I go to bed (forgetting to shut down chrome)--naturally don't get a full backup.

Therefore, I added the else if--HOWEVER---if I *DO* shut down Chrome (the file runs, but it's rather "Dirty"---How can I add an "IF NOT"--do I nest it inside the else if?

Here's what I'm running, again it works (regardless of if Chrome is shut down or not)--but not "Clean"---would like to0 make it clean (ie...showing error "Chrome does not Exist).

PS-if curious, reason not pinging the loop back is because several other backup programs use it, so don't want to ping it when they're using it.


...............................................................

IF EXIST CHROME COMMAND (

set drive=C:
echo ### Killing Chrome Task...
taskkill /F /IM chrome.exe /T
PING 1.1.1.1 -n 1 -w 60000 >NUL

)

ELSE (

:: variables
set drive=E:\BrowserBackups\Chrome
set folder=%DATE:~4,2%_%DATE:~7,2%_%DATE:~10,4%_%RANDOM%
set backupcmd=xcopy /C/E/H/I/R/K/Y

echo ### Backing up directory...
%backupcmd% "%USERPROFILE%\Local Settings\Application Data\Google\Chrome" "%drive%\%folder%"

)

pause
>>>>>>>>>>>>>>>>>>>>>>>>>>

Not sure where to put the "IF NOT EXIST COMMAND"--THANK YOU!!!



See More: Batch Command useing Else IF to terminate program before bak

Report •


#1
January 1, 2013 at 18:55:08

I'm somewhat confused... I guess that "if exist chrome command" is throwing me off. I don't understand that syntax - how does that work? I thought "if exist" just tested for the presence of a file, not a running process?
Oh well, here's how I think you want things to work, but I may be way out of orbit (using pseudo script)
if (chrome is running) (
taskkill chrome
wait 60 seconds "safety"
) else (echo chrome was already asleep)

:backup
set vars
do backup stuff
::======== end
I guess you want to do backup regardless, so it should not be inside the IF.
All the IF does is test for chrome process, shut it down if running, and display a message if it's not. Tasklist is the way I usually test for any given process.


Report •

#2
January 2, 2013 at 13:53:21

I would just add a goto function at the end of the "IF". "IF" the function happens it would skip the "ELSE" part. Otherwise in theory it would skip the "IF" and run the "ELSE"

goto skipif
)

:: variables 
set drive=E:\BrowserBackups\Chrome
set folder=%DATE:~4,2%_%DATE:~7,2%_%DATE:~10,4%_%RANDOM%
set backupcmd=xcopy /C/E/H/I/R/K/Y
echo ### Backing up directory...
%backupcmd% "%USERPROFILE%\Local Settings\Application Data\Google\Chrome" "%drive%\%folder%"

:skipif
pause

:: mike


Report •

Related Solutions


Ask Question