Search code examples
windows-installeradvanced-installer

How can I tell whether a property was passed in via command line?


I have a situation where I want to initialize APPDIR via a C# custom action, but I only want to do so if APPDIR wasn't supplied as a command line argument (there's custom logic which occurs in our bootstrapper which I want to use in setting the default path for the MSI as well, as we ship both).

I've tried looking through the tables but it doesn't appear as though the command line arguments are set there.

The logs output:

MSI (c) (A0:78) [16:40:33:995]: Command Line: APPDIR=C:\WHAT CURRENTDIRECTORY=E:\ CLIENTUILEVEL=0 CLIENTPROCESSID=10912

when I set APPDIR=C:\WHAT on the command line, but I cannot find a place to check whether a value was in fact set by command line (rather than by default value, UI or a custom action).


Solution

  • You should be able to do this by just looking for the property at various stages in the install. If it is present before the UI sequence starts (and before any custom actions that might change it) then by definition it must have been set on the command line. So you can have a property SETONCOMMANDLINE and have a type 51 custom action (a set property CA) that sets SETONCOMMANDLINE to true with the condition APPDIR, so it will be set only if APPDIR was already set.

    After the UI sequence (and before anything else that might change it) do the same with a SETINUI property. Have a property set CA that sets SETINUI to true conditioned on -APPDIR AND NOT SETONCOMMANDLINE- so SETINUI will be true if it's been set to a value but it wasn't via the command line. But it might be simpler to have your UI set SETINUI at the same time that it sets APPDIR.

    By the time you need to know how it was set you can do it if -NOT SETINUI AND NOT SETONCOMMANDLINE-