【问题标题】:Running an instance as Administrator以管理员身份运行实例
【发布时间】:2015-10-13 13:30:38
【问题描述】:

当尝试创建 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)

【问题讨论】:

  • 这里似乎遗漏了一个问题(?)

标签: vb.net outlook uac


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

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

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

    2. 将打开一个对话框。选择Application Manifest File,然后点击Add

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

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

    1. asInvoker 替换为requireAdministratorhighestAvailable

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

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

    【讨论】:

    • 项目对话框中没有应用程序清单文件。我正在使用 VS 2010。我已经更改了 bin 文件夹中的清单文件,但这并没有做任何事情。
    • 看看this question 和接受的答案。它解释了如何在 VS2010 中向您的项目添加清单。
    猜你喜欢
    • 2012-11-22
    • 2016-09-20
    • 2010-11-26
    • 2012-05-28
    • 2011-03-24
    • 2021-08-10
    • 1970-01-01
    • 2022-01-08
    • 2015-01-22
    相关资源
    最近更新 更多