PC Review


Reply
Thread Tools Rate Thread

Bulletproof Exiting Outlook (and not crashing)

 
 
Derek Hart
Guest
Posts: n/a
 
      28th Dec 2009
In building an Outlook integration, I try to exit Outlook this way:



Marshal.ReleaseComObject(objOutlook)
objOutlook = Nothing



Before I did this, sometimes this code would not execute, and Outlook would
then get a bit messed up. I would have to load Outlook and wait for it to
repair and/or shut down Outlook in the Task Manager. I don't want this ever
to happen to a user in a commercial application. Is the above code the best
way to handle this scenario. I want to bulletproof an application with
Outlook, and I don't want to corrupt a user's Outlook file.



I am just using standard VB .Net code. Here is a sample. Anything that can
make it safer than my code here?



Try

Dim objOutlook As Outlook.Application

Dim objNameSpace As Outlook.NameSpace

Dim objFolder As Outlook.MAPIFolder

Dim objItem As Outlook.MailItem



objOutlook = New Outlook.Application

objNameSpace = objOutlook.GetNamespace("MAPI")

objNameSpace.Logon()

objFolder =
objNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)



' Do email processing



Catch ex As Exception

MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Information)



Finally

Marshal.ReleaseComObject(objOutlook)

objOutlook = Nothing









 
Reply With Quote
 
 
 
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      28th Dec 2009
You need to release all of your COM objects (Outlook objects included) and
you should call the garbage collector also in your shutdown code:

GC.Collect()
GC.WaitForPendingFinalizers()

You may need to call ReleaseComObject() in a loop until it returns 0,
depending on your object instantiations and handling.

Any other answers would depend on whether this is addin code or not, and
what context the code would run in.

--
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


"Derek Hart" <(E-Mail Removed)> wrote in message
news:ejcr7c$(E-Mail Removed)...
> In building an Outlook integration, I try to exit Outlook this way:
>
>
>
> Marshal.ReleaseComObject(objOutlook)
> objOutlook = Nothing
>
>
>
> Before I did this, sometimes this code would not execute, and Outlook
> would then get a bit messed up. I would have to load Outlook and wait for
> it to repair and/or shut down Outlook in the Task Manager. I don't want
> this ever to happen to a user in a commercial application. Is the above
> code the best way to handle this scenario. I want to bulletproof an
> application with Outlook, and I don't want to corrupt a user's Outlook
> file.
>
>
>
> I am just using standard VB .Net code. Here is a sample. Anything that can
> make it safer than my code here?
>
>
>
> Try
>
> Dim objOutlook As Outlook.Application
>
> Dim objNameSpace As Outlook.NameSpace
>
> Dim objFolder As Outlook.MAPIFolder
>
> Dim objItem As Outlook.MailItem
>
>
>
> objOutlook = New Outlook.Application
>
> objNameSpace = objOutlook.GetNamespace("MAPI")
>
> objNameSpace.Logon()
>
> objFolder =
> objNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
>
>
>
> ' Do email processing
>
>
>
> Catch ex As Exception
>
> MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
> MessageBoxIcon.Information)
>
>
>
> Finally
>
> Marshal.ReleaseComObject(objOutlook)
>
> objOutlook = Nothing
>
>
>
>
>
>
>
>
>


 
Reply With Quote
 
Derek Hart
Guest
Posts: n/a
 
      29th Dec 2009
Ken,

This is not an add-in, just a plain old pst file being synchronized with a
database.

Based on the code below, is there something I should do differently to get
the current Outlook instance if it is loaded? I think Outlook can only be
loaded one time when done manually, so when I run the code below, does it
create a whole new instance, or attach to the one that is running?

Derek



