0

When trying to create an instance of Outlook however the UAC is blocking this process. I know on windows 7 UAC can be changed but windows 8 it can not be fully removed. This is the reason I need admin right for this process.

        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)
ɐsɹǝʌ ǝɔıʌ
  • 4,440
  • 3
  • 35
  • 56
D.Alexander
  • 81
  • 1
  • 1
  • 7

2 Answers2

0

You'll need to modify the Manifest file so that the application starts in Administrator mode by default

Manifest file is a file in VB project which contains the information about the contents of file distribution. It also allow the application to state the privilege level at which it needs to run, and whether it requires elevation.

  1. Open VB.NET project and click Project > Add New Item

  2. A dialog box will open. Select Application Manifest File and click Add.

  3. Open this manifest file and look for the following code:

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

  1. Replace asInvoker with requireAdministrator or highestAvailable

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

This will make the application run with highest available privileges.

ɐsɹǝʌ ǝɔıʌ
  • 4,440
  • 3
  • 35
  • 56
  • There is no Application Manifest File in the Item dialog box. I am using VS 2010. I have changed the Manifest File in the bin folder but this does not do any thing. – D.Alexander Oct 13 '15 at 15:10
  • Take a look at [this question](http://stackoverflow.com/questions/8141795/how-to-add-an-assembly-manifest-to-a-net-executable) and the accepted answer. It explains how to add a manifest to your project in VS2010. – ɐsɹǝʌ ǝɔıʌ Oct 13 '15 at 15:34
0

COM system will refuse to marshal calls between 2 COM objects in different security contexts. Make sure both your app and Outlook are running in the same context.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78