Tips and notes  

 

Here are below some hints and codes snippets to enhance ScriptEZ.API usage while building applications and scripts:

1.     How to add a built-in code for running VBScript with ScriptEZ.API under Windows 64 bit

 

2.     How to run VBScript with ScriptEZ.API thanks to SendTo from Windows Explorer menu

 

3.     How to enhance VBScript with MTA (Multi-Threaded Apartment) and STA (Single-Threaded Apartment)

 

4.     How to  configure and to run ScriptEZ.API component without Registry.

 

5.     How to prevent from crash for some applications or scripts when they run under Windows 7 or plus

 

6.     How to enforce variables typing and to avoid syntax error with property’s calling ?

 

7.     How to get started easily with a local or remote interprocess lock and share mechanism ?

 

8.     How to implement easily a built-in bandwidths measuring with a couple of properties ?

 

9.     How to restart automatically apps or scripts after an abnormal crash or an unwanted exit ?

 

10.  How to use ScriptEZ.API from within VBScript pure 64-bit thanks to ‘COM+ AppBuilder’ ?

 

11. How to wait for all SQLite transactions achieve before exiting an application or script ?

 

12.  When editing a script file with Notepad, please save it as ANSI encoding format to avoid error at runtime:


 

 

13.  How to keep an eye on your computer/network load and your security status on your computer ?


 NetUsage
utility can be one response to that. Just download the setup and run it (eventually as admin user).

 The UI of this utility is a console window as following:

 

  

 

 Moreover, once the setup completed, you can call it anywhere from Windows Explorer with a contextual menu

 command "Show/Hide NetUsage Profiler"


 

 