"Ken Slovak - [MVP - Outlook]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> You need to release all of your COM objects (Outlook objects included) and
> you should call the garbage collector also in your shutdown code:
>
> GC.Collect()
> GC.WaitForPendingFinalizers()
>
> You may need to call ReleaseComObject() in a loop until it returns 0,
> depending on your object instantiations and handling.
>
> Any other answers would depend on whether this is addin code or not, and
> what context the code would run in.
>
> --
> 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
>
>
> "Derek Hart" <(E-Mail Removed)> wrote in message
> news:ejcr7c$(E-Mail Removed)...
>> In building an Outlook integration, I try to exit Outlook this way:
>>
>>
>>
>> Marshal.ReleaseComObject(objOutlook)
>> objOutlook = Nothing
>>
>>
>>
>> Before I did this, sometimes this code would not execute, and Outlook
>> would then get a bit messed up. I would have to load Outlook and wait for
>> it to repair and/or shut down Outlook in the Task Manager. I don't want
>> this ever to happen to a user in a commercial application. Is the above
>> code the best way to handle this scenario. I want to bulletproof an
>> application with Outlook, and I don't want to corrupt a user's Outlook
>> file.
>>
>>
>>
>> I am just using standard VB .Net code. Here is a sample. Anything that
>> can make it safer than my code here?
>>
>>
>>
>> Try
>>
>> Dim objOutlook As Outlook.Application
>>
>> Dim objNameSpace As Outlook.NameSpace
>>
>> Dim objFolder As Outlook.MAPIFolder
>>
>> Dim objItem As Outlook.MailItem
>>
>>
>>
>> objOutlook = New Outlook.Application
>>
>> objNameSpace = objOutlook.GetNamespace("MAPI")
>>
>> objNameSpace.Logon()
>>
>> objFolder =
>> objNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
>>
>>
>>
>> ' Do email processing
>>
>>
>>
>> Catch ex As Exception
>>
>> MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
>> MessageBoxIcon.Information)
>>
>>
>>
>> Finally
>>
>> Marshal.ReleaseComObject(objOutlook)
>>
>> objOutlook = Nothing
>>
>>
>>
>>
>>
>>
>>
>>
>>

>



 
Reply With Quote
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      29th Dec 2009
I would certainly make sure to release all COM objects, including any
Outlook objects such as your objNameSpace, objFolder, etc.

As it's standalone code I'd also handle the Explorer and Inspector Close()
events if you are displaying any UI that can be closed. If there is no UI
then you just need to release everything when you are finished with your
code.

You can only have one instance of Outlook running at any time. I prefer to
do things differently in cases where I'm automating Outlook from a
standalone program. I like to know if I need to start an instance or one was
running already. I use code something like this for that purpose, this
happens to be C# code:

private void InstantiateOutlook()

{

try

{

string olProcess = "Outlook.exe";

SelectQuery query = new SelectQuery("SELECT Name FROM Win32_Process WHERE
name='" + olProcess + "'");

ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);

ManagementObjectCollection objectCollection = searcher.Get();

int collCount = objectCollection.Count;

searcher.Dispose();

objectCollection.Dispose();

searcher = null;

objectCollection = null;

if (collCount != 0)

{

// Outlook already running, hook into the Outlook instance

_outlookApp = Marshal.GetActiveObject("Outlook.Application") as
Outlook.Application;

if (_outlookApp != null) canQuit = false;

}

else

{

// Outlook not already running, start it

Outlook.ApplicationClass _app = new Outlook.ApplicationClass();

_outlookApp = (Outlook.Application)_app;

}

}

catch (System.Exception ex)

{

MessageBox.Show(ex.Message);

}

}


--
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


"Derek Hart" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Ken,
>
> This is not an add-in, just a plain old pst file being synchronized with a
> database.
>
> Based on the code below, is there something I should do differently to get
> the current Outlook instance if it is loaded? I think Outlook can only be
> loaded one time when done manually, so when I run the code below, does it
> create a whole new instance, or attach to the one that is running?
>
> Derek
>


 
Reply With Quote
 
Derek Hart
Guest
Posts: n/a
 
      29th Dec 2009
Wow... thank you for this code. A few things...

