Custom action UI handler/managed code example to launch exe and handle errors other than 0

Posted on 2013-06-21
Last Modified: 2013-06-28
I am creating an MSI using InstallShield 2012 (part of AdminStudio).

The file structure I need installed on the PCs requires Adobe AIR, so I have created custom actions to silently install and uninstall Adobe AIR, and have sequenced these correctly in the Install Exec sequence. (I have the correct distribution license from Adobe)

The problem comes when I want to check (prior to the Adobe AIR installation / uninstall) whether or not AIR is already installed. I am using the Adobe ARH utility - which returns a non-zero value when Adobe AIR is not detected.

I am not a programmer; can anyone design (or point me towards) a managed code sample, or custom dll (or another way) that I can use to be able to correctly handle a non-zero return value from the Adobe ARH utility?

Essentially, install sequence is:
1) Copy files (MSI handles this bit)
2) Run ARH utility as part of a Custom Action to detect installed AIR (terminates with zero if a version is found installed, non-zero otherwise)
3) If previous CA terminated with non-zero value, run next CA (to install Adobe AIR)

uninstall sequence:
1) Run CA to uninstall Adobe AIR
2)Remove Files

(uninstall is fine as it is)

Can anyone give me any pointers, or sample code etc. to execute the ARH utility?
Alternatively, a better way to do this - i.e. Managed code or a custom dll?

Question by:and235100
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
LVL 40

Expert Comment

by:Vadim Rapp
ID: 39267444
Before we get to the custom action analyzing return code, here's indeed the alternative way. To detect if Air is already installed, find out some registry key that tells that it's installed, and create system search looking for that key. For instance, as I can see, there is a key HKEY_CLASSES_ROOT\Applications\ADOBEA~1.EXE\shell\open\command. Then use the result of that system search as a condition of the installation.

But if you really want to run the utility*, you probably need to run custom action type 2 . Incidentally, this custom action is indeed looking for return code 0 as success, so it should work for you. This is still not very good way, since if utility returns non-zero code, the installation will be canceled without telling the real reason. For a better handling, I would write vbscript that would launch the utility, then, depending on the return code, create a registry key. Then system search would look for that registry key as a condition of the installation. This would allow to specify the message to the user.

*) The desire to run the utility instead of looking at the registry key might be based on the belief that Adobe-supplied utility would detect Air in some very reliable way. Given that it's Adobe, it's unlikely. This is based on my personal experience, however the close look on the registry key I specified above, is already an illustration of it.
LVL 32

Author Comment

ID: 39268496
Thank you for your comments. Perhaps checking a condition based on a present registry key is a better way of doing this - but in my experience with several Adobe products, registry keys get left behind, and may result in a false positive.

I take your point regarding the reliability of an Adobe utility - but I would have thought (from my testing so far) that it is fairly reliable at detecting a version of Adobe AIR that is installed. (After all, that it is one of only 5-6 functions it actually is capable of doing! :-) )

What I am really trying to avoid within the msi install is a 1722 error - i.e. when the custom action using the ARH utility returns a non-zero value. ( I could choose to ignore the error code, but that isn't particularly satisfactory either)

Can you give me an example of some vbscript that would work?
Thanks again.
LVL 40

Accepted Solution

Vadim Rapp earned 500 total points
ID: 39268552
>Can you give me an example of some vbscript that would work?

set v = createobject("")
rc ="path\program.exe",,True)
if rc=0 then v.regwrite "HKCR\SOFTWARE\myinstallation\returncode",0

The description of the method "run" is at , and 3nd parameter True ensures wait on return and return code passed back to the script.

The main challenge is in placing arh.exe in place. This custom action has to run before the actual installation, which means that even if the installation installed arh.exe, it would be much later. Which means that arh.exe must be put in place by the custom action itself. I would access the current installation using Session object, access table Binary where I stored arh.exe, and stored it to %temp%. Writing such a code is not very trivial.

I have to warn, however, that although I personally have been using vbscript custom actions without a problem, some developers think it's dangerous (I would argue that (1) writing bad code is possible in vbscript as well as in dll, (2) developer's difficulties don't mean the result code is bad, and (3) antivirus can react on the custom dll as well as on the vbscript).
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

LVL 32

Author Comment

ID: 39268955

I will give this a go.

Is there not a way I can do this without a registry key? As you suggested, with a custom DLL or a small custom exe?

The point being, I should think I can run this after InstallFiles within the sequence, but use a custom exe or wrapper to call the ARH utility. The problem being, there is no error handling from the running of custom actions.
LVL 40

Expert Comment

by:Vadim Rapp
ID: 39269438
> The point being, I should think I can run this after InstallFiles

My whole point was that you want to run this check as install condition, but now that I re-read it, I was probably wrong. Writing to the registry key was part of that idea - you can then create install condition based on the system search for the registry key.

If you are going to run it after InstallFiles, then it's even easier: you can make arh.exe part of the installation, and then run it from installed files, no need to extract it from binary table. But then it would be deferred custom action, to which you would have to pass the INSTALLDIR via CustomActionData property.

Or there can be another way. If arh.exe gets installed along with Adobe Air, such as it is with Adobe Reader, as I can see on my own computer, then you can perform system search for Adobe Air, and run arh.exe from there.

That said, are you sure you even need all this. Even if Air is already installed, you can simply run its installation unconditionally, such as in repair mode, and if it's already in place, the (nested) installation will do nothing at all and won't take much time.
LVL 32

Author Comment

ID: 39270902
That is a very good point you make.
For reference, arh.exe doesn't seem to get installed with Adobe AIR)

Unfortunately, there do not seem to be any "repair" options for installing Adobe AIR. (according to (not a problem, however, as we only add a couple of registry keys in to prevent updates etc.)

The problem is, I cannot handle errors natively, so I will have to ignore the return code, include the registry, and "hope" that an error doesn't occur.

I am already running the ARH utility deferred in system context - which is fine - but I cannot handle any non-zero value that it returns.

Perhaps I am making this too complicated - but there must be a way to "wrap" the arh.exe utility and catch the error. This is by far the best way of checking that Adobe AIR is installed, in my opinion - because it will detect current and future versions.

If I include the Adobe AIR install in my msi - I would have to update this everytime a new version of AIR was released - not particularly satisfactory in my opinion.

Thanks again.
LVL 40

Expert Comment

by:Vadim Rapp
ID: 39273358
> Unfortunately, there do not seem to be any "repair" options for installing Adobe AIR.

Simply run msiexec /qn /i setup.msi . If it's already installed, it will do nothing; if not, it will install. I'm sure, if older version found, it will upgrade. Exactly what you need.

That is, assuming you use from the distribution3 page.
LVL 32

Author Comment

ID: 39285448
All good suggestions. Thanks for your help.

Featured Post

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a collection of issues that people face from time to time and possible solutions to those issues. I hope you enjoy reading it.
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question