1

I am facing an issue in my windows7 32bit Pc(on i3).I have Outlook 2010 and Delphi 7 on it. I am using following code to detect Outlook is running or not.

ClassID := ProgIDToClassID(ClassName);
Result  := (GetActiveObject(ClassID, nil, Unknown) = S_OK);

This fails, ie, result become false and yet in other PCs this working fine.

The error I'm getting is MK_E_Unavailable.

Update:

May be it just happening with me only.

procedure TForm1.Button1Click(Sender: TObject);
function IsObjectActive(ClassName: string): Boolean;
var
  ClassID: TCLSID;
  Unknown: IUnknown;
begin
  try
    ClassID := ProgIDToClassID(ClassName);
    Result  := (GetActiveObject(ClassID, nil, Unknown) =S_OK );
  except
      Result := False;
    end;
end;
begin
  if IsObjectActive('Outlook.Application') Then
    ShowMessage('OutLook is there.')
  else
    ShowMessage('OutLook is not there.')
end;

Plz note OL is running and

  • When I am running the created exe, I am getting message "OutLook is there".
  • when I am running from Delphi IDE, I am getting Message 'OutLook is not there.'

This happens always, I am using Delphi 7 on Windows 7, running with Run as Admin. Kindly tell me why this happening and how can I fix this.

What's the issue of Delphi 7 on Windows 7.

Please suggest.

Community
  • 1
  • 1
Vijesh V.Nair
  • 157
  • 1
  • 18
  • 1
    The first thing to do is find out what GetActiveObject returns and decode the HRESULT value – David Heffernan Dec 23 '11 at 08:29
  • 1
    A quick web search suggests this is related to integrity levels – David Heffernan Dec 23 '11 at 12:36
  • The error you list officially means the object is not running. – Johan Dec 23 '11 at 22:03
  • WinError.h: `//MessageId: MK_E_UNAVAILABLE // MessageText: Operation unavailable #define MK_E_UNAVAILABLE _HRESULT_TYPEDEF_(0x800401E3L)` Not an answer, just a note. – Ian Boyd Dec 24 '11 at 04:10
  • _When_ are you executing this code? Did Outlook just start up? Outlook doesn't directly install itself in the Running Object Table at startup, it usually waits for the first focus switch / activate. – Paul-Jan Dec 24 '11 at 11:41
  • 1
    Also... _from where_ are you executing this code? A regular application? A service? An ISAP dll? – Paul-Jan Dec 24 '11 at 11:41
  • 1
    I am executing the above code from Delphi 7, ie, its happening in my Development machine. – Vijesh V.Nair Dec 26 '11 at 07:53
  • Thanks I think Seems the issue is in OLE, I skipped the use of above code. But stuck when using outlook 2010 automation in Windows 7. I am attaching the code. FOutlookApp := TOutlookApplication.Create(self); FOutlookApp.OnQuit:=OutlookOnQuit; FOutlookApp.AutoQuit := False; FOutlookApp.ConnectKind:= ckRunningOrNew; FOutlookApp.Connect; I am getting the message "Server Execution failed" Kindly Help me. I tried to import Outlook OLB as Type Library. when Installing unit, gives error, as classes already installed. Please Help me – Vijesh V.Nair Dec 29 '11 at 10:40

3 Answers3

1

I was facing the same issue and I found the solution.

It's simple, If Outlook is already running, it MUST have the same rights as the process that is trying to use it.

In simple words, if you are running Outlook with admin rights, you must execute your app with admin rights.

Your problem must be that you are running Outlook without admin rights, and Delphi IDE with admin rights. So when you are launching your app from within IDE, the rights doesn't match, and you get the error. This is why when running your app outside the IDE it works as expected. Because outside IDE your app runs without admin rights.

Try to match the rights. This is something to take into account for the end user environment too.

Also, the UAC under Windows Vista and later is known to cause multiple issues with these type of things. If everything else fails, disable UAC (User Account Control, you will find it under your account options) and see what happens.

Apostolis
  • 83
  • 7
1

Here's the entry for GetActiveObject.
http://msdn.microsoft.com/en-us/library/a276e30c-6a7f-4cde-9639-21a9f5170b62%28VS.85%29

If you want to decode the error, you need to find out what the HResult means.
Wikipedia has a link to a ERR.EXE utility from MS that will translate the HResult code into an error description. For COM HResults see: http://matthewbass.com/2005/11/15/decoding-com-hresult-error-codes/.
note the download link in the article is broken, here's a working link: http://www.softlookup.com/display.asp?id=7113 Once you know what the error is, update the question.

If you want to know whether a process is running without using OLE, see: How to check if a process is running using Delphi?

Another option might to use FindWindowEx to check for Outlook 2010 specific windows.
You can use WinID (a spy++ clone) to see the windows used by Outlook 2010.

Community
  • 1
  • 1
Johan
  • 74,508
  • 24
  • 191
  • 319
  • 1
    I'm not sure err.exe is what's needed. This is a COM HRESULT. – David Heffernan Dec 23 '11 at 10:33
  • @davidhefferman ms really do go the extra mile to obfusticate don't they. Thank did an extra search and found: http://matthewbass.com/2005/11/15/decoding-com-hresult-error-codes/ – Johan Dec 23 '11 at 21:50
  • 1
    Thanks I think Seems the issue is in OLE, I skipped the use of above code. But stuck when using outlook 2010 automation in Windows 7. I am attaching the code. FOutlookApp := TOutlookApplication.Create(self); FOutlookApp.OnQuit:=OutlookOnQuit; FOutlookApp.AutoQuit := False; FOutlookApp.ConnectKind:= ckRunningOrNew; FOutlookApp.Connect; I am getting the message "Server Execution failed" Kindly Help me. I tried to import Outlook OLB as Type Library. when Installing unit, gives error, as classes already installed. Please Help me – – Vijesh V.Nair Dec 29 '11 at 10:40
-2

try to use rctrl_renwnd32

try this:

(FindWindow('rctrl_renwnd32', nil) <> 0)

http://users.skynet.be/am044448/Programmeren/VBA/vba_class_names.htm

Dharman
  • 30,962
  • 25
  • 85
  • 135