|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Detect completion of Outlook Send/Recieve programatically (vbs?)How can I detect when the Outlook Send and Receive process is completed using
VBScript or VB? Basically I have a program that needs to wait until the Outlook profile is completely synchronized before I can run a part of my code. Any idea how to detect that? You can't. If the code starts a send/receive as a sync action you can handle
an event when the sync completes. You get no events when a scheduled sync or user started sync occurs. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm Show quote "Jaswicki" <Jaswi***@discussions.microsoft.com> wrote in message news:4EF3FA8F-5A04-4887-8ED2-7A43D0678BE6@microsoft.com... > How can I detect when the Outlook Send and Receive process is completed > using > VBScript or VB? Basically I have a program that needs to wait until the > Outlook profile is completely synchronized before I can run a part of my > code. Any idea how to detect that? OK, if I initiate a send/recieve programatically while there is another synch
occuring will I get the handle? Show quote "Ken Slovak - [MVP - Outlook]" wrote: > You can't. If the code starts a send/receive as a sync action you can handle > an event when the sync completes. You get no events when a scheduled sync or > user started sync occurs. > > -- > Ken Slovak > [MVP - Outlook] > http://www.slovaktech.com > Author: Professional Programming Outlook 2007 > Reminder Manager, Extended Reminders, Attachment Options > http://www.slovaktech.com/products.htm > > > "Jaswicki" <Jaswi***@discussions.microsoft.com> wrote in message > news:4EF3FA8F-5A04-4887-8ED2-7A43D0678BE6@microsoft.com... > > How can I detect when the Outlook Send and Receive process is completed > > using > > VBScript or VB? Basically I have a program that needs to wait until the > > Outlook profile is completely synchronized before I can run a part of my > > code. Any idea how to detect that? > > Only to the synch you start in code, for the other one no. And how would you
know that a synch is ongoing to begin with? -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm Show quote "Jaswicki" <Jaswi***@discussions.microsoft.com> wrote in message news:49D368EE-34C3-4275-BF1A-BDAD063248DC@microsoft.com... > OK, if I initiate a send/recieve programatically while there is another > synch > occuring will I get the handle? OK from what I read the SyncEnd() event is not accessible from VBScript. I
rewrote the script as a VB.net Console Application (I need no user interaction due to SMS deployment. I have everything working other than that the event never gets triggered even when I see the sync is complete in Outlook and Any timer event I use to wait for the event to trigger causes my CPU to peg at 99% utilization which causes the sync to run extremely slowly. I have pasted my code below any help would be greatly appreciated. ________________________________________________________________ Imports Outlook = Microsoft.Office.Interop.Outlook Module Module1 Public Interface SyncObjectEvents End Interface Public bSendReceiveEnded As Boolean 'Private WithEvents objDefaultSendReceive As Outlook.SyncObject Sub instance_SyncEnd() MsgBox("triggered") bSendReceiveEnded = True End Sub Sub Main() On Error Resume Next ' Create an Outlook application. Dim i As Integer Dim myTimer As New System.Timers.Timer() myTimer.Interval = 3000 Dim oApp As Outlook._Application = New Outlook.Application ' Create the name space. Dim oNS As Outlook._NameSpace = oApp.GetNamespace("mapi") Dim oSyncs As Outlook.SyncObjects Dim oSync As Outlook.SyncObject Dim instance As SyncObjectEvents Dim myAPF = oNS.Folders("Public Folders").Folders("All Public Folders").Folders("North America").Folders("Business functions/Projects (Cross-site)") Dim pfFolder = oNS.Folders("Public Folders").Folders("Favorites") Dim chkfold = oNS.Folders("Public Folders").Folders("Favorites").Folders("NA Field Force Automation") If chkfold Is Nothing Then 'If chkfold Is Nothing Then ' Reference SyncObjects. myAPF.Folders("NA Field Force Automation").AddToPFFavorites() bSendReceiveEnded = False oSyncs = oNS.SyncObjects oSync = oSyncs.Item("All Accounts") ' Send and receive. oSync.Start() Do While bSendReceiveEnded = False myTimer.Enabled = True Loop Dim favfold = oNS.Folders("Public Folders").Folders("Favorites").Folders("NA Field Force Automation") favfold.display() 'End If End If ' Clean up. chkfold = Nothing myAPF = Nothing oSync = Nothing oSyncs = Nothing oNS = Nothing oApp = Nothing End Sub End Module ____________________________________________________________________ Show quote "Ken Slovak - [MVP - Outlook]" wrote: > Only to the synch you start in code, for the other one no. And how would you > know that a synch is ongoing to begin with? > > -- > Ken Slovak > [MVP - Outlook] > http://www.slovaktech.com > Author: Professional Programming Outlook 2007 > Reminder Manager, Extended Reminders, Attachment Options > http://www.slovaktech.com/products.htm > > > "Jaswicki" <Jaswi***@discussions.microsoft.com> wrote in message > news:49D368EE-34C3-4275-BF1A-BDAD063248DC@microsoft.com... > > OK, if I initiate a send/recieve programatically while there is another > > synch > > occuring will I get the handle? > > Why are you using a timer to wait for synching to finish? Synching is
asynchronous and will fire an event when it's finished. Just handle the event that fires when the synch finishes. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm Show quote "Jaswicki" <Jaswi***@discussions.microsoft.com> wrote in message news:75A9F220-AD77-4C1E-B607-9F30E54350F6@microsoft.com... > OK from what I read the SyncEnd() event is not accessible from VBScript. I > rewrote the script as a VB.net Console Application (I need no user > interaction due to SMS deployment. I have everything working other than > that > the event never gets triggered even when I see the sync is complete in > Outlook and Any timer event I use to wait for the event to trigger causes > my > CPU to peg at 99% utilization which causes the sync to run extremely > slowly. > I have pasted my code below any help would be greatly appreciated. > > ________________________________________________________________ > Imports Outlook = Microsoft.Office.Interop.Outlook > > > Module Module1 > Public Interface SyncObjectEvents > End Interface > > Public bSendReceiveEnded As Boolean > > 'Private WithEvents objDefaultSendReceive As Outlook.SyncObject > > > Sub instance_SyncEnd() > MsgBox("triggered") > bSendReceiveEnded = True > End Sub > > Sub Main() > On Error Resume Next > > ' Create an Outlook application. > Dim i As Integer > Dim myTimer As New System.Timers.Timer() > myTimer.Interval = 3000 > Dim oApp As Outlook._Application = New Outlook.Application > ' Create the name space. > Dim oNS As Outlook._NameSpace = oApp.GetNamespace("mapi") > Dim oSyncs As Outlook.SyncObjects > Dim oSync As Outlook.SyncObject > Dim instance As SyncObjectEvents > Dim myAPF = oNS.Folders("Public Folders").Folders("All Public > Folders").Folders("North America").Folders("Business functions/Projects > (Cross-site)") > Dim pfFolder = oNS.Folders("Public Folders").Folders("Favorites") > Dim chkfold = oNS.Folders("Public > Folders").Folders("Favorites").Folders("NA Field Force Automation") > If chkfold Is Nothing Then > > > 'If chkfold Is Nothing Then > ' Reference SyncObjects. > myAPF.Folders("NA Field Force Automation").AddToPFFavorites() > > bSendReceiveEnded = False > oSyncs = oNS.SyncObjects > oSync = oSyncs.Item("All Accounts") > ' Send and receive. > oSync.Start() > Do While bSendReceiveEnded = False > myTimer.Enabled = True > Loop > > Dim favfold = oNS.Folders("Public > Folders").Folders("Favorites").Folders("NA Field Force Automation") > favfold.display() > 'End If > End If > > ' Clean up. > chkfold = Nothing > myAPF = Nothing > oSync = Nothing > oSyncs = Nothing > oNS = Nothing > oApp = Nothing > End Sub > > End Module I tried that as well but I never seem to catch the event no matter if that
timer was there or not. Do you see anything in my syncend event handler that is incorrect? Show quote "Ken Slovak - [MVP - Outlook]" wrote: > Why are you using a timer to wait for synching to finish? Synching is > asynchronous and will fire an event when it's finished. Just handle the > event that fires when the synch finishes. > > -- > Ken Slovak > [MVP - Outlook] > http://www.slovaktech.com > Author: Professional Programming Outlook 2007 > Reminder Manager, Extended Reminders, Attachment Options > http://www.slovaktech.com/products.htm > > > "Jaswicki" <Jaswi***@discussions.microsoft.com> wrote in message > news:75A9F220-AD77-4C1E-B607-9F30E54350F6@microsoft.com... > > OK from what I read the SyncEnd() event is not accessible from VBScript. I > > rewrote the script as a VB.net Console Application (I need no user > > interaction due to SMS deployment. I have everything working other than > > that > > the event never gets triggered even when I see the sync is complete in > > Outlook and Any timer event I use to wait for the event to trigger causes > > my > > CPU to peg at 99% utilization which causes the sync to run extremely > > slowly. > > I have pasted my code below any help would be greatly appreciated. > > > > ________________________________________________________________ > > Imports Outlook = Microsoft.Office.Interop.Outlook > > > > > > Module Module1 > > Public Interface SyncObjectEvents > > End Interface > > > > Public bSendReceiveEnded As Boolean > > > > 'Private WithEvents objDefaultSendReceive As Outlook.SyncObject > > > > > > Sub instance_SyncEnd() > > MsgBox("triggered") > > bSendReceiveEnded = True > > End Sub > > > > Sub Main() > > On Error Resume Next > > > > ' Create an Outlook application. > > Dim i As Integer > > Dim myTimer As New System.Timers.Timer() > > myTimer.Interval = 3000 > > Dim oApp As Outlook._Application = New Outlook.Application > > ' Create the name space. > > Dim oNS As Outlook._NameSpace = oApp.GetNamespace("mapi") > > Dim oSyncs As Outlook.SyncObjects > > Dim oSync As Outlook.SyncObject > > Dim instance As SyncObjectEvents > > Dim myAPF = oNS.Folders("Public Folders").Folders("All Public > > Folders").Folders("North America").Folders("Business functions/Projects > > (Cross-site)") > > Dim pfFolder = oNS.Folders("Public Folders").Folders("Favorites") > > Dim chkfold = oNS.Folders("Public > > Folders").Folders("Favorites").Folders("NA Field Force Automation") > > If chkfold Is Nothing Then > > > > > > 'If chkfold Is Nothing Then > > ' Reference SyncObjects. > > myAPF.Folders("NA Field Force Automation").AddToPFFavorites() > > > > bSendReceiveEnded = False > > oSyncs = oNS.SyncObjects > > oSync = oSyncs.Item("All Accounts") > > ' Send and receive. > > oSync.Start() > > Do While bSendReceiveEnded = False > > myTimer.Enabled = True > > Loop > > > > Dim favfold = oNS.Folders("Public > > Folders").Folders("Favorites").Folders("NA Field Force Automation") > > favfold.display() > > 'End If > > End If > > > > ' Clean up. > > chkfold = Nothing > > myAPF = Nothing > > oSync = Nothing > > oSyncs = Nothing > > oNS = Nothing > > oApp = Nothing > > End Sub > > > > End Module > > Imports Outlook = Microsoft.Office.Interop.Outlook
Module Module1 Public Interface SyncObjectEvents End Interface Public bSendReceiveEnded As Boolean Private WithEvents instance As Outlook.SyncObject Sub instance_SyncEnd() MsgBox("triggered") bSendReceiveEnded = True End Sub Sub Main() On Error Resume Next ' Create an Outlook application. Dim i As Integer 'Dim myTimer As New System.Timers.Timer() 'myTimer.Interval = 3000 Dim oApp As Outlook._Application = New Outlook.Application ' Create the name space. Dim oNS As Outlook._NameSpace = oApp.GetNamespace("mapi") Dim oSyncs As Outlook.SyncObjects 'Dim oSync As Outlook.SyncObject 'Dim instance As SyncObjectEvents Dim myAPF = oNS.Folders("Public Folders").Folders("All Public Folders").Folders("North America").Folders("Business functions/Projects (Cross-site)") Dim pfFolder = oNS.Folders("Public Folders").Folders("Favorites") Dim chkfold = oNS.Folders("Public Folders").Folders("Favorites").Folders("NA Field Force Automation") If chkfold Is Nothing Then 'If chkfold Is Nothing Then ' Reference SyncObjects. myAPF.Folders("NA Field Force Automation").AddToPFFavorites() bSendReceiveEnded = False oSyncs = oNS.SyncObjects instance = oSyncs.Item("All Accounts") ' Send and receive. instance.Start() 'Do While bSendReceiveEnded = False ' myTimer.Enabled = True ' Loop Dim favfold = oNS.Folders("Public Folders").Folders("Favorites").Folders("NA Field Force Automation") favfold.display() 'End If Else MessageBox.Show("chkfold IsNot Nothing") End If ' Clean up. chkfold = Nothing myAPF = Nothing 'oSync = Nothing oSyncs = Nothing oNS = Nothing oApp = Nothing End Sub End Module -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm Show quote "Jaswicki" <Jaswi***@discussions.microsoft.com> wrote in message news:25931AB9-0314-4AE9-994D-77EA95A6BC39@microsoft.com... >I tried that as well but I never seem to catch the event no matter if that > timer was there or not. Do you see anything in my syncend event handler > that > is incorrect? Thanks Ken but I created a nwe project and pasted in your code just to be on
the safe side and it still drops through before the sync is competed. Any idea why? Show quote "Ken Slovak - [MVP - Outlook]" wrote: > Imports Outlook = Microsoft.Office.Interop.Outlook > > Module Module1 > Public Interface SyncObjectEvents > End Interface > > Public bSendReceiveEnded As Boolean > > Private WithEvents instance As Outlook.SyncObject > > Sub instance_SyncEnd() > MsgBox("triggered") > bSendReceiveEnded = True > End Sub > > Sub Main() > On Error Resume Next > > ' Create an Outlook application. > Dim i As Integer > > 'Dim myTimer As New System.Timers.Timer() > 'myTimer.Interval = 3000 > > Dim oApp As Outlook._Application = New Outlook.Application > ' Create the name space. > Dim oNS As Outlook._NameSpace = oApp.GetNamespace("mapi") > Dim oSyncs As Outlook.SyncObjects > 'Dim oSync As Outlook.SyncObject > 'Dim instance As SyncObjectEvents > Dim myAPF = oNS.Folders("Public Folders").Folders("All Public > Folders").Folders("North America").Folders("Business functions/Projects > (Cross-site)") > Dim pfFolder = oNS.Folders("Public Folders").Folders("Favorites") > Dim chkfold = oNS.Folders("Public > Folders").Folders("Favorites").Folders("NA Field Force Automation") > If chkfold Is Nothing Then > > > 'If chkfold Is Nothing Then > ' Reference SyncObjects. > myAPF.Folders("NA Field Force Automation").AddToPFFavorites() > > bSendReceiveEnded = False > oSyncs = oNS.SyncObjects > instance = oSyncs.Item("All Accounts") > ' Send and receive. > instance.Start() > 'Do While bSendReceiveEnded = False > ' myTimer.Enabled = True > ' Loop > > Dim favfold = oNS.Folders("Public > Folders").Folders("Favorites").Folders("NA Field Force Automation") > favfold.display() > 'End If > Else > MessageBox.Show("chkfold IsNot Nothing") > End If > > ' Clean up. > chkfold = Nothing > myAPF = Nothing > 'oSync = Nothing > oSyncs = Nothing > oNS = Nothing > oApp = Nothing > End Sub > > End Module > > > -- > Ken Slovak > [MVP - Outlook] > http://www.slovaktech.com > Author: Professional Programming Outlook 2007 > Reminder Manager, Extended Reminders, Attachment Options > http://www.slovaktech.com/products.htm > > > "Jaswicki" <Jaswi***@discussions.microsoft.com> wrote in message > news:25931AB9-0314-4AE9-994D-77EA95A6BC39@microsoft.com... > >I tried that as well but I never seem to catch the event no matter if that > > timer was there or not. Do you see anything in my syncend event handler > > that > > is incorrect? > > If this is a console app then it's just running to completion before the
synch ends. You could just do your loop without the timer but setting that Boolean flag in the synch end event as a means of exiting the loop. If you do use something like a loop I'd put a DoEvents in the loop so you cede control to other processes while the loop is running. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm Show quote "Jaswicki" <Jaswi***@discussions.microsoft.com> wrote in message news:6A8FDDBD-0C77-4AA9-BB57-51D16EBAA595@microsoft.com... > Thanks Ken but I created a nwe project and pasted in your code just to be > on > the safe side and it still drops through before the sync is competed. Any > idea why? Thanks! So if I had used a normal Windows .ent application project it would
have waited for the syncend rather than needing the loop? I added the following loop... Do While bSendReceiveEnded = False System.Windows.Forms.Application.DoEvents() Loop The problem is that this loop still peaks my processor to about 90%. Isn't there a way to get vb to just wait without running the proc like this? Show quote "Ken Slovak - [MVP - Outlook]" wrote: > If this is a console app then it's just running to completion before the > synch ends. You could just do your loop without the timer but setting that > Boolean flag in the synch end event as a means of exiting the loop. > > If you do use something like a loop I'd put a DoEvents in the loop so you > cede control to other processes while the loop is running. > > -- > Ken Slovak > [MVP - Outlook] > http://www.slovaktech.com > Author: Professional Programming Outlook 2007 > Reminder Manager, Extended Reminders, Attachment Options > http://www.slovaktech.com/products.htm > > > "Jaswicki" <Jaswi***@discussions.microsoft.com> wrote in message > news:6A8FDDBD-0C77-4AA9-BB57-51D16EBAA595@microsoft.com... > > Thanks Ken but I created a nwe project and pasted in your code just to be > > on > > the safe side and it still drops through before the sync is competed. Any > > idea why? > > It depends on the type of app you're running. I usually use COM addin
programs that run until Outlook closes or the user disconnects the addin. In cases like that there's no problem because a Sub Main() type procedure isn't there to run to completion. An alternative might be to use a form that has a Close button and showing that form modally would prevent the app from completing. This isn't a VB thing, the same thing would happen using VB6 or C# or Delphi or C++ or whatever in standalone code. You have to find a way to prevent the code from completing and shutting down a standalone app. It's the same with any event driven application. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm Show quote "Jaswicki" <Jaswi***@discussions.microsoft.com> wrote in message news:31528D67-3B5C-473B-98BB-9FF85F0EEFDD@microsoft.com... > Thanks! So if I had used a normal Windows .ent application project it > would > have waited for the syncend rather than needing the loop? > I added the following loop... > Do While bSendReceiveEnded = False > System.Windows.Forms.Application.DoEvents() > Loop > The problem is that this loop still peaks my processor to about 90%. Isn't > there a way to get vb to just wait without running the proc like this? Thanks again. I really appreciate the time you have put in helping me with
this. I actually just walked out of a meeting where they decided to scrap the functionallity this remaining step would have given so, though I will continue to try and figure out my issue, it is going to the back burner now. If, hopefully when, I find the solution I will come back and post it here for others to benefit from. Show quote "Ken Slovak - [MVP - Outlook]" wrote: > It depends on the type of app you're running. I usually use COM addin > programs that run until Outlook closes or the user disconnects the addin. In > cases like that there's no problem because a Sub Main() type procedure isn't > there to run to completion. > > An alternative might be to use a form that has a Close button and showing > that form modally would prevent the app from completing. > > This isn't a VB thing, the same thing would happen using VB6 or C# or Delphi > or C++ or whatever in standalone code. You have to find a way to prevent the > code from completing and shutting down a standalone app. It's the same with > any event driven application. > > -- > Ken Slovak > [MVP - Outlook] > http://www.slovaktech.com > Author: Professional Programming Outlook 2007 > Reminder Manager, Extended Reminders, Attachment Options > http://www.slovaktech.com/products.htm > > > "Jaswicki" <Jaswi***@discussions.microsoft.com> wrote in message > news:31528D67-3B5C-473B-98BB-9FF85F0EEFDD@microsoft.com... > > Thanks! So if I had used a normal Windows .ent application project it > > would > > have waited for the syncend rather than needing the loop? > > I added the following loop... > > Do While bSendReceiveEnded = False > > System.Windows.Forms.Application.DoEvents() > > Loop > > The problem is that this loop still peaks my processor to about 90%. Isn't > > there a way to get vb to just wait without running the proc like this? > > |
|||||||||||||||||||||||