mattfidler / org-outlook.el

org-mode and outlook integration.
43 stars 8 forks source link

Open link fails with "Access is denied" ShellExecute error #4

Open fleimgruber opened 9 years ago

fleimgruber commented 9 years ago

Emacs 24.4.1 Outlook 2010

org-outlook-open fails in the else call at

(w32-shell-execute "open" (concat "outlook:" id))

with the error

error: "ShellExecute failed: Access is denied."

Do you know what could be causing this? Does Emacs need special privileges? Is this a missing setting in outlook?

mattfidler commented 9 years ago

Sorry, for the late reply. You need org-protocol to be setup, including the protocol itself so that entering org-protocol from internet explorere will open emacs.

I haven't checked Emacs 24.4 to see if there are any differences. I'm working on emacs 24.3

fleimgruber commented 9 years ago

org-protocol:// works fine from an iexplore, i.e. I get an Emacs buffer in the running instance.

Still the same error. Will try with Emacs 24.3 - any other hints on debugging in the meantime?

mattfidler commented 9 years ago

I can't reproduce it, so I'm stumped :(

mattfidler commented 9 years ago

Perhaps you are having write access to a temp file?

fleimgruber commented 9 years ago

How would you test with the temp file? BTW, have you tried with emacs 24.4 already?

mattfidler commented 9 years ago

I haven't tested the emacs 24.4, but if explorer opens the emacs link, then its because outlook settings are conservative and think you are opening a virus.

I use a key-binding in outlook, so I can't remember if this happened for me in an upgrade. You could script it in autohotkey. This is what I did for ergoemacs-mode autohotkey script:

execute-extended-command:
  ;; Send to org-outlook if using outlook
  If !WinActive("ahk_class Emacs"){
       If WinActive("ahk_class rctrl_renwnd32"){
          If !FileExist(OutlookSave){
             FileSelectFolder, OutlookSave, ,3, Select Folder to Save
Outlook Emails
             IniWrite, %OutlookSave%, ergoemacs-settings.ini, Outlook, Save
          }
          If !FileExist(EmacsClient){
             FileSelectFile, EmacsClient, 1, , Emacs Client, Emacs Client
(emacs*.exe)
             IniWrite, %EmacsClient%, ergoemacs-settings.ini, Emacs,
EmacsClient
          }
          If (OutlookTemplate == "ERROR") {
                InputBox OutlookTemplate, Org-mode capture template for
emails (can't be blank)
                IniWrite, %OutlookTemplate%, ergoemacs-settings.ini,
Outlook, Template

          }
          Clipboard=
          SendKey("{Ctrl down}{c}{Ctrl up}")
          ClipWait
          EmailBody=%clipboard%
          EmailBody:=uri_encode(EmailBody)
          SendKey("{F12}",0)
          Clipboard=
          While !WinActive("Save As"){
                Sleep 100
          }
          SendKey("{Ctrl down}{c}{Ctrl up}")
          ClipWait
          Counter = 1
          Title=%clipboard%
          Title := uri_encode(Title)
          fileName = %OutlookSave%\%clipboard%-%Counter%.msg
          while FileExist(fileName)
          {
             Counter := Counter + 1
             fileName = %OutlookSave%\%clipboard%-%Counter%.msg
          }
          Clipboard =
          Clipboard := fileName
          ClipWait
          While !WinActive("Save As"){
                Sleep 100
          }
          SendKey("{Backspace}")
          SendInput, %Clipboard%
          SendKey("{Enter}")
          While WinActive("Save As"){
                Sleep 100
          }
          SendKey("{Del}")
          fileName := uri_encode(fileName)
          fileName = "%EmacsClient%"
org-protocol:/capture:/%OutlookTemplate%/%fileName%/%Title%/%EmailBody%
          Run, %fileName%
          }
  }
  return
fleimgruber commented 9 years ago

I don't understand how the autohotkey script is related to the issue.

Is the ahk script then supposed to be run in the w32-shell-execute?

mattfidler commented 9 years ago

The w32-shell-execute is often blocked by corporations or security settings in outlook. Autohotkey is a windows scripting solution that allows you to send keys and actions to windows and then run them by binding them to a keyboard shortcut (http://www.autohotkey.com/). In this case, the autohotkey script saves the email to somewhere in your hard-drive, and then sends the link to emacs directly without having to use w32-shell-execute. Hence it is a work-around.

mattfidler commented 9 years ago

Without testing, I think this autohotkey script would work. It binds the action key to M-x

!x::
         OutlookSave="c:\org-outlook-messages\"
         EmacsClient="c:\emacs\bin\emacsclient.exe"
         OutlookTemplate=""
         Clipboard=
          SendKey("{Ctrl down}{c}{Ctrl up}")
          ClipWait
          EmailBody=%clipboard%
          EmailBody:=uri_encode(EmailBody)
          SendKey("{F12}",0)
          Clipboard=
          While !WinActive("Save As"){
                Sleep 100
          }
          SendKey("{Ctrl down}{c}{Ctrl up}")
          ClipWait
          Counter = 1
          Title=%clipboard%
          Title := uri_encode(Title)
          fileName = %OutlookSave%\%clipboard%-%Counter%.msg
          while FileExist(fileName)
          {
             Counter := Counter + 1
             fileName = %OutlookSave%\%clipboard%-%Counter%.msg
          }
          Clipboard =
          Clipboard := fileName
          ClipWait
          While !WinActive("Save As"){
                Sleep 100
          }
          SendKey("{Backspace}")
          SendInput, %Clipboard%
          SendKey("{Enter}")
          While WinActive("Save As"){
                Sleep 100
          }
          SendKey("{Del}")
          fileName := uri_encode(fileName)
          fileName = "%EmacsClient%"
org-protocol:/capture:/%OutlookTemplate%/%fileName%/%Title%/%EmailBody%
          Run, %fileName%
 return
fleimgruber commented 9 years ago

With the latest ahk (v 1.1.21.03) I get the error

Error: Call to nonexistent function

Specifically: SendKey("{Ctrl down}{c}{Ctrl up}")

Binding M-x in this way would intercept it globally, wouldn't it?

Also, do you know what the corresponding outlook security setting would be?

fleimgruber commented 9 years ago

I resorted to directly using the IMAP server via gnus and link to mail through the gnus:nnimap link types.

mattfidler commented 9 years ago

Sorry. Perhaps if I have time, I will write a script to setup the autohotkey support.

On Tue, Apr 28, 2015, 8:55 AM fleimgruber notifications@github.com wrote:

I resorted to directly using the IMAP server via gnus and link to mail through the gnus:nnimap link types.

— Reply to this email directly or view it on GitHub https://github.com/mlf176f2/org-outlook.el/issues/4#issuecomment-97071815 .