Script to quit program prior to Robocopy

0

I'm setting up a backup script for a client that will be scheduled to run once a month to backup his 200GB iTunes directory to his NAS. It's compiled using some defined parameters and ROBOCOPY %_source% %_dest% %_what% %_options%. How can I add something to the start of that script to quit all open applications prior to the Robocopy task?

I could use taskkill.exe but I'm concerned that might damage some iTunes files if it's running at the time. Is there a clean way to quit everything?

Reece

Posted 2014-03-17T04:59:05.997

Reputation: 303

Answers

0

As far as I know batch scripts are not capable of gentle closes, you would be better of using a vbscript to close itunes use

Set objitunes = CreateObject("Itunes.Application")
objItunes.quit

This should do what you want.

Then use

CreateObject("WScript.Shell").Run("""C:\myfile.bat""")

to open your copy batch file or use robocopy from the vbs file directly (I know it can be done but I don't know how)

If you use a batch file you can use

tasklist /FI "IMAGENAME eq itunes.exe" 2>NUL | find /I /N "itunes.exe">NUL
if "%ERRORLEVEL%"=="1" robocopy C:\your\folder\ N:\your\other\folder /mir

to make it copy only when itunes is closed

niteshadow

Posted 2014-03-17T04:59:05.997

Reputation: 133

I'm not very good with vbs. When I try your suggestion, I get this error: http://i.imgur.com/EwhLBab.jpg

– Reece – 2014-03-17T22:21:37.450

Please post your current vbs file and also which windows are you currently running. – niteshadow – 2014-03-18T02:15:45.390

Also since you are making this for a different person would it be possible to send them a vbs file with just the first block of code and see if it works for them? – niteshadow – 2014-03-18T02:43:53.897

I've just created a .vbs file on my desktop with the contents Set objiTunes = CreateObject("iTunes.Application") objiTunes.quit

CreateObject("WScript.Shell").Run("""C:\BACKUP-SCRIPTS\3d-FileSync.bat"""). I'm using Windows 7 64-bit. And 64-bit iTunes. UAC is disabled. – Reece – 2014-03-18T03:21:50.840

Alright I'm using windows 8 so things might be slightly different, but I've managed to duplicate the error on my system. It seems to happen when the application doesn't exist and after googling it seems like something didn't register correctly when itunes was installed and a repair install might fix it, but like I mentioned before since you won't be using this script you should send the objitunes.quit block to your client and see if it works for them. – niteshadow – 2014-03-18T04:06:49.390

Also I should mention that if itunes is already closed this script will open and then close it. – niteshadow – 2014-03-18T04:53:20.853

0

Based on this page, it seems taskkill should work.

taskkill /IM itunes.exe

I tried it on a few programs(notepad, ide, music player) and they all either shutdown properly or brought up the confirmation dialog.

Shazvi

Posted 2014-03-17T04:59:05.997

Reputation: 1 140