Programmatic Access Security Pop up with Wordeditor

R

Reinfried

Outlook 2007 SP2
Exchange 2007 SP1

I want to create a task with an formated hyperlink in the body.

At
Set objDoc = objInsp.WordEditor
always security boxes pop up !!!!! Why????

This is the Code:
Private Sub CreateNewTaskWithHyperlink()
Dim appOutLook As Outlook.Application
Dim taskOutLook As Outlook.TaskItem
Dim objInsp As Outlook.Inspector
Dim objSel As Word.Selection
Dim strLink As String
Dim strLinkText As String
Dim olAnw As Object
Dim docangebot As Word.Document
Set docangebot = ActiveDocument
'Only For test fix Hyperlink
strLink = "http://www.google.de"
strLinkText = "Googeln" '
'
On Error Resume Next
Set olAnw = GetObject(, "Outlook.Application")
On Error GoTo ErrorToDo
If olAnw Is Nothing Then
Dim wshShell As Object
Dim strPath As String
Dim strOpen As String
Const PATH =
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\Outlook\InstallRoot\Path"
Const APP = "Outlook.exe"
Set wshShell = CreateObject("WScript.Shell")
strPath = wshShell.RegRead(PATH)
strOpen = strPath & APP
Shell strOpen, vbMinimizedNoFocus
Set wshShell = Nothing
End If
Set appOutLook = CreateObject("Outlook.Application")
appOutLook.Session.Logon
Set taskOutLook = appOutLook.CreateItem(olTaskItem)
With taskOutLook
.Subject = "Test hyperlink"
.Importance = olImportanceNormal
'Only for test fix Date
.DueDate = "01.03.2010"
.StartDate = "01.03.2010"
.ReminderTime = "01.03.2010" & " " & "08:00"
'
.ReminderSet = True
Set objInsp = .GetInspector
' ?????????
Set objDoc = objInsp.WordEditor 'Programmatic Access Security
Check
'
Set objSel = objDoc.Windows(1).Selection
objDoc.Hyperlinks.Add objSel.Range, strLink, "", "", strLinkText,
""
Set objSel = objDoc.Windows(1).Selection
'Text before Hyperlink
With objSel
.Collapse wdCollapseStart
.InsertBefore "Das ist der Link zum "
End With
'Text after Hyperlink
Set objSel = objDoc.Windows(1).Selection
With objSel
.Collapse wdCollapseStart
.MoveEnd WdUnits.wdStory, 1
.Select
.InsertAfter " Viel Spass! "
End With
.Importance = olImportanceHigh
.Save
End With
ErrorExit:
Set taskOutLook = Nothing
Set appOutLook = Nothing
Exit Sub
ErrorToDo:
Select Case Err.Number
Case 13
Resume ErrorExit
Case 287
Resume ErrorExit
Case Else
MsgBox Err.Number & ";" & Err.Description
End Select
End Sub

Without WordEditor the code runs without security pop up:

Set appOutLook = CreateObject("Outlook.Application")
appOutLook.Session.Logon
Set taskOutLook = appOutLook.CreateItem(olTaskItem)
With taskOutLook
.Subject = "Test hyperlink"
.Importance = olImportanceNormal
.DueDate = "01.03.2010"
.StartDate = "01.03.2010"
.ReminderTime = "01.03.2010" & " " & "08:00"
.ReminderSet = True
.Body = "Das ist der Link zum " & "http://www.google.at" & " Viel
Spass!"
.Importance = olImportanceHigh
.Save
End With


Reinfried
 
K

Ken Slovak - [MVP - Outlook]

Where is this code running? If it's running in the Outlook VBA you really
should be using the trusted Application object that's provided to you, and
not an untrusted Application object you get from GetObject().

If that's not it then check your code security settings. If Outlook security
is set up correctly and you have an up to date anti-virus software running
you should not get that prompt.
 
R

Reinfried

reinfriedThank's for the Answer.
The Code is running in Word 2007.
In Outlook the security is set to "Always warn me about suspicious activity"
 
K

Ken Slovak - [MVP - Outlook]

What does that tab show for antivirus status? If it's valid then the setting
should be warn me about suspicious activity when my av software is inactive,
etc.

Is this in a corporate setting perhaps where the admins have locked things
down? Or is there no valid antivirus software? If your setting is changeable
then you need to set it to a different setting, which could be dangerous.
 
