2015-10-13 215 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

    相關問題