[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

robocopy suspend

Posted on 2014-08-18
20
Medium Priority
?
424 Views
Last Modified: 2014-08-22
I made a simple batch file to copy outlook pst files to a network share. this is what i have so far

taskkill /T /F /IM OUTLOOK.EXE

robocopy "C:\outlook" "H:\Outlook Files" /fft /XO /E

I found that i need to pause this simple script between when it closes outlook, and starts copying, but I can't figure out how to create a pause. Any ideas how I could do this?
0
Comment
Question by:JeffBeall
  • 6
  • 5
  • 5
  • +2
20 Comments
 
LVL 85

Assisted Solution

by:oBdA
oBdA earned 500 total points
ID: 40268368
Well, you can always do a few pings to localhost if you know the maximum delay required; for example 10 seconds:
ping.exe -n 11 localhost

Open in new window

What's the error you get when you start too early? By default, robocopy tries a million times with a 30 second pause between each attempt when it encounters an error (or did you save these values in the registry at some point?).
0
 
LVL 57

Expert Comment

by:Joe Winograd, EE MVE 2015&2016
ID: 40268369
Hi Jeff,
Yes, it's a pity that batch files don't have a simple Sleep command, but there are numerous ways to achieve this. One is to use the Choice command with the timeout parameter. Here's what the command is for a 5-second delay (change the 5 to however many seconds you want to pause):

choice /d y /t 5

Regards, Joe
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 40268547
A better approach would be to loop while outlook.exe is still running, and then continue when it ends.  But this question closed very quick so I'll assume that wasn't useful and move along to other open questions.

~bp
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 57

Expert Comment

by:Joe Winograd, EE MVE 2015&2016
ID: 40268553
Hi Bill,
According to my browser, this question is still open. Regards, Joe
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 40268561
Wasn't a minute ago!

:)
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 40268597
Why do you need to wait? RoboCopy with the default settings retries to copy locked files 1 million times with a 30 seconds pause. That should suffice.
0
 
LVL 59

Assisted Solution

by:Bill Prew
Bill Prew earned 500 total points
ID: 40268614
If you do want to kill outlook, and wait for it to end before starting, then here's an example of an approach for that.

@echo off
setlocal

REM Define task to kill
set KillTask=outlook.exe

REM Invote the kill of this task
taskkill /IM /T /F %KillTask% >NUL 2>&1

REM Loop until the task is no longer running before proceeding
:WaitLoop
  REM Delay 1 second (in milliseconds) between checks
  ping -n 1 -w 1000 192.0.0.0 >NUL 2>&1
  REM If task is still running, loop until it isn't
  tasklist /FI "imagename eq %KillTask%" | find /I "%KillTask%" >NUL 2>&1 && goto :WaitLoop

REM Do the copy now that our task has stopped
robocopy "C:\outlook" "H:\Outlook Files" /fft /XO /E

Open in new window

~bp
0
 
LVL 1

Author Comment

by:JeffBeall
ID: 40268667
ok, so this is what i found, first off, the ping pause and the choise pause both work. so thank you for that.
Why wait, I'm not exactly sure, all i know is that from trial and error, if i try

taskkill /f /t /im outlook.exe

it closes outlook, but for some reason, when i copy something to the pst, then the batch closed outlook with taskkill the things that were copied to the pst are not there when i open outlook again. So I close outlook by clicking on the red X in the upper right corner of the windows, then after the copy command runs and i open outlook again, the stuff in the pst is there
so i googled some stuff and found this

pushd %~dp0
cscript closeoutlook.vbs

I put my batch and this vbscript in the same directory and now the batch looks like this

pushd %~dp0
cscript closeoutlook.vbs

choice /d y /t 5

robocopy "C:\outlook" "H:\Outlook Files" /fft /XO /E

and on my computer this works great, stuff i copy to the pst, then run the batch, it closes outlook, pauses 5 seconds, then copies the pst to my "H" drive. then i open outlook and everything that i put in the pst is still there.
now the problem is i copied this whole setup on a user's pc, but

pushd %~dp0
cscript closeoutlook.vbs

isn't closing outlook on her computer.
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 40268674
Post the VBS script or the link to the source, please.
0
 
LVL 1

Author Comment

by:JeffBeall
ID: 40268854
Set objOutlook = CreateObject("Outlook.Application")
objOutlook.Quit

that is the script, but I'm sorry, I don't know where I got it. It was earlier in the day and I closed my browser. I have my browser set to always run in private mode. sorry.
0
 
LVL 71

Accepted Solution

