I have a VB.NET app that detects if outlook is running. Works fine
when I run the app by it's self. When I put it in an MSI as a CA, it
fails, such that the
"Dim oOutlookApp As New Outlook.Application" command throws an
exception with the oh so helpful message "Server execution failed".
My code is as follows:
Try
Dim oOutlookApp As New Outlook.Application
If TypeName(oOutlookApp.ActiveExplorer) = "Nothing" Then
Return False
Else
Return True
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "DetectAppRunning")
End Try
Return False
I know weird things happen inside the MSI and it's hard to get normal
apps to work correctly, but I don't have a clue on how to proceed on
fixing this. Is there a better way to detect if outlook is running?
It doesn't seem to me that you're going in the right direction here. You're
not detecting that Outlook is running, you're
trying to early-bind instantiate Outlook via its COM interface, a completely
different thing. This will cause Outlook to run if it's not already running,
and (because you're using managed code) will need an interop assembly to be
present for your VB.NET code to work, Interop.something.Dll, which is
probably in your app folder from an import but missing when your custom
action runs.

Signature
Phil Wilson [MVP Windows Installer]
----
> I have a VB.NET app that detects if outlook is running. Works fine
> when I run the app by it's self. When I put it in an MSI as a CA, it
[quoted text clipped - 20 lines]
> apps to work correctly, but I don't have a clue on how to proceed on
> fixing this. Is there a better way to detect if outlook is running?
Joe Goeke - 10 Jun 2004 22:41 GMT
As I said before, the CA exe runs fine on the target machine when not
running it from within the MSI. When I run it from in the MSI it
fails. To run it on the target machine, I simply copy the exe and
nothing else to the target machine and run it.
I'm open to other approaches to detect if Outlook is running, but this
method is promoted quite a lot within these google groups as a .Net
way to do this.
The dependant files you mention are:
Microsoft.Office.Interop.Outlook.dll
Office.dll
stdole.dll
All of these are in the GAC, so why would I need to include them on a
system that has Office installed? Do I need to include these files in
my setup so that they can be found when running the CA exe from within
MSI?
If there is a better way to see if outlook is running, I'm all for it.
Thanks!
---JHG
> It doesn't seem to me that you're going in the right direction here. You're
> not detecting that Outlook is running, you're
[quoted text clipped - 28 lines]
> > apps to work correctly, but I don't have a clue on how to proceed on
> > fixing this. Is there a better way to detect if outlook is running?
Phil Wilson - 11 Jun 2004 04:59 GMT
If I go to a system with Outlook installed but not running and run that code
of yours, it *starts* Outlook (with no UI shown). The ActiveExplorer method
tells you if Outlook has a UI showing. It returns Nothing because there's no
UI, but Outlook.exe *is* now running because you fired it up. As a way to
detect if Outlook is *running* it's therefore inaccurate because it really
just looks for a UI. So if you want to know if Outlook has a UI showing,
that code is fine. If you want to know if it's running the answer should
always be yes because you just fired it up! I'm being picky yes, but you
asked to detect if Outlook.exe was running, not whether it had a UI showing.
If a program is using the Outlook COM interface to send mail, it will be
running but that code of yours won't detect it.

Signature
Phil Wilson
[MVP Windows Installer]
> As I said before, the CA exe runs fine on the target machine when not
> running it from within the MSI. When I run it from in the MSI it
[quoted text clipped - 52 lines]
> > > apps to work correctly, but I don't have a clue on how to proceed on
> > > fixing this. Is there a better way to detect if outlook is running?
Joe Goeke - 11 Jun 2004 20:56 GMT
Ok, I see what you are saying, and yes I thought it was a dubious way
to check for outlook running (or as you pointed out UI displayed) ,
but I'm still curious why this code will not run correctly when
executed with in an MSI?
---JHG
> If I go to a system with Outlook installed but not running and run that code
> of yours, it *starts* Outlook (with no UI shown). The ActiveExplorer method
[quoted text clipped - 69 lines]
> > > > apps to work correctly, but I don't have a clue on how to proceed on
> > > > fixing this. Is there a better way to detect if outlook is running?
Phil Wilson - 12 Jun 2004 16:11 GMT
I think it's a permissions problem. The custom action works when Outlook
isn't running, but if it is running it cannot connect to it (COM tries to
use the running Outlook as the COM server for the custom action). Custom
actions run in a DCOM environment - they're not a direct call from the
install, so I think the custom action code doesn't have enough privilege.

Signature
Phil Wilson
[MVP Windows Installer]
Definitive Guide to Windows Installer
http://apress.com/book/bookDisplay.html?bID=280
> Ok, I see what you are saying, and yes I thought it was a dubious way
> to check for outlook running (or as you pointed out UI displayed) ,
[quoted text clipped - 76 lines]
> > > > > apps to work correctly, but I don't have a clue on how to proceed on
> > > > > fixing this. Is there a better way to detect if outlook is running?
Joe Goeke - 15 Jun 2004 01:29 GMT
I don't pretend to know what you mean on the DCOM thing, but for now I
just understand that programs run from within a MSI might not work due
to DCOM vs COM privledges? Did I get that right?
In any event, is there a way to get the required privilege's? Would
"elevated privileges" fix this? I noticed in the MSI docs that CA's
run using user privileges by default, and the user in this case is
Admin, so why would there still not be adequate priviliges?
Is there a way to set a Visual Studio Setup to have elevated
privileges?
Thanks again!
---JHG
> I think it's a permissions problem. The custom action works when Outlook
> isn't running, but if it is running it cannot connect to it (COM tries to
[quoted text clipped - 99 lines]
> > > > > > fixing this. Is there a better way to detect if outlook is
> running?
Phil Wilson - 15 Jun 2004 20:11 GMT
I'm not exactly sure, but when you're in a custom action you're being
impersonated with a particular set of privileges. There's probably something
in the security that doesn't let you connect to a running COM server, but
whether it's actually a missing privilege I'm not sure. I'm beginning to
think you should just look for a process called Outlook.exe. What do you
want to do if it's running? Ask the user to shut it down?

Signature
Phil Wilson [MVP Windows Installer]
----
> I don't pretend to know what you mean on the DCOM thing, but for now I
> just understand that programs run from within a MSI might not work due
[quoted text clipped - 115 lines]
> > > > > > > fixing this. Is there a better way to detect if outlook is
> > running?