473,729 Members | 2,309 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Outlook security, MAPI32 and RtlMoveMemory (oh my!)

Howdy, all.

I am currently looking for a way to, using VB.NET, get around those
annoying little "Allow Access for X Minutes" dialogs that pop up in
Outlook 2003, without resorting to 3rd party add-ins, utilities, or
changes to Exchange Server policies.

After a lot of digging around, I came across an article on
MAPILab.com that contained some VB6 source code. Here's the URL for
those who are curious:

http://www.mapilab.com/articles/vb_o...ecurity_4.html

Basically the article involves hooking into MAPI32.DLL via API
calls, which gives you a pointer to a structure (SPropValue), which in
turn contains a pointer (stored in val1) to a string variable which
contains the value I want. Anyway, I tried it in VB6, and it worked
like a charm. Exactly what I want. Here's the working VB6 source
code:

Private Declare Function HrGetOneProp Lib "mapi32" Alias
"HrGetOneProp@1 2" ( _
ByVal lpMapiProp As IUnknown, _
ByVal ulPropTag As Long, _
ByRef lppProp As Long) As Long

Private Declare Function MAPIFreeBuffer Lib "mapi32" ( _
ByVal lppProp As Long) As Long

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMem ory" ( _
Destination As Any, Source As Any, ByVal Length As Long)

Private Declare Function lstrlenA Lib "kernel32.d ll" ( _
ByVal lpString As Long) As Long

Private Type SPropValue
ulPropTag As Long
dwAlignPad As Long
val1 As Long
val2 As Long
val3 As Long
End Type

Private Function LPSTRtoBSTR(ByV al lpsz As Long) As String
Dim cChars As Long
cChars = lstrlenA(lpsz)
LPSTRtoBSTR = String$(cChars, 0)
CopyMemory ByVal StrPtr(LPSTRtoB STR), ByVal lpsz, cChars
LPSTRtoBSTR = Trim(StrConv(LP STRtoBSTR, vbUnicode))
End Function

Public Sub PrintEmail()
Dim objSesson As Object
Dim objItem As Object

Set objSession = CreateObject("M API.Session")
objSession.Logo n
Set objItem = objSession.Inbo x.Messages.GetF irst

Dim ptrSProp As Long
ptrSProp = 0
If HrGetOneProp(ob jItem.MAPIOBJEC T, CdoPR_SENDER_NA ME, ptrSProp) =
0 Then
Dim sprop As SPropValue
CopyMemory sprop, ByVal ptrSProp, 20
MsgBox LPSTRtoBSTR(spr op.val1)
MAPIFreeBuffer ptrSProp
End If

Set objItem = Nothing
Set objSession = Nothing
End Sub

Now I am trying to convert it to VB.NET, and this is where it all
goes horribly pear-shaped. I ran it through the upgrader (just to see
what the heck I SHOULD be doing), took care of all the comments and
such, and I have read previous postings regarding upgraded API calls
and believe I have what SHOULD be working code.

However, when I run the new application, the resulting structure
does not contain any non-zero values, and the final string I want is
also blank. Could someone take a look at my source code (posted below)
and see if anything looks glaringly obvious? Or perhaps suggest a
different solution altogether? I'm guessing I'm just doing something
wrong with my CopyMemory calls, but God only knows...

If all else fails, I'll simply turn the VB6 code into a DLL and
just do the COM wrapper thing, but that seems really kludgy, so I'd
like to see this work in .NET.

Thanks in advance! Here's the new source code. Sorry about the
length:

Imports System.Runtime. InteropServices
Imports Microsoft.Offic e.Interop
Imports Microsoft.Offic e.Interop.Outlo ok
Imports MAPI

Module MapiProps
#Region " API Calls "
Public Declare Auto Function HrGetOneProp Lib "mapi32.dll " Alias
"HrGetOneProp@1 2" ( _
<MarshalAsAttri bute(UnmanagedT ype.IUnknown)> ByVal lpMapiProp
As Object, _
ByVal ulPropTag As Integer, _
ByRef lppProp As Integer) As Integer

Private Declare Function MAPIFreeBuffer Lib "mapi32" (ByVal lppProp
As Integer) As Integer

Private Declare Sub CopyMemoryStruc t Lib "kernel32" Alias
"RtlMoveMem ory" ( _
ByVal Destination As SPropValue, _
ByVal Source As Integer, _
ByVal Length As Integer)

Private Declare Sub CopyMemoryStrin g Lib "kernel32" Alias
"RtlMoveMem ory" ( _
ByVal Destination As String, _
ByVal Source As Integer, _
ByVal Length As Integer)

