尝试创建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)
答案 0 :(得分:0)
您需要修改清单文件,以便默认情况下应用程序以管理员模式启动
清单文件是VB项目中的一个文件,其中包含有关文件分发内容的信息。它还允许应用程序声明它需要运行的权限级别,以及是否需要提升。
打开VB.NET项目,然后点击Project
> Add New Item
将打开一个对话框。选择Application Manifest File
,然后点击Add
。
打开此清单文件并查找以下代码:
<requestedExecutionLevel level="asInvoker" uiAcces="false" />
asInvoker
替换为requireAdministrator
或highestAvailable
<requestedExecutionLevel level="highestAvailable" uiAcces="false" />
这将使应用程序以最高可用权限运行。
答案 1 :(得分:0)
COM系统将拒绝在不同安全上下文中封送2个COM对象之间的调用。确保您的应用和Outlook在相同的上下文中运行。