Brian Modra
Posts: 6
Joined: Thu Apr 13, 2023 11:05 pm

Inline vbscript Public functions and subs?

I suspect the answer will be "no", but ideally I'd like to be able to create a small library of inline vbscript public functions and subs (not installed files), which I can call from other inline vbscript custom actions.
I tried having a custom action that has an earlier sequence, having an inline public sub in it, and then tried to call that sub from another custom action inline vbscript. It did not work.

Is there some other way to achieve this (adding a small library of public functions and subs to the AIP file) ?
Catalin
Posts: 6608
Joined: Wed Jun 13, 2018 7:49 am

Re: Inline vbscript Public functions and subs?

Hello Brian,

I'm afraid that you were right and that this might not be possible.

I've run some tests on my end and can confirm this.

Additionally, upon stumbling upon an old thread on a VBS forum, it looks like you have to read the content of the first VBS in your second VBS and then call the sub/function using ExecuteGlobal.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Brian Modra
Posts: 6
Joined: Thu Apr 13, 2023 11:05 pm

Re: Inline vbscript Public functions and subs?

ExecuteGlobal was the answer - THANKS!

This is what I do, and it works:

Use an inline powershell script to write a vbs file with the public sub somewhere.
e.g.

Code: Select all

#Requires -version 2
$src = @'
Public Sub ...
...
End Sub
'@
$appdir = AI_GetMsiProperty APPDIR
$installDir = Join-Path $appdir "install"
$filePath = Join-Path $installDir "library.vbs"
Out-File -Force -InputObject $src -FilePath $filePath
Then in the inline vbscript:

Code: Select all

Set fso = CreateObject("Scripting.FileSystemObject")
baseDir = fso.BuildPath(Session.Property("APPDIR"), "install")
libraryScriptName = fso.BuildPath(baseDir, "library.vbs")

ExecuteGlobal(fso.OpenTextFile(libraryScriptName, 1, False, -1).ReadAll())
Import = True
Catalin
Posts: 6608
Joined: Wed Jun 13, 2018 7:49 am

Re: Inline vbscript Public functions and subs?

Awesome, Brian!

You are always welcome! :)

A quick note is that VBS will become deprecated:

Features removed or no longer developed starting with Windows Server 2022

Thought you might want to know this as I just remembered.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”