Private Declare Function lstrlenA Lib "kernel32.d ll" (ByVal
lpString As Integer) As Integer
#End Region

Private Structure SPropValue
Dim ulPropTag As Integer
Dim dwAlignPad As Integer
Dim val1 As Integer
Dim val2 As Integer
Dim val3 As Integer
End Structure

Private Function LPSTRtoBSTR(ByV al lpsz As Integer) As String
Dim cChars As Integer = lstrlenA(lpsz)
Dim strValue As String = New String("0", cChars)
CopyMemoryStrin g(strValue, lpsz, cChars)
Return Trim(strValue)
End Function

Public Sub PrintEmail()
Dim objSession As Object
Dim objSesson As Object
Dim objItem As Object

objSession = CreateObject("M API.Session")
objSession.Logo n()
objItem = objSession.Inbo x.Messages.GetF irst

Dim ptrSProp As Integer
ptrSProp = 0
Dim sprop As SPropValue
If HrGetOneProp(ob jItem.MAPIOBJEC T,
MAPI.CdoPropTag s.CdoPR_SENDER_ NAME, ptrSProp) = 0 Then
CopyMemoryStruc t(sprop, ptrSProp, 20)
MsgBox(LPSTRtoB STR(sprop.val1) )
MAPIFreeBuffer( ptrSProp)
End If

Object_Dispose( objItem)
Object_Dispose( objSession)
End Sub

Public Sub Object_Dispose( ByVal aobjItem As Object)
' Add the following statement to the top of any vb file where
you place this Sub
' Imports System.Runtime. InteropServices
Dim count As Integer
Debug.WriteLine ("DisposeObj ect Called")
Try
If aobjItem Is Nothing Then
Exit Try
End If
count = Marshal.Release ComObject(aobjI tem)
Debug.WriteLine (String.Format( "DisposeObj ect - Release {0},
RefCount: {1}", aobjItem.ToStri ng(), count), "")
While count > 0
count = Marshal.Release ComObject(aobjI tem)
End While
Catch ex As SystemException
Debug.WriteLine (String.Format( "DisposeObj ect Exception:
{0}"), ex.Message)
Finally
aobjItem = Nothing
End Try
End Sub
End Module

Nov 21 '05 #1
0 3002

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4947
by: Kimmo Laine | last post by:
Hello, can i set MSMQ security options from my code: I want that whenever i create a new queue, certain rights ( open, read and sen ) are given to certain group. thx Kimmo Laine
0
1018
by: Mads W. | last post by:
Hi, I'm coding a small program that can create new mails in outlook. So far I'm avoding the security warning by only displaying the created mail, and let the user interact to send the mail. But I would like to be able to send the mail. I know there are ways of avoiding the security warning throug Outlook redemption. But their sollution is a little expensive for my use. Can I somehow avoid in any other way?
1
3478
by: Rohith | last post by:
I have written a C# application (not a add in) to access outllook. I retrieve information from Contacts,Inbox and notes folder. But when i run the application I get a Security warning from outlook stating that -A program is trying to access email address..Do you want to allow (Yes/No) and also it asks the time duration for access. Kindly let me know how to suppress this warning message.
3
2224
by: John | last post by:
Hi I am getting the notorious "an application is trying to access your application..." whenever I try to send an email using outlook from within a vb.net app. Is there a way to bypass this? I am using outlook with exchange server. Thanks Regards
14
6957
by: John | last post by:
Hi Is there a way to e-mail using outlook2002 from within vb.net without getting the nasty "An application is trying to access you outlook..." message? Thanks Regards
3
1286
by: Yavuz Bogazci | last post by:
Hi, i am connecting to my outlook via vb.net and mapi. When i want to access an Mailitem an get its properties i get an Security Message form Outlook popping up saying somethin like "A program is try ing to access ...." How can i suppress this message within my application? thanks yavuz bogazci
16
4355
by: ML | last post by:
Is there anyway to get around the security prompt from Outlook when using the object in a vb.net winforms app? I want to be able to load the contacts lists from Outlook but each time it access it you get the security warning.
3
1026
by: =?Utf-8?B?UGF1bERIQw==?= | last post by:
Hi all, another outlook question I'm afraid. is there a way of disabling the security settings within outlook. When my app tries to send an email, a little message appears stating that another program is trying to send an email. Shall Outlook let it. if the user clicks yes then the email goes as per normal. So is there a way of disabling this message? Thanks
4
1267
by: Mike P | last post by:
Is it possible to prevent Outlook security warnings without using a 3rd party tool (i.e. is there some code you can write yourself to do this)? *** Sent via Developersdex http://www.developersdex.com ***
0
8917
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9281
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9142
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8148
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.