运行 一个实例作为管理员

Running an instance as Administrator

尝试创建 Outlook 实例时,UAC 阻止了此过程。我知道 windows 7 UAC 可以更改,但 windows 8 它不能完全删除。这就是我需要此过程的管理员权限的原因。

        Try
            ' Get running outlook instance (if there is)
            outlook = GetObject(Nothing, OUTLOOK_CLASS)
        Catch ex As Exception
        End Try

        ' No running instance? then create new instance of outlook
        If IsNothing(outlook) = True Then
            Try
                outlook = CreateObject(OUTLOOK_CLASS)
            Catch ex As Exception
            End Try
        End If

        ' Show error message if outlook is not installed
        If IsNothing(outlook) = True Then
            MsgBox(String.Format(My.Resources.ErrorEmailUnableToSend, vbCrLf, My.Settings.EmailNHD), MsgBoxStyle.Exclamation, My.Application.Info.Title)
            Exit Try
        End If

        ' Create the email message
        email = outlook.CreateItem(mailItem)

您需要修改 Manifest 文件,使应用程序默认以管理员模式启动

清单文件是VB项目中的一个文件,其中包含有关文件分发内容的信息。它还允许应用程序声明它需要 运行 的特权级别,以及它是否需要提升。

  1. 打开 VB.NET 项目并单击 Project > Add New Item

  2. 将打开一个对话框。 Select Application Manifest File 并单击 Add

  3. 打开此清单文件并查找以下代码:

<requestedExecutionLevel level="asInvoker" uiAcces="false" />

  1. asInvoker替换为requireAdministratorhighestAvailable

<requestedExecutionLevel level="highestAvailable" uiAcces="false" />

这将使应用程序 运行 具有最高可用权限。

COM 系统将拒绝编组不同安全上下文中的 2 个 COM 对象之间的调用。确保您的应用和 Outlook 在同一上下文中 运行。