2

I am trying the following inside a customaction:

Session.Log("GetOfficeBitness =" & Session.Property("OfficeBitness"))

And I am getting the error:

Error 1720. There is a problem with this Windows Installer package. A script required for this install to complete could not be run. Contact your support personnel or package vendor. Custom action GetOfficeBitness script error -2146827850, Microsoft VBScript runtime error: Object doesn't support this property or method: 'Session.Log' Line 39, Column 9, MSI (c) (FC:94) [05:51:13:621]: Product: Windward Report Designer 32-bit -- Error 1720. There is a problem with this Windows Installer package. A script required for this install to complete could not be run. Contact your support personnel or package vendor. Custom action GetOfficeBitness script error -2146827850, Microsoft VBScript runtime error: Object doesn't support this property or method: 'Session.Log' Line 39, Column 9,

How can I write to the log inside my script?

David Thielen
  • 28,723
  • 34
  • 119
  • 193
  • 1
    Does this answer your question? [Windows Installer Deferred execution - how can we log the custom actions running in deferred mode?](https://stackoverflow.com/questions/57572168/windows-installer-deferred-execution-how-can-we-log-the-custom-actions-running) – user692942 Feb 23 '20 at 18:29
  • Does this answer your question? [how to add a log to my vbscript](https://stackoverflow.com/a/15908693/692942) – user692942 Feb 23 '20 at 22:03
  • @Lankymart I don't think so because my vbscript is in a wix file. I haven't found a way to have a stand-alone vbscript in the wix file that I can then call from another script. – David Thielen Feb 23 '20 at 22:24
  • Does this answer your question? [WIX installer execute vbscript from CustomAction](https://stackoverflow.com/q/51947460/692942) – user692942 Feb 25 '20 at 08:04

1 Answers1

2

Logging: Please try to read Robert Dickau's MSI Tip: Writing to the Log File from a Custom Action. In essence something like this:

option explicit
dim inst, rec
set inst = CreateObject("WindowsInstaller.Installer")
set rec=inst.CreateRecord (2)
rec.StringData(1) = "Logging call from " & property("CustomActionData")
Session.Message &H04000000, rec

WiX Sample: I just remembered that I put a sample for this on github: https://github.com/glytzhkof/WiXVBScriptWriteToLog


Tip: Here is a bunch of WiX / MSI links on all kinds of topics centering around debugging.


Links:

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
  • No wonder I couldn't find it - I kept looking for some kind of Session.Log() call. Is there a way to put all that in its own script in the wix that other scripts can call? Then I can call Log("hi there") when I need to log. ??? – David Thielen Feb 23 '20 at 16:22
  • I don't use VBScript for anything but testing when it comes to custom actions (it is great for testing though - no runtime requirements and very simple). Could you use [C#](https://stackoverflow.com/a/57573250/129130) or [preferably C++ instead](https://stackoverflow.com/a/54929785/129130) for your custom actions? Then you can call the logging in a separate function quite easily. I suppose you could use some VBScript hacks too, but the feature set is limited. [C++ custom actions are actually easier to debug once you know how to do so](https://stackoverflow.com/a/52880033/129130). – Stein Åsmul Feb 23 '20 at 17:37
  • If I was starting from scratch - yes. But there's a ton of VB in this and I just need to add some logging to it. – David Thielen Feb 23 '20 at 18:45
  • Hmm, I have honestly never tried to keep all code in a single VBScript file and call functions from within each custom action sub or function. Not sure if that would work to be honest. When I have more than basic needs I abandon VBScript. How much code are we talking about? VBScript is very hard to debug in MSI. Could you run the code on application launch instead? Or is this for addins? [Custom actions are very error prone](https://stackoverflow.com/a/46179779/129130). – Stein Åsmul Feb 23 '20 at 22:29
  • It's not even a single vbs file, it's all short scripts inline in custom actions. I may just be stuck having to do all that code each time. – David Thielen Feb 23 '20 at 22:32
  • Can you log to the system's main event log? I suppose you have code for that in VBScript and it failed from within a custom action? [Sample here](https://www.vbsedit.com/scripts2/logs/eventlog/scr_1410.asp). It showed up in my system's *`"Program"`* log. – Stein Åsmul Feb 23 '20 at 22:46
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/208377/discussion-between-stein-asmul-and-david-thielen). – Stein Åsmul Feb 23 '20 at 23:11
  • I appreciate all the help you've provided. But I'm just going to do this the hard way. It's 5 log messages so not a big deal to do it the hard way. You have convinced me though to put in a JIRA ticket to redo all this using C# when we get a chance. Thank you very much - this was all very helpful. – David Thielen Feb 23 '20 at 23:36
  • OK, great. C# is better, the best is C++ - nothing like native, down-to-the-metal, minimum dependency and easily debuggable code. C++ itself as a language is obviously a nightmare though - .NET API is way easier to use and more accessible to learn & use. – Stein Åsmul Feb 24 '20 at 00:08