by:
Qlemo earned 500 total points
ID: 40269091
That's all? Two reasons why that script might not work are apparent:
a) Outlook is not found, or the above starts a new Outlook, which is then closed instead.
b) Outlook does prevent closing, e.g. because it is blocked, doing something, or changes may got lost at that moment. E.g. Outlook will not close while writing a message; a save prompt is displayed. There might be something in the background (VBA project changes, ...).
0
 
LVL 1

Author Comment

by:JeffBeall
ID: 40269315
ok, I found this script, hopefully it's better.

On Error Resume Next
Set Outlook = GetObject(, "Outlook.Application")
If Err = 0 Then
Outlook.Quit()
Set Outlook = Nothing
End If
Wscript.Quit

I don't know how to script, but it seems like this has some logic to it. I guess it looks for outlook, and closes outlook if it finds it
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 40269348
So, does that work now on both test PCs?

~bp
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 40269359
Depending on how you make out, here are a couple of small utils you could also explore for safely closing outlook.

https://www.maxoutput.com/SendMsg.html

http://www.aswit.com/akill/

~bp
0
 
LVL 57

Assisted Solution

by:Joe Winograd, EE MVE 2015&2016
Joe Winograd, EE MVE 2015&2016 earned 500 total points
ID: 40269369
Jeff,
I run a script every day in the wee hours to close Outlook so the PST can be backed up. It has never failed to close Outlook in years of usage. I wrote it in AutoHotkey, but there are a variety of languages you could write it in. The basic technique is to send Alt-F4 to Outlook. If you'd like to try AutoHotkey, here's the code:
SetTitleMatchMode,2 ; set title matching behavior to CONTAINS
IfWinExist Outlook ; check if "Outlook" exists in any title bar
{
  WinActivate ; activate the Outlook window
  Send !{F4} ; send Alt-F4 to close Outlook
}

Open in new window

Put the above in a file called <ExitOutlook.ahk>. After installing AutoHotkey, it will own the file type AHK. Then put this call in Task Scheduler:

D:\scripts\exitoutlook.ahk

Of course, <scripts> is wherever your scripts are stored. If you'd prefer a stand-alone/no-install executable to run on a computer that doesn't have AutoHotkey installed, simply compile the AHK file (right-click/Compile) on any computer with AutoHotkey installed and put the EXE file that the compiler creates on any computer where you want it to run. Then your Task Scheduler call would be:

D:\whateverfolder\exitoutlook.exe

Regards, Joe
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 40269868
The SendKey approach could be used in VBS too, but trying to get the Outlook object and sending a close command is much better, so I would stay with the new VBS script. For Outlook it should not matter whether you use GetObject or CreateObject, as you can't create more than one instance (AFAIK) of Outlook anyway - CreateObject just returns the pointer to the already running Outlook.
0
 
LVL 1

Author Comment

by:JeffBeall
ID: 40277126
ok, for whatever reason, on one of the user's computers. outlook refuses to close with
taskkill /IM /T /F OUTLOOK.exe >NUL 2>&1
or
On Error Resume Next
 Set Outlook = GetObject(, "Outlook.Application")
 If Err = 0 Then
 Outlook.Quit()
 Set Outlook = Nothing
 End If
 Wscript.Quit
so I started thinking, would it be possible to have a script that logs off the user - which would make windows kill the outlook process. and then copy the pst file to a network share? I'm assuming that since the script would be started by the user, windows would kill all of the user's processes, including the script. but is it possible to have a script run as a service maybe?
also, I'm wanting to save the pst file to a network share - but given the nature of a pst file, i assume the whole file has to be copied up each time. So if it is a 2gb file, every time it will copy 2gb, and not just changes to the pst.
lastly, i thought maybe cached mode would work, but cached mode in outlook, i thought only make a local copy of the mailbox, and ignores pst files
I also wanted to mention Joe Winograd, I'm not ignoring your suggestion - I can't install something like AutoHoyKey in my environment. only approved software is allowed. were I used to work, I used AutoIt, which sounds a lot like AutoHotKey.
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 40277561
You really should check why Outlook does not close. Try doing it manually - maybe it just last very long for Outlook to properly close?
0
 
LVL 1

Author Comment

by:JeffBeall
ID: 40277608
I found a script that works! ( it does close manually ), anyhow i found this

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'Outlook.exe'")
For Each objProcess in colProcessList
   objProcess.Terminate()
Next

I don't know why it works, I just know it does!
0
 
LVL 1

Author Closing Comment

by:JeffBeall
ID: 40278908
thank you for the help, I think I got points to everyone.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
There are many software programs on offer that will claim to magically speed up your computer. The best advice I can give you is to avoid them like the plague, because they will often cause far more problems than they solve. Try some of these "do it…
This Micro Tutorial will teach you how to change your appearance and customize your Windows 7 interface to your unique preference. This will be demonstrated using Windows 7 operating system.
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question