2015-10-13 232 views
0

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

似乎在这里丢失了一个问题(?) – dummy

回答

0

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

0

你需要使应用程序在管理员模式下默认启动

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

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

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

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

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

  • 替换asInvokerrequireAdministratorhighestAvailable
  • <requestedExecutionLevel level="highestAvailable" uiAcces="false" />

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

    +0

    项目对话框中没有应用程序清单文件。我正在使用VS 2010.我已经更改了bin文件夹中的Manifest文件,但是这没有做任何事情。 –

    +0

    看看[这个问题](http://stackoverflow.com/questions/8141795/how-to-add-an-assembly-manifest-to-a-net-executable)和接受的答案。它解释了如何在VS2010中为您的项目添加清单。 – equisde

    相关问题