jlavery
Posts: 27
Joined: Tue Oct 14, 2008 4:56 pm

Debug a vbs script

Hi all,
Does anyone know how I can debug a vbs script which is called from Advanced Installer? I can run it from Visual Studio and/or by supplying the //X command line argument to cscript.exe, but I need to be able to set up the Session.Installer and Session.Property etc.

Any pointers would be appreciated.

James
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Debug a vbs script

Hi James,

Unfortunately there aren't any good methods of debugging VBScript code. For your custom action you can try writing debug information into a log when you encounter problems. The User Guide contains the Write text into a file how-to which may help you.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
jlavery
Posts: 27
Joined: Tue Oct 14, 2008 4:56 pm

Re: Debug a vbs script

Hi Cosmin,
Thanks - so there's no way of, for example, passing the //X parameter to cscript.exe when the installation is run?

James
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Debug a vbs script

Hi James,

I'm not sure if it will work, but you can try (we didn't test this). Perhaps this article will also help.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
jlavery
Posts: 27
Joined: Tue Oct 14, 2008 4:56 pm

Re: Debug a vbs script

Hi Cosmin,
Yes I've seen that article, and tried it. The problem is setting up the environment so that the Installer properties are available to the script. Any thoughts?

Thanks,

James
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Debug a vbs script

Hi James,

To access the value of a property the value needs to be set into a variable. For example:

Code: Select all

value = Session.Property("PROPERTY_NAME")
I'm afraid that the installer properties cannot be accessed in another way from the debugging environment.

To run the code in debug mode you can try using an "EXE with working Dir" custom action which runs "wscript.exe" with the custom command line.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
jlavery
Posts: 27
Joined: Tue Oct 14, 2008 4:56 pm

Re: Debug a vbs script

Hi Cosmin,
Thanks - yes that works. However, because wscript.exe is being run as a separate process, the installer properties aren't available. I think I'm going to have to resort to writing debug info to a text file as you suggested earlier.

Regards,

James
jlavery
Posts: 27
Joined: Tue Oct 14, 2008 4:56 pm

Re: Debug a vbs script

Hi Cosmin,
I've found the solution, although it needs a registry hack. :D

Before running the installer, set the following registry value to 1, to force Just In Time (JIT) debugging for Windows scripting:

HKEY_CURRENT_USER\Software\Microsoft\Windows Script\Settings\JITDebug

Then, when the installer is run, the standard 'which environment do you want to use for debugging' window pops up. Pick the appropriate environment (I chose Visual Studio 2003), and the script can then be debugged - and it has the Session and Session.Installer etc. set correctly.

I'd recommend setting the registry value back as soon as you've finished debugging, though, as otherwise you get the debug prompt whenever any jscript/javascript code is run from a web page!

James

Return to “Common Problems”