R

Reinfried

We have set the Programmatic Access Security to "Always warn me about
suspicious activity" because we wor with TerminalServer wit Windows Server
2003 and i hope You know that to detect the status of the antivirus software
on client computers, Outlook 2007 depends on the WSC. Currently, antivirus
products that are compatible with Windows XP SP2 and Windows Vista register
status information with the WSC. Outlook first checks for the current status
of antivirus software by querying the WSC. On computers running Microsoft
Windows Server 2003, because the WSC is not available, Outlook is unable to
detect the status of antivirus software and therefore does not disable
security warnings.

And now oncemore to my Question:

Without WordEditor the code runs without security pop up:

Set appOutLook = CreateObject("Outlook.Application")
appOutLook.Session.Logon
Set taskOutLook = appOutLook.CreateItem(olTaskItem)
With taskOutLook
.Subject = "Test hyperlink"
.Importance = olImportanceNormal
.DueDate = "01.03.2010"
.StartDate = "01.03.2010"
.ReminderTime = "01.03.2010" & " " & "08:00"
.ReminderSet = True
.Body = "Das ist der Link zum " & "http://www.google.at" & " Viel
Spass!"
.Importance = olImportanceHigh
.Save
End With

And with WordEditor the code runs with security pop up:

Set appOutLook = CreateObject("Outlook.Application")
appOutLook.Session.Logon
Set taskOutLook = appOutLook.CreateItem(olTaskItem)
With taskOutLook
.Subject = "Test hyperlink"
.Importance = olImportanceNormal
'Only for test fix Date
.DueDate = "01.03.2010"
.StartDate = "01.03.2010"
.ReminderTime = "01.03.2010" & " " & "08:00"
'
.ReminderSet = True
Set objInsp = .GetInspector
' ?????????
Set objDoc = objInsp.WordEditor 'Programmatic Access Security
Check
'
Set objSel = objDoc.Windows(1).Selection
objDoc.Hyperlinks.Add objSel.Range, strLink, "", "", strLinkText,
""
Set objSel = objDoc.Windows(1).Selection
'Text before Hyperlink
With objSel
.Collapse wdCollapseStart
.InsertBefore "Das ist der Link zum "
End With
'Text after Hyperlink
Set objSel = objDoc.Windows(1).Selection
With objSel
.Collapse wdCollapseStart
.MoveEnd WdUnits.wdStory, 1
.Select
.InsertAfter " Viel Spass! "
End With
.Importance = olImportanceHigh
.Save
End With

Reinfried
 
K

Ken Slovak - [MVP - Outlook]

If that's your setup, which wasn't mentioned before, there's not much you
can do about avoiding the object model guard other than bypassing the
Outlook object model. WordEditor is a restricted object in cases like that.

There are a couple of alternatives. First, you can use a 3rd party library
called Redemption (www.dimastr.com/redemption) to avoid the security, which
is what most of us do.

The alternative to that would be to get the WordEditor window using Win32
API calls, which is ugly and requires callbacks but can be used when you
cannot use Redemption.

For that you have to get the window using FindWindow() and FindWindowEx() to
find a window with your caption and a class of "OpusApp". There will be more
than 1 window with that class, so you need the window caption from
Inspector.Caption, but after the email is saved so the caption is valid.

When you find a candidate for the window you use EnumWindows() and
EnumChildWindows() to check for "OpusApp" and the correct caption, and under
that a window class "_WwF" in the case of Outlook/Word 2007. When you've
found those you get the RECT for the candidate window and match it with the
RECT for the Inspector window you derive from the Inspector's size
attributes.

Once you get that you need to use AccessibleObjectFromWindow() to look for
an accessibility object that exposes IDispatch that's one of the child
windows. When you get that you use the ppvObj parameter of
AccessibleObjectFromWindow() thusly, if ob is that object: ob.Document. That
will be your WordEditor object.

I've done that when customers won't allow the use of 3rd party libraries
such as Redemption, but as you can see from the description of the method
you need to know your Win32 API calls and to spend a lot of time playing
with Spy++.

It's a lot easier to use 1 line of Redemption code than the 200 or so lines
of code a GetWordEditor() and needed subsidiary methods take :)
 
R

Reinfried

Thank's for your answer. From what I'm looking was:

WordEditor is a restricted object in cases like that.

Reinfried
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top