<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://nsis.sourceforge.io/mediawiki/index.php?action=history&amp;feed=atom&amp;title=VBScript_Include</id>
	<title>VBScript Include - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://nsis.sourceforge.io/mediawiki/index.php?action=history&amp;feed=atom&amp;title=VBScript_Include"/>
	<link rel="alternate" type="text/html" href="https://nsis.sourceforge.io/mediawiki/index.php?title=VBScript_Include&amp;action=history"/>
	<updated>2026-05-12T20:51:53Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.17</generator>
	<entry>
		<id>https://nsis.sourceforge.io/mediawiki/index.php?title=VBScript_Include&amp;diff=18624&amp;oldid=prev</id>
		<title>Zinthose: Initial Release</title>
		<link rel="alternate" type="text/html" href="https://nsis.sourceforge.io/mediawiki/index.php?title=VBScript_Include&amp;diff=18624&amp;oldid=prev"/>
		<updated>2010-06-16T19:09:26Z</updated>

		<summary type="html">&lt;p&gt;Initial Release&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{PageAuthor|Zinthose}}&lt;br /&gt;
== About ==&lt;br /&gt;
This is mostly a proof of concept that demonstrates a way to use VBScripts within your NSIS packages.  I primarily developed this as a way to keep all your code that is relevant to the current project inline.  When compiled, the VBScripts are dynamically created and executed.  Take a look at the example and use your imagination.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;highlight-nsis&amp;gt;## Execute a script at compile time and !include the output &lt;br /&gt;
    ${VBS} NEW&lt;br /&gt;
    ${VBS} `PackageName = Left(CreateObject(&amp;quot;Scriptlet.TypeLib&amp;quot;).Guid, 38)`                     ## Create a new Guid&lt;br /&gt;
    ${VBS} `PackageName = InputBox(&amp;quot;What is the Package Name?&amp;quot;, &amp;quot;NSIS VBScript&amp;quot;, PackageName)`  ## Prompt programmer for Package Name with a new guid as the default&lt;br /&gt;
    ${VBS} `WScript.Echo &amp;quot;!define PACKAGENAME &amp;#039;&amp;quot; &amp;amp; PackageName &amp;amp; &amp;quot;&amp;#039;&amp;quot;`                           ## Echo message to file to included&lt;br /&gt;
    ${VBS} !Include&lt;br /&gt;
&lt;br /&gt;
## Execute a script at compile time&lt;br /&gt;
    ${VBS} NEW&lt;br /&gt;
    ${VBS} `WScript.echo &amp;quot;Hello Programmer!&amp;quot;`   ## Greet the programmer!&lt;br /&gt;
    ${VBS} !Execute&lt;br /&gt;
&lt;br /&gt;
## Execute a vbscript at runtime&lt;br /&gt;
    ${VBS} NEW&lt;br /&gt;
    ${VBS} `UsersName = InputBox(&amp;quot;What is your Name?&amp;quot;, &amp;quot;${PACKAGENAME}&amp;quot;)`                   ## Display an input box to the user to ask for name&lt;br /&gt;
    ${VBS} `WScript.Echo &amp;quot;User claims his/her name is &amp;quot; &amp;amp; UsersName`                        ## This will echo to the detail view&lt;br /&gt;
    ${VBS} `MsgBox &amp;quot;Hello &amp;quot; &amp;amp; UsersName, 0, &amp;quot;Hello User&amp;quot;`                                   ## Greet the user!&lt;br /&gt;
    ${VBS} `If MsgBox(&amp;quot;Do you want to win the lottery?&amp;quot;, 4, &amp;quot;${PACKAGENAME}&amp;quot;) = 6 Then`     ## Ask the user a question&lt;br /&gt;
    ${VBS} `    WScript.Echo &amp;quot;User wants to win the lottery&amp;quot;`                               &lt;br /&gt;
    ${VBS} `Else`&lt;br /&gt;
    ${VBS} `    WScript.Echo &amp;quot;User is a liar!&amp;quot;`&lt;br /&gt;
    ${VBS} `End If`&lt;br /&gt;
    ${VBS} Execute&lt;br /&gt;
&lt;br /&gt;
    ## Get the results from the script&amp;#039;s execution (Uses nsExec::Exec syntax)&lt;br /&gt;
    Pop $0&lt;br /&gt;
    DetailPrint `RC:$0`&amp;lt;/highlight-nsis&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== vbscript.nsi ==&lt;br /&gt;
&amp;lt;highlight-nsis&amp;gt;!ifndef __VBSCRIPT__&lt;br /&gt;
!define __VBSCRIPT__ 1&lt;br /&gt;
&lt;br /&gt;
/*  vbscript.nsi&lt;br /&gt;
    ----------------------------------------------------------------&lt;br /&gt;
    Simplifies execution of VBScripts from nsis.  &lt;br /&gt;
    This is targeted to be primarily used as part of the precompiler &lt;br /&gt;
    but has limited support for runtim use although not recommended.&lt;br /&gt;
    ----------------------------------------------------------------*/&lt;br /&gt;
