Article ID: 821470 - View products that this article applies to.
When you run code that impersonates a user to access a mailbox, Microsoft Office Outlook 2007, Outlook 2003, or Outlook 2002 may stop responding or you may receive an error message that is similar to the following:
Method '~' of object '~' failed
This problem may occur if new threads are created when you impersonate a user. MAPI and Collaboration Data Objects (CDO) create new threads as a normal function, and these new threads do not inherit full access to the impersonated users token.
Note Impersonation with MAPI is not a supported behavior.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure. However, they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
To work around this problem, split your code into two separate programs.
For example, the first program should do the impersonation by using LogonUser, and then start the second program as a separate process by using CreateProcessAsUser as in the following sample Visual Basic code:
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.