I am wondering if I should simply run this code first to instantiate
Outlook, and then use my code as I did before to go get it. Since you did
not send me a function, it looks like I am not retrieving the instance from
this routine and pulling it into another routine.

A couple variables were not declared in your code, so I am unclear how to
use this. Should I declare this as a global variable. If so, I tried that,
and the code is having problems.
Dim _outlookApp As Outlook.Application

So in my routine I load Outlook this way:
InstantiateOutlook()

Then the global variable _outlookApp is used everywhere. But then at the end
of my routine, I release the com object and set it to nothing. So then I
thought I should put the code as follows in your routine.
objOutlook = New Outlook.Application
If collCount <> 0 Then
' Outlook already running, hook into the Outlook instance
objOutlook =
TryCast(Marshal.GetActiveObject("Outlook.Application"), Outlook.Application)

But that code errors on the TryCast line. Please explain how to use this
code appropriately.

And I am unclear what the canQuit flag is used for:
Dim canQuit As Boolean


"Ken Slovak - [MVP - Outlook]" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
>I would certainly make sure to release all COM objects, including any
>Outlook objects such as your objNameSpace, objFolder, etc.
>
> As it's standalone code I'd also handle the Explorer and Inspector Close()
> events if you are displaying any UI that can be closed. If there is no UI
> then you just need to release everything when you are finished with your
> code.
>
> You can only have one instance of Outlook running at any time. I prefer to
> do things differently in cases where I'm automating Outlook from a
> standalone program. I like to know if I need to start an instance or one
> was running already. I use code something like this for that purpose, this
> happens to be C# code:
>
> private void InstantiateOutlook()
>
> {
>
> try
>
> {
>
> string olProcess = "Outlook.exe";
>
> SelectQuery query = new SelectQuery("SELECT Name FROM Win32_Process WHERE
> name='" + olProcess + "'");
>
> ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
>
> ManagementObjectCollection objectCollection = searcher.Get();
>
> int collCount = objectCollection.Count;
>
> searcher.Dispose();
>
> objectCollection.Dispose();
>
> searcher = null;
>
> objectCollection = null;
>
> if (collCount != 0)
>
> {
>
> // Outlook already running, hook into the Outlook instance
>
> _outlookApp = Marshal.GetActiveObject("Outlook.Application") as
> Outlook.Application;
>
> if (_outlookApp != null) canQuit = false;
>
> }
>
> else
>
> {
>
> // Outlook not already running, start it
>
> Outlook.ApplicationClass _app = new Outlook.ApplicationClass();
>
> _outlookApp = (Outlook.Application)_app;
>
> }
>
> }
>
> catch (System.Exception ex)
>
> {
>
> MessageBox.Show(ex.Message);
>
> }
>
> }
>
>
> --
> 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
>
>
> "Derek Hart" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Ken,
>>
>> This is not an add-in, just a plain old pst file being synchronized with
>> a database.
>>
>> Based on the code below, is there something I should do differently to
>> get the current Outlook instance if it is loaded? I think Outlook can
>> only be loaded one time when done manually, so when I run the code below,
>> does it create a whole new instance, or attach to the one that is
>> running?
>>
>> Derek
>>

>



 
Reply With Quote
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      29th Dec 2009
_outlookApp is declared at a global or class level. I just call the method I
showed to instantiate an Outlook.Application object declared as _outlookApp.
I use the flag value canQuit to know if I should close Outlook when I'm
done, or if it was already running I just leave it alone.

The code I showed is in C#, if you are going to use it in a VB.NET
application you will need to translate it from C#.

That code is pretty much the equivalent of calling GetObject() in VB6 on an
Outlook.Application object and then calling CreateObject() or New if the
GetObject() call fails.

--
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


"Derek Hart" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Wow... thank you for this code. A few things...
>
> I am wondering if I should simply run this code first to instantiate
> Outlook, and then use my code as I did before to go get it. Since you did
> not send me a function, it looks like I am not retrieving the instance
> from this routine and pulling it into another routine.
>
> A couple variables were not declared in your code, so I am unclear how to
> use this. Should I declare this as a global variable. If so, I tried that,
> and the code is having problems.
> Dim _outlookApp As Outlook.Application
>
> So in my routine I load Outlook this way:
> InstantiateOutlook()
>
> Then the global variable _outlookApp is used everywhere. But then at the
> end of my routine, I release the com object and set it to nothing. So then
> I thought I should put the code as follows in your routine.
> objOutlook = New Outlook.Application
> If collCount <> 0 Then
> ' Outlook already running, hook into the Outlook instance
> objOutlook =
> TryCast(Marshal.GetActiveObject("Outlook.Application"),
> Outlook.Application)
>
> But that code errors on the TryCast line. Please explain how to use this
> code appropriately.
>
> And I am unclear what the canQuit flag is used for:
> Dim canQuit As Boolean


 
Reply With Quote
 
Derek Hart
Guest
Posts: n/a
 
      29th Dec 2009
When I run this process, it works fine the first time. After the first run,
Outlook is running. Then let's say the user exits Outlook. It is still in
the task manager. Then when your code looks to see if it is there, it is.
But then the code tries to get the Outlook with this line:

objOutlook = TryCast(Marshal.GetActiveObject("Outlook.Application"),
Outlook.Application)

But it is not really there. So the code errors. Should I trap for that and
then get Outlook the other way:
Dim _app As New Outlook.ApplicationClass()
objOutlook = DirectCast(_app, Outlook.Application)

I guess the global variable keeps Outlook in the task manager, but even when
I was not doing this process Outlook still stayed in the task manager. It
never seems to exit, even with this:
Marshal.ReleaseComObject(objOutlook)
objOutlook = Nothing

And is there code to exit it properly in the Explorer and Inspector Close()
events? I was unclear on this... I am not displaying Outlook UI, but just
WindowsForms windows that read and write data to/from the pst file. Do I
have to use these events to properly close and get rid of Outlook in the
task manager?





"Ken Slovak - [MVP - Outlook]" <(E-Mail Removed)> wrote in message
news:O$(E-Mail Removed)...
> _outlookApp is declared at a global or class level. I just call the method
> I showed to instantiate an Outlook.Application object declared as
> _outlookApp. I use the flag value canQuit to know if I should close
> Outlook when I'm done, or if it was already running I just leave it alone.
>
> The code I showed is in C#, if you are going to use it in a VB.NET
> application you will need to translate it from C#.
>
> That code is pretty much the equivalent of calling GetObject() in VB6 on
> an Outlook.Application object and then calling CreateObject() or New if
> the GetObject() call fails.
>
> --
> 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
>
>
> "Derek Hart" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Wow... thank you for this code. A few things...
>>
>> I am wondering if I should simply run this code first to instantiate
>> Outlook, and then use my code as I did before to go get it. Since you did
>> not send me a function, it looks like I am not retrieving the instance
>> from this routine and pulling it into another routine.
>>
>> A couple variables were not declared in your code, so I am unclear how to
>> use this. Should I declare this as a global variable. If so, I tried
>> that, and the code is having problems.
>> Dim _outlookApp As Outlook.Application
>>
>> So in my routine I load Outlook this way:
>> InstantiateOutlook()
>>
>> Then the global variable _outlookApp is used everywhere. But then at the
>> end of my routine, I release the com object and set it to nothing. So
>> then I thought I should put the code as follows in your routine.
>> objOutlook = New Outlook.Application
>> If collCount <> 0 Then
>> ' Outlook already running, hook into the Outlook instance
>> objOutlook =
>> TryCast(Marshal.GetActiveObject("Outlook.Application"),
>> Outlook.Application)
>>
>> But that code errors on the TryCast line. Please explain how to use this
>> code appropriately.
>>
>> And I am unclear what the canQuit flag is used for:
>> Dim canQuit As Boolean

>



 
Reply With Quote
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      29th Dec 2009
If Outlook is not completely exiting as a result of running your code it
means you aren't releasing all your Outlook objects. You need to release
every one of them. It doesn't matter from where your shutdown code is
called, from an Explorer or Inspector Close() event or Application.Quit(),
or anywhere else. You just release everything.

--
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


"Derek Hart" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> When I run this process, it works fine the first time. After the first
> run, Outlook is running. Then let's say the user exits Outlook. It is
> still in the task manager. Then when your code looks to see if it is
> there, it is. But then the code tries to get the Outlook with this line:
>
> objOutlook = TryCast(Marshal.GetActiveObject("Outlook.Application"),
> Outlook.Application)
>
> But it is not really there. So the code errors. Should I trap for that and
> then get Outlook the other way:
> Dim _app As New Outlook.ApplicationClass()
> objOutlook = DirectCast(_app, Outlook.Application)
>
> I guess the global variable keeps Outlook in the task manager, but even
> when I was not doing this process Outlook still stayed in the task
> manager. It never seems to exit, even with this:
> Marshal.ReleaseComObject(objOutlook)
> objOutlook = Nothing
>
> And is there code to exit it properly in the Explorer and Inspector
> Close() events? I was unclear on this... I am not displaying Outlook UI,
> but just WindowsForms windows that read and write data to/from the pst
> file. Do I have to use these events to properly close and get rid of
> Outlook in the task manager?
>
>


 
Reply With Quote
 
Derek Hart
Guest
Posts: n/a
 
      29th Dec 2009
Shouldn't this be doing it?

Class Level
Dim objOutlook As Outlook.Application

Subroutine
Dim objNameSpace As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Dim objItem As Outlook.MailItem
InstantiateOutlook()
objNameSpace = objOutlook.GetNamespace("MAPI")
objFolder =
objNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
objNameSpace.Logon()

' Do processing

' Release all objects

Marshal.ReleaseComObject(objOutlook)
Marshal.ReleaseComObject(objNameSpace)
Marshal.ReleaseComObject(objFolder)
Marshal.ReleaseComObject(objItem)
objOutlook = Nothing
objNameSpace = Nothing
objFolder = Nothing
objItem = Nothing

' This is the code for InstantiateOutlook
Private Sub InstantiateOutlook()
Try
Dim canQuit As Boolean
Dim olProcess As String = "Outlook.exe"
Dim query As New SelectQuery("SELECT Name FROM Win32_Process
WHERE name='" & olProcess & "'")
Dim searcher As New ManagementObjectSearcher(query)
Dim objectCollection As ManagementObjectCollection =
searcher.Get()
Dim collCount As Integer = objectCollection.Count
searcher.Dispose()
objectCollection.Dispose()
searcher = Nothing
objectCollection = Nothing
If collCount <> 0 Then
' Outlook already running, hook into the Outlook instance
objOutlook =
TryCast(Marshal.GetActiveObject("Outlook.Application"), Outlook.Application)
If objOutlook IsNot Nothing Then
canQuit = False
End If
Else
' Outlook not already running, start it
Dim _app As New Outlook.ApplicationClass()
objOutlook = DirectCast(_app, Outlook.Application)
End If

SecurityManager1.ConnectTo(objOutlook)
SecurityManager1.DisableOOMWarnings = True

Catch ex As System.Exception
MessageBox.Show(ex.Message)
End Try
End Sub



"Ken Slovak - [MVP - Outlook]" <(E-Mail Removed)> wrote in message
news:OZKL%(E-Mail Removed)...
> If Outlook is not completely exiting as a result of running your code it
> means you aren't releasing all your Outlook objects. You need to release
> every one of them. It doesn't matter from where your shutdown code is
> called, from an Explorer or Inspector Close() event or Application.Quit(),
> or anywhere else. You just release everything.
>
> --
> 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
>
>
> "Derek Hart" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> When I run this process, it works fine the first time. After the first
>> run, Outlook is running. Then let's say the user exits Outlook. It is
>> still in the task manager. Then when your code looks to see if it is
>> there, it is. But then the code tries to get the Outlook with this line:
>>
>> objOutlook = TryCast(Marshal.GetActiveObject("Outlook.Application"),
>> Outlook.Application)
>>
>> But it is not really there. So the code errors. Should I trap for that
>> and then get Outlook the other way:
>> Dim _app As New Outlook.ApplicationClass()
>> objOutlook = DirectCast(_app, Outlook.Application)
>>
>> I guess the global variable keeps Outlook in the task manager, but even
>> when I was not doing this process Outlook still stayed in the task
>> manager. It never seems to exit, even with this:
>> Marshal.ReleaseComObject(objOutlook)
>> objOutlook = Nothing
>>
>> And is there code to exit it properly in the Explorer and Inspector
>> Close() events? I was unclear on this... I am not displaying Outlook UI,
>> but just WindowsForms windows that read and write data to/from the pst
>> file. Do I have to use these events to properly close and get rid of
>> Outlook in the task manager?
>>
>>

>



 
Reply With Quote
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      30th Dec 2009
That releases all the objects you are showing, is that release code being
called and are there any other objects not being released?

--
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


"Derek Hart" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Shouldn't this be doing it?
>
> Class Level
> Dim objOutlook As Outlook.Application
>
> Subroutine
> Dim objNameSpace As Outlook.NameSpace
> Dim objFolder As Outlook.MAPIFolder
> Dim objItem As Outlook.MailItem
> InstantiateOutlook()
> objNameSpace = objOutlook.GetNamespace("MAPI")
> objFolder =
> objNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
> objNameSpace.Logon()
>
> ' Do processing
>
> ' Release all objects
>
> Marshal.ReleaseComObject(objOutlook)
> Marshal.ReleaseComObject(objNameSpace)
> Marshal.ReleaseComObject(objFolder)
> Marshal.ReleaseComObject(objItem)
> objOutlook = Nothing
> objNameSpace = Nothing
> objFolder = Nothing
> objItem = Nothing
>
> ' This is the code for InstantiateOutlook
> Private Sub InstantiateOutlook()
> Try
> Dim canQuit As Boolean
> Dim olProcess As String = "Outlook.exe"
> Dim query As New SelectQuery("SELECT Name FROM Win32_Process
> WHERE name='" & olProcess & "'")
> Dim searcher As New ManagementObjectSearcher(query)
> Dim objectCollection As ManagementObjectCollection =
> searcher.Get()
> Dim collCount As Integer = objectCollection.Count
> searcher.Dispose()
> objectCollection.Dispose()
> searcher = Nothing
> objectCollection = Nothing
> If collCount <> 0 Then
> ' Outlook already running, hook into the Outlook instance
> objOutlook =
> TryCast(Marshal.GetActiveObject("Outlook.Application"),
> Outlook.Application)
> If objOutlook IsNot Nothing Then
> canQuit = False
> End If
> Else
> ' Outlook not already running, start it
> Dim _app As New Outlook.ApplicationClass()
> objOutlook = DirectCast(_app, Outlook.Application)
> End If
>
> SecurityManager1.ConnectTo(objOutlook)
> SecurityManager1.DisableOOMWarnings = True
>
> Catch ex As System.Exception
> MessageBox.Show(ex.Message)
> End Try
> End Sub
>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux Bulletproof ? Better read this if you think so. Jasper Windows Vista General Discussion 73 27th May 2008 06:43 PM
Outlook Beta Crashing (data file crashing?) =?Utf-8?B?QWxlamFuZHJv?= Microsoft Outlook Discussion 1 29th Oct 2006 11:47 AM
BulletProof software mgm Windows XP Security 14 23rd Jul 2005 12:22 AM
Bulletproof backup - how to test? deko Windows XP General 31 26th Jun 2005 07:42 PM
Bulletproof Freeware alserlhsd Freeware 5 7th Aug 2003 10:22 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:26 PM.