&lt;br /&gt;
!macro _VBS_New&lt;br /&gt;
    !ifdef _VBScriptFile&lt;br /&gt;
        !delfile &amp;quot;${_VBScriptFile}&amp;quot;&lt;br /&gt;
        !undef _VBScriptFile&lt;br /&gt;
    !endif&lt;br /&gt;
    !tempfile _VBScriptFile&lt;br /&gt;
    !verbose 4&lt;br /&gt;
    !echo `VBS NEW = ${_VBScriptFile}`&lt;br /&gt;
    !verbose 3&lt;br /&gt;
!macroend&lt;br /&gt;
&lt;br /&gt;
!macro _VBS_Append _ScriptLine&lt;br /&gt;
    !ifndef _VBScriptFile&lt;br /&gt;
        !insertmacro _VBS_New&lt;br /&gt;
    !endif&lt;br /&gt;
    !verbose 4&lt;br /&gt;
    !echo `VBS &amp;lt;-- ${_ScriptLine}`&lt;br /&gt;
    !verbose 3&lt;br /&gt;
    !appendfile &amp;quot;${_VBScriptFile}&amp;quot; `${_ScriptLine}$\n`&lt;br /&gt;
!macroend&lt;br /&gt;
&lt;br /&gt;
!macro _VBS_Include&lt;br /&gt;
    !ifdef _OutFile&lt;br /&gt;
        !undef _OutFile&lt;br /&gt;
    !endif&lt;br /&gt;
    !ifndef _VBScriptFile&lt;br /&gt;
        !error &amp;quot;No script defined!&amp;quot;&lt;br /&gt;
    !endif&lt;br /&gt;
    !tempfile _OutFile&lt;br /&gt;
    !system `&amp;quot;%windir%\System32\CScript.exe&amp;quot; &amp;quot;${_VBScriptFile}&amp;quot; //E:VBS //NOLOGO &amp;gt; &amp;quot;${_OutFile}&amp;quot;`&lt;br /&gt;
    !include &amp;quot;${_OutFile}&amp;quot;&lt;br /&gt;
    !delfile &amp;quot;${_OutFile}&amp;quot;&lt;br /&gt;
    !verbose 4&lt;br /&gt;
    !echo `VBS INC ${_VBScriptFile}`&lt;br /&gt;
    !verbose 3&lt;br /&gt;
!macroend&lt;br /&gt;
&lt;br /&gt;
!macro _VBS_Execute&lt;br /&gt;
    !ifndef _VBScriptFile&lt;br /&gt;
        !error &amp;quot;No script defined!&amp;quot;&lt;br /&gt;
    !endif&lt;br /&gt;
    !system `&amp;quot;%windir%\System32\wScript.exe&amp;quot; &amp;quot;${_VBScriptFile}&amp;quot; //E:VBS //NOLOGO`&lt;br /&gt;
!macroend&lt;br /&gt;
&lt;br /&gt;
!macro _VBS _Operator&lt;br /&gt;
    !verbose push&lt;br /&gt;
    !verbose 3&lt;br /&gt;
    !if `${_Operator}` == `NEW`&lt;br /&gt;
        !insertmacro _VBS_New&lt;br /&gt;
    !else if `${_Operator}` == `!INCLUDE`&lt;br /&gt;
        !insertmacro _VBS_Include&lt;br /&gt;
    !else if `${_Operator}` == `!EXECUTE`&lt;br /&gt;
        !insertmacro _VBS_Execute&lt;br /&gt;
    !else if `${_Operator}` == `EXECUTE`&lt;br /&gt;
        !ifndef _VBScriptFile&lt;br /&gt;
            !error &amp;quot;No script defined!&amp;quot;&lt;br /&gt;
        !endif&lt;br /&gt;
        !ifndef __VBS__EXECUTE_FIRSTRUN__&lt;br /&gt;
            !define __VBS__EXECUTE_FIRSTRUN__&lt;br /&gt;
            !warning &amp;quot;It is not recomended to execute scripts at runtime as antivirus software will likley block script execution.&amp;quot;&lt;br /&gt;
            InitPluginsDir&lt;br /&gt;
        !endif&lt;br /&gt;
        File /oname=$PLUGINSDIR\vbstmp.vbs `${_VBScriptFile}`&lt;br /&gt;
        nsExec::ExecToLog `cScript.exe &amp;quot;$PLUGINSDIR\vbstmp.vbs&amp;quot; //E:VBS //NOLOGO`&lt;br /&gt;
    !else&lt;br /&gt;
        !insertmacro _VBS_Append `${_Operator}`&lt;br /&gt;
    !endif&lt;br /&gt;
    !verbose pop&lt;br /&gt;
!macroend&lt;br /&gt;
!define VBS &amp;quot;!insertmacro _VBS&amp;quot;&lt;br /&gt;
&lt;br /&gt;
!endif&amp;lt;/highlight-nsis&amp;gt;&lt;br /&gt;
[[Category:Compile-Time Macros]]&lt;/div&gt;</summary>
		<author><name>Zinthose</name></author>
	</entry>
</feed>