模拟代码中的用户可能会使 Outlook 在停止响应或导致方法失败的错误消息

针对 Office 2003 的支持已终止

Microsoft 已于 2014 年 4 月 8 日终止了针对 Office 2003 的支持。该更改已影响到您的软件更新和安全选项。 了解这一措施对于您的含义以及如何继续保持受保护状态。

注意:这篇文章是由无人工介入的微软自动的机器翻译软件翻译完成。微软很高兴能同时提供给您由人工翻译的和由机器翻译的文章, 以使您能使用您的语言访问所有的知识库文章。然而由机器翻译的文章并不总是完美的。它可能存在词汇,语法或文法的问题,就像是一个外国人在说中文时总是可能犯这样的错误。虽然我们经常升级机器翻译软件以提高翻译质量,但是我们不保证机器翻译的正确度,也不对由于内容的误译或者客户对它的错误使用所引起的任何直接的, 或间接的可能的问题负责。

点击这里察看该文章的英文版: 821470
本文已归档。它按“原样”提供,并且不再更新。
症状
您在运行代码的模拟来访问邮箱的用户时 Microsoft Office Outlook 2007,Outlook 2003 或 Outlook 2002 可能会停止响应或者您可能会收到与以下类似的错误消息:
方法 ~ 的对象 ~ 失败
原因
如果模拟用户时,会创建新线程,则可能会出现此问题。MAPI 和协作数据对象 (CDO) 创建新线程作为一个正常的函数,这些新的线程不会继承被模拟的用户令牌的完全访问权限。

注意 模拟与 MAPI 不受支持的行为。
替代方法
Microsoft 提供的编程示例只,用于说明不附带任何明示或暗示保证。这包括,但不限于对适销性或针对特定用途的适用性的暗示的担保。本文假定您熟悉演示了正在使用的编程语言以及用于创建和调试过程的工具。Microsoft 支持工程师可以帮助解释某个特定过程的功能。但是,他们不会修改这些示例以提供额外的功能或构建过程来满足您的具体要求。

要变通解决此问题,拆分为两个单独的程序的代码。

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:
'<-- Launcher programConst LOGON32_LOGON_INTERACTIVE = 2Const LOGON32_PROVIDER_DEFAULT = 0Const CREATE_DEFAULT_ERROR_MODE = &H4000000Private Type STARTUPINFO   cb As Long   lpReserved As Long ' !!! must be Long for Unicode string   lpDesktop As Long  ' !!! must be Long for Unicode string   lpTitle As Long    ' !!! must be Long for Unicode string   dwX As Long   dwY As Long   dwXSize As Long   dwYSize As Long   dwXCountChars As Long   dwYCountChars As Long   dwFillAttribute As Long   dwFlags As Long   wShowWindow As Integer   cbReserved2 As Integer   lpReserved2 As Long   hStdInput As Long   hStdOutput As Long   hStdError As LongEnd TypePrivate Type PROCESS_INFORMATION   hProcess As Long   hThread As Long   dwProcessId As Long   dwThreadId As LongEnd TypePrivate Declare Function CreateProcessAsUser Lib "advapi32.dll" _      Alias "CreateProcessAsUserA" _      (ByVal hToken As Long, _      ByVal lpApplicationName As Long, _      ByVal lpCommandLine As String, _      ByVal lpProcessAttributes As Long, _      ByVal lpThreadAttributes As Long, _      ByVal bInheritHandles As Long, _      ByVal dwCreationFlags As Long, _      ByVal lpEnvironment As Long, _      ByVal lpCurrentDirectory As String, _      lpStartupInfo As STARTUPINFO, _      lpProcessInformation As PROCESS_INFORMATION) As LongPrivate Declare Function LogonUser Lib "advapi32.dll" Alias "LogonUserA" ( _      ByVal lpszUsername As String, _      ByVal lpszDomain As String, _      ByVal lpszPassword As String, _      ByVal dwLogonType As Long, _      ByVal dwLogonProvider As Long, _      phToken As Long) As LongPrivate Declare Function CloseHandle Lib "kernel32" ( _      ByVal hObject As Long) As LongPrivate Sub Command1_Click()      Dim hToken As Long      Dim ulResult As Long      Dim startup As STARTUPINFO      Dim process As PROCESS_INFORMATION          ulResult = LogonUser("ImpersonatedUsed", "ImpersonatedDomain", _         "ImpersonatedUserPassword", LOGON32_LOGON_INTERACTIVE, _            LOGON32_PROVIDER_DEFAULT, hToken)      If ulResult = 0 Then         MsgBox "Error in LogonUser:  " & Err.LastDllError         Exit Sub      End If      startup.cb = Len(startup)      'TODO: Replace 'mail.exe' with the name of the program you wish to start      ulResult = CreateProcessAsUser(hToken, 0&, "mail.exe", 0&, 0&, _         False, CREATE_DEFAULT_ERROR_MODE, 0&, "path", startup, process)      If ulResult = 0 Then         MsgBox "Error in CreateProcessAsUser:  " & Err.LastDllError         Exit Sub      End If          CloseHandle hToken    End Sub'<-- End of first program '<-- Start of second process'<-- Mail.exe project:Private Sub Command1_Click()On Error GoTo ErrHandler   Dim oSession 'As MAPI.Session   Set oSession = CreateObject("MAPI.Session")   oSession.Logon , , , , , True, "ServerName" & vbLf & "MailboxName"   Dim oFolder 'As MAPI.Folder   Set oFolder = oSession.GetDefaultFolder(1) 'CdoDefaultFolderInbox   Set oMessages = oFolder.Messages   Set oMessage = oMessages.GetFirst   MsgBox oMessage.Subject   Set oMessage = Nothing   MsgBox "1"   Set oMessages = Nothing   MsgBox "2"   Set oFolder = Nothing   MsgBox "3"   oSession.Logoff  '   MsgBox "4"      Set oSession = Nothing   MsgBox "Done"   Exit Sub    ErrHandler:   MsgBox Err.Number & "   -->   " & Err.Description   Set oMessage = Nothing   Set oMessages = Nothing   Set oFolder = Nothing   oSession.Logoff   Set oSession = NothingEnd Sub
状态
Microsoft 已经确认这是在"适用于"一节中列出的 Microsoft 产品中的问题。
OFFQFE 8382

警告:本文已自动翻译

属性

文章 ID:821470 - 上次审阅时间:01/11/2015 22:49:58 - 修订版本: 2.1

Microsoft Outlook 2002 标准版, Microsoft Office Outlook 2003, Microsoft Office Outlook 2007

  • kbnosurvey kbarchive kbmt kberrmsg kbbug kbprb KB821470 KbMtzh
反馈