send Outlook Task programmatically from ASP.NET page

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I have an asp.net application written in VB.NET that allows the user to
assign a task to other users. On my development laptop, everything works
fine. On the web server, it doesn't work. Below are the code and error
details:

I am enabling/disabling Impersonation on the fly with the following code:

Dim LOGON32_LOGON_INTERACTIVE As Integer = 2
Dim LOGON32_PROVIDER_DEFAULT As Integer = 0

Dim impersonationContext As WindowsImpersonationContext

Declare Function LogonUserA Lib "advapi32.dll" (ByVal lpszUsername As
String, _
ByVal lpszDomain As String, _
ByVal lpszPassword As String, _
ByVal dwLogonType As Integer, _
ByVal dwLogonProvider As Integer, _
ByRef phToken As IntPtr) As Integer

Declare Auto Function DuplicateToken Lib "advapi32.dll" ( _
ByVal ExistingTokenHandle As IntPtr, _
ByVal ImpersonationLevel As Integer, _
ByRef DuplicateTokenHandle As IntPtr) As Integer

Declare Auto Function RevertToSelf Lib "advapi32.dll" () As Long
Declare Auto Function CloseHandle Lib "kernel32.dll" (ByVal handle As
IntPtr) As Long

Private Function impersonateValidUser(ByVal userName As String, ByVal
domain As String, ByVal password As String) As Boolean

Dim tempWindowsIdentity As WindowsIdentity
Dim token As IntPtr = IntPtr.Zero
Dim tokenDuplicate As IntPtr = IntPtr.Zero
impersonateValidUser = False
Try
If RevertToSelf() Then
If LogonUserA(userName, domain, password,
LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, token) <> 0 Then
If DuplicateToken(token, 2, tokenDuplicate) <> 0 Then
tempWindowsIdentity = New
WindowsIdentity(tokenDuplicate)
impersonationContext =
tempWindowsIdentity.Impersonate()
If Not impersonationContext Is Nothing Then
impersonateValidUser = True
End If
End If
End If
End If
If Not tokenDuplicate.Equals(IntPtr.Zero) Then
CloseHandle(tokenDuplicate)
End If
If Not token.Equals(IntPtr.Zero) Then
CloseHandle(token)
End If
Catch ex As Exception

End Try
End Function

Private Sub undoImpersonation()
impersonationContext.Undo()
End Sub



And I call it like:

If impersonateValidUser("secretusername", "", "secretuserpassword") Then
SendTask(Request.QueryString("issueid"))
undoImpersonation()
End If

The "secretusername" is a local admin on the box and Outlook is installed on
the box and there is a profile created for that user. Since the user is a
local admin, it successfully processes the following line of code:

Dim app As Outlook.ApplicationClass = New Outlook.ApplicationClass

But it errors out with a "The operation failed." error at this line of code:

Dim tsk As Outlook.TaskItem =
CType(app.CreateItem(Outlook.OlItemType.olTaskItem), Outlook.TaskItem)


Here's the important details of the SendTask function I used above:

Dim app As Outlook.ApplicationClass = New
Outlook.ApplicationClass
Dim tsk As Outlook.TaskItem =
CType(app.CreateItem(Outlook.OlItemType.olTaskItem), Outlook.TaskItem)
tsk.Body = "You have been tasked with Issue Number 1"
tsk.StartDate = DateTime.Now
tsk.DueDate = DateTime.Now
tsk.Subject = "Item 1"
tsk.Recipients.Add("user@xxxxxxxx")
tsk.Assign()
tsk.Save()
tsk.Send()
app = Nothing
tsk = Nothing

I suspect it works fine on my development laptop since I'm running Outlook
whereas I am not running Outlook on the web box (but it is installed and
configured with a usuable profile).

I've been banging on this all week with no success. Does anyone out there
know what I'm doing wrong?

Please help. Thanks in advance,
Steve.

.



Relevant Pages

  • Re: closing all applicatios vs processes
    ... Dim targets() As System.Diagnostics.Process ... Declare Auto Function EnumWindows Lib "user32" (ByVal lpEnumFunc As EnumWindowsProc, ByVal lParam As IntPtr) As Boolean ...
    (microsoft.public.dotnet.languages.vb)
  • Re: libmp4v2.dll help
    ... Declare Auto Function MP4GetMetadataName Lib "e:\libmp4v2.dll" ... (ByVal filehandle As IntPtr, ByRef val As IntPtr) ... Dim filehandle As IntPtr ...
    (microsoft.public.dotnet.languages.vb)
  • Re: libmp4v2.dll help
    ... Declare Auto Function MP4GetMetadataName Lib "e:\libmp4v2.dll" ... Dim filehandle As Long ... Dim result As Boolean ... Dim test As IntPtr ...
    (microsoft.public.dotnet.languages.vb)
  • Re: ASP.NET Process Identity???
    ... Private ImpersonationContext As WindowsImpersonationContext ... Declare Auto Function LogonUser Lib "advapi32.dll" (ByVal lpszUsername As ... ByRef phToken As IntPtr) As Integer ... Public Function Personificar() As Boolean ...
    (microsoft.public.dotnet.security)
  • Re: Win API cant retrieve palette from clipboard
    ... lpLogPalette As IntPtr) As IntPtr ... Public Declare Auto Function SetClipboardData Lib "user32.dll" (ByVal ... Dim peAs PALETTEENTRY ...
    (microsoft.public.dotnet.languages.vb)