1. Take it easy when running your VBScript under Windows 64-bit, by pre-pending the below codes snippet

    before instantiating ScriptEZ.API object. It allows your script to start by double-click from Windows Explorer.

 

  Set WshShell = CreateObject("WScript.Shell")

  Set fso          = CreateObject("Scripting.FileSystemObject")

  Set objArgs   = WScript.Arguments 

 

  Dim Windir

  Dim FullQualifiedEngineName

  '-- if Windows 64-bit, restart with WScript.exe/CScript.exe 32-bit

  On Error Resume Next

  Windir = WshShell.ExpandEnvironmentStrings("%WinDir%")

  FullQualifiedEngineName = Windir+"\SysWOW64" + _

                                          Mid(WScript.FullName,InStrRev(WScript.FullName,"\"),Len(WScript.FullName))

 

  If fso.FolderExists(Windir+"\SysWOW64") And _

     LCase(WScript.FullName) <>  LCase(FullQualifiedEngineName) And _

     LCase(WScript.FullName) = LCase(Windir+"\System32" + Mid(WScript.FullName,InStrRev(WScript.FullName,"\"),Len(WScript.FullName))) And _

     fso.FileExists(FullQualifiedEngineName) = True Then

 

    '--  enlisting all extra params…

    If objArgs.Count > 0 Then

      cmdOptions =""

      For i=0 To objArgs.Count -1

        cmdOptions = cmdOptions + Chr(34) + objArgs(i) + Chr(34) + " "

      Next

    End If

 

    '-- run with 32-bit VBScript interpreter…

    WshShell.Run FullQualifiedEngineName + " " + Chr(34) + CStr(WScript.ScriptFullName) + Chr(34) + " " + cmdOptions

    WScript.Quit

  End If

 

 '-- instantiate component object with callback interface

  Set ScriptEZMain = WScript.CreateObject("ScriptEZ.API ","ScriptEZMain_")

  '-- and so on…

 

 

2. Running ScriptByWOW64.vbs will add new menu items into Windows Explorer -> Send To command which will

    ease you to run or register your ScriptEZ.API based script (program or script component) under Windows 64-bit :

      . Script Engine (32 bits)

      . Script Component Register (32 bits)

 

    Here is below the contents of this useful provided script:

 

Main()

 

Sub Main()

 

 Dim WshShell

 Dim fso

 Dim scriptfile

 Dim strSendTo

 Dim oShellLink

 Dim Windir

 

 Set WshShell = CreateObject("WScript.Shell")

 

 scriptfile = "\WScript.exe"

 regsvr32   = "\Regsvr32.exe"

 strSendTo = WshShell.SpecialFolders("SendTo")

 

 On Error Resume Next

 Set fso = CreateObject("Scripting.FileSystemObject")

 If fso.FileExists(strSendTo & "\Script Engine (32 bits)....lnk") = False Then

    Set oShellLink = WshShell.CreateShortcut(strSendTo & "\Script Engine (32 bits)....lnk")

    Windir = WshShell.ExpandEnvironmentStrings("%WinDir%")

    If fso.FolderExists(Windir+"\SysWOW64") And fso.FileExists(Windir+"\SysWOW64\WScript.exe") Then

      oShellLink.TargetPath = Windir+"\SysWOW64\WScript.exe"

      oShellLink.WindowStyle = 1

      oShellLink.Description = "Script Engine (32 bits)"

      oShellLink.WorkingDirectory = Mid(oShellLink.TargetPath, 1, InStr(oShellLink.TargetPath, scriptfile))

      oShellLink.Save

   Else

      MsgBox "Your Windows Operating System is not a 64-bit native flavor",vbInformation,"ScriptByWOW64"

      Exit Sub

   End If

 End If

 

 If fso.FileExists(strSendTo & "Script Component Register (32 bits)....lnk") = False Then

   Set oShellLink = WshShell.CreateShortcut(strSendTo & "\Script Component Register (32 bits)....lnk")

   Windir = WshShell.ExpandEnvironmentStrings("%WinDir%")

   If fso.FolderExists(Windir+"\SysWOW64") And fso.FileExists(Windir+"\SysWOW64\Regsvr32.exe") Then

      oShellLink.TargetPath = Windir+"\SysWOW64\Regsvr32.exe"

      oShellLink.WindowStyle = 1

      oShellLink.Description = "Script Component Register (32 bits)"

      oShellLink.WorkingDirectory = Mid(oShellLink.TargetPath, 1, InStr(oShellLink.TargetPath, regsvr32))

      oShellLink.Save

   End If

 End If

 

If fso.FileExists(strSendTo & "Script Component UnRegister (32 bits)....lnk") = False Then

   Set oShellLink = WshShell.CreateShortcut(strSendTo & "\Script Component UnRegister (32 bits)....lnk")

   Windir = WshShell.ExpandEnvironmentStrings("%WinDir%")

   If fso.FolderExists(Windir+"\SysWOW64") And fso.FileExists(Windir+"\SysWOW64\Regsvr32.exe") Then

      oShellLink.TargetPath = Windir+"\SysWOW64\Regsvr32.exe"

      oShellLink.WindowStyle = 1

      oShellLink.Description = "Script Component UnRegister (32 bits)"

      oShellLink.WorkingDirectory = Mid(oShellLink.TargetPath, 1, InStr(oShellLink.TargetPath, regsvr32 + " /u"))

      oShellLink.Save

   End If

 End If

 

 Set fso = Nothing

 Set WshShell = Nothing

 

End Sub

3. Executing VBScript from within Multi-Threaded Apartment (MTA) by surrounding the ScriptEZ.API object(s)

    instantiating with these codes snippet so that its methods/properties are simultaneously and parallely invoked.

 

(!) Even if this hint can help boost a script, be careful about executing your script within this COM Apartment, since

     calls to properties/methods which use Windows Common Dialog boxes (such like File/Directory Open, File Save As),

     may result to unproperly display them.

 

     If this issue occurs while running your script, please turn back to standard Single-Threaded Apartment (STA).

 

 

  Set WshShell  = CreateObject("WScript.Shell")

  '-- force to use MTA (Multi Threaded Apartment)

  WshShell.RegWrite "HKCR\CLSID\{01947673-ADB3-48F4-A162-CF06BB23CBCD}\InprocServer32\ThreadingModel", _

                              "Free", _

                              "REG_SZ"

 

  On Error Resume Next

  '-- instantiate component object with callback interface

  Set ScriptEZMain = WScript.CreateObject(SCRIPTEZ_API,"ScriptEZMain_")

 

  '-- restore to default STA (Single Threaded Apartment)

  WshShell.RegWrite "HKCR\CLSID\{01947673-ADB3-48F4-A162-CF06BB23CBCD}\InprocServer32\ThreadingModel",_

                              "Both", _

                              "REG_SZ"

  Set WshShell = Nothing

  '-- and so on…

 

4. From Windows XP upward ( Vista, Win7, Win8…),

 

    (1) if you can not register scriptez.dll into the Registry as a COM object when delivering it side by side with

         your executable file(s) - for instance because of administrative restrictions -

    (2) or if you want to enhance and run ScriptEZ.API object into STA (serialized calls) or MTA (multi-threaded calls),

 

   … you can then use XML manifest file(s) as shown below :

 

1. This is the contents of ScriptEZ.dll.manifest file (ScriptEZ.API component):

 

*  For running into STA (Single Threaded Apartment), this is the default thread safe behaviour

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<assembly xmlns="urn:schemas-microsoft-com:asm.v1"

  manifestVersion="1.0">

 

<assemblyIdentity

    type="win32"

    name="ScriptEZ.dll"

    version="2.3.5.4" />

 

<file name="ScriptEZ.dll">

  <comClass

    progid="ScriptEZ.API"

    clsid="{01947673-ADB3-48F4-A162-CF06BB23CBCD}"

    threadingModel="Both" />

  <typelib tlbid="{4FCD2B75-F177-4EDC-A004-4273DCAFC679}"

     version="1.0" helpdir=""/>

</file>

 

<comInterfaceExternalProxyStub

    name="IAPI"

    iid="{1CF8638D-DBE5-47B3-9C84-4AB68B77FA9B}"

    proxyStubClsid32="{00020424-0000-0000-C000-000000000046}"

    baseInterface="{00000000-0000-0000-C000-000000000046}"

    tlbid = "{4FCD2B75-F177-4EDC-A004-4273DCAFC679}" />

 

</assembly>

 

*  For running into MTA (Multi Threaded Apartment), this multi-threading potentially boosts apps.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<assembly xmlns="urn:schemas-microsoft-com:asm.v1"

  manifestVersion="1.0">

 

<assemblyIdentity

    type="win32"

    name="ScriptEZ.dll"

    version="2.3.5.4" />

 

<file name="ScriptEZ.dll">

  <comClass

    progid="ScriptEZ.API"

    clsid="{01947673-ADB3-48F4-A162-CF06BB23CBCD}"

    threadingModel="Free" />

  <typelib tlbid="{4FCD2B75-F177-4EDC-A004-4273DCAFC679}"

     version="1.0" helpdir=""/>

</file>

 

<comInterfaceExternalProxyStub

    name="IAPI"

    iid="{1CF8638D-DBE5-47B3-9C84-4AB68B77FA9B}"

    proxyStubClsid32="{00020424-0000-0000-C000-000000000046}"

    baseInterface="{00000000-0000-0000-C000-000000000046}"

    tlbid = "{4FCD2B75-F177-4EDC-A004-4273DCAFC679}" />

 

</assembly>

 

 

2. This is the contents of ServerDoc.exe.manifest file (ServerDoc.exe is your application):

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<assembly xmlns="urn:schemas-microsoft-com:asm.v1"

  manifestVersion="1.0">

 

<assemblyIdentity

    type = "win32"

    name = "ServerDoc.exe"

    version = "7.2.0.0" />

 

<dependency>

    <dependentAssembly>

        <assemblyIdentity

          type="win32"

          name="ScriptEZ.dll"

          version="2.3.5.4" />

    </dependentAssembly>

</dependency>

 

</assembly>

 

 

5. Preventing from crash for apps and scripts which are running with ScriptEZ.API component under Windows 7 or plus.

 

    (1). ScriptEZ_API.host is a simple text file that allows you to keep some applications and scripts engines runnable with

     ScriptEZ.API component, when they are calling to CreateFlashWindow(…), InputCombox(…), InputListBox(…)

     under Windows 7 or plus and would be issuing crash.

 

     This text file must be and stay in the same directory as with wizapi32.dll file where each line contains the program name

    

     For instance, here is an excerpt of 2 lines from a ScriptEZ_API.host:

     ScriptEZ.API_dotNET.exe

     Php.exe

 

(2). Alternatively, passing programmatically hWndParent parameter as negative value will prevent from issuing crash as well.

 

6.  a) Be careful when your VBScript must return result  for properties which require a long or a string.

         Think of casting with CLng(…) or CStr(…) to enforce your variables type converting.

 

     b) Moreover, calling a property must use a mandatory variable assignment like this: r = Scriptez.AppAutoRestart

         otherwise, a syntax error occurs and stops your script from running.

 

 

7.   With Dynamic Data Exchange (DDE) in action, you can easily implement a local or remote interprocess lock and share

      mechanism, as shown into the both script programs ScriptEZ_LockOverDDE.vbs and ScriptEZ_LockOverTCPIP.vbs.

 

      These samples are based on the combined use of API messages, sent to:

 

      a) Remote Loader Monitor (Rldrmon.exe) which is relaying calls to Rloader.exe or to ServerDoc apps - aka DDE server

      b) ServerDoc which is relaying calls to Rloader.exe - aka TCP/IP server  

      c) Remote Loader (Rloader.exe) - aka COM/DCOM server

 

 

 

