1

I'm building an installer using advanced installer and have run into a problem trying to add dates into the log file. I tried a command using cmd which worked, however when I added it to the MSI commandline all the date values came out as blank. Below is the parameters I pass for the MSI

/L*V "C:\Log_%date:~4,2%.%date:~7,2%.%date:~10,4%-%time:~0,2%.%time:~3,2%.%time:~6,2%.log"

We are trying to make the log be Log_04.05.2019-15.03.45.log instead of Log.log since the logs get overwritten when uninstall happens or on a retry of an installation..

Kaizer69
  • 373
  • 4
  • 18
  • Where in the Advanced Installer views do you specify this command line? What version do you run? – Stein Åsmul Apr 06 '19 at 03:20
  • 2
    @SteinÅsmul I assume he sets it in Builds page. There is an additional "MSI Command line" field available if your project output is set to EXE package with MSI inside (option available in the same view). – Bogdan Mitrache Apr 08 '19 at 07:04

1 Answers1

1

Advanced Installer: Sorry, I see that I must have misunderstood. You are trying to set the log file name from within Advanced Installer. Will have a quick look. Where do you specify this command line in the tool? Please note that setting the logging policy for "Global Logging" will ensure unique log file names and that every MSI operation is logged in TMP.


Clarification: So it looks like you don't want to write to the log, but to control the file name of the log file itself?


PowerShell: I find batch files clunky with regards to stuff like this. Can you invoke the installation via Powershell? I don't really use PowerShell, but seeing as it can use .NET, maybe a simple conversion of this C# call would do the trick?

You want something like: "Log_04.05.2019-15.03.45.log", so you could perhaps try this in C#:

Console.WriteLine("Log_" + DateTime.Now.ToString("dd.MM.yyyy-HH.mm.ss") + ".log");

Here is a blog on using PowerShell with Windows Installer, see towards the bottom for this PowerShell snippet (again, I do not use PowerShell for this purpose):

$DataStamp = get-date -Format yyyyMMddTHHmmss
$logFile = '{0}-{1}.log' -f $file.fullname,$DataStamp

$MSIArguments = @(
    "/i"
    ('"{0}"' -f $file.fullname)
    "/qn"
    "/norestart"
    "/L*v"
    $logFile
)
Start-Process "msiexec.exe" -ArgumentList $MSIArguments -Wait -NoNewWindow 

Maybe also have a read about the Windows Installer PowerShell Module (Heath Stewart) as linked to in this general purpose answer: How can I use powershell to run through an installer?. Special-purpose PowerShell Module making Windows Installer operations less clunky.


Some Links:

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
  • Hello Stein, Thanks for your answer, I'm trying to set it within advanced installer in the builds page since I'm having advanced installer create the bootstrapper, so Powershell is not an option. – Kaizer69 Apr 08 '19 at 19:49
  • If you can't get that working, I suppose you should investigate the [**MsiLogging property**](https://docs.microsoft.com/en-us/windows/desktop/msi/msilogging). That should give you a unique log file for each run - at least. Here is [an untested github.com sample](https://github.com/habeebtc/WixPowershell/blob/da225eed843b0f523ddd11197f63de5f5a646aec/SamplePowershell/Code/Property.wxs). And [more hits](https://github.com/search?l=XML&q=%3CWix+MsiLogging&type=Code). Personally I like to set the [global logging policy](https://stackoverflow.com/a/54458890/129130) instead (registry keys). – Stein Åsmul Apr 09 '19 at 01:55
  • Hello Stein, It seems I can only set static paths for the MsiLogging property which we already have. Advanced installer date properties have the wrong formatting and would not be allowed by OS. Thanks for your help though – Kaizer69 Apr 09 '19 at 13:45
  • You don't set a path, you specify what logging you want and the log file shows up in the temp folder. You can even open that log file after the installation is complete since you can retrieve its full path via the [**MsiLogFileLocation**](https://learn.microsoft.com/en-us/windows/desktop/msi/msilogfilelocation) property. – Stein Åsmul Apr 09 '19 at 14:01
  • I think Advanced Installer has features to enable a check box to open a log after installation. I think you just enable it in the dialogs. Been a while. You can also add a custom action to copy the log file somewhere triggered by a dialog button click event or something like that. – Stein Åsmul Apr 09 '19 at 14:09