8.   Here is below a snippet of code in VBScript which is showing how to wait for all SQLite transactions being achieved before exit:

 

        Set fso = CreateObject("Scripting.FileSystemObject")  '-- Create file system object

        Set ScriptEZ = WScript.CreateObject("ScriptEZ.API")

 

        '-- create/open a SQLite file

        hSQLite = ScriptEZ.CreateSQLiteDBObject(“c:\sqlite\iproxy.sqlite”)

 

       

        

         ‘ create SQLite table and columns

         ‘ loop for parsing and inserting data from flat file into the table

        

       

 

        '-- Flushing all SQLite transactions in progress such inserting/updating rows

        ScriptEZ.SetSQLiteDBObjectCommitTimeout hSQLite,0

        '-- Block until all commits terminate into SQLite file

        Do Until ScriptEZ.SQLite_pendingTransactionCount(hSQLite) = 0

             WScript.Sleep 1000

        Loop

       

        '-- Or another way:

        '-- Flushing all SQLite transactions in progress such inserting/updating rows

        ScriptEZ.SetSQLiteDBObjectCommitTimeout hSQLite,0

        '-- Block until all commits terminate into SQLite file

        Do Until Not fso.FileExists(“c:\sqlite\iproxy.sqlite” + "-journal")

             WScript.Sleep 1000

        Loop