You are here:

ActiveXperts.com > ActiveXperts Scripting Toolkit

ActiveXperts Scripting Toolkit Invoke VBScript functions and remote Windows commands from any application

Integrate VBScript and Windows commands in any application

ActiveXperts Scripting Toolkit enables Software Developers to run VBScript program or a command-line tool without invoking the Windows Scripting Host or console window. With ActiveXperts Scripting Toolkit, VBScript programs and command-line tools can be invoked from any application or script.

How to use Scripting toolkit Visual Stuio.NET Web Application GUI Application Console Application
Startup screen after installation Use Scripting Toolkit with MS Visual Studio Scripting Toolkit in a .NET web application Scripting Toolkit in a .NET forms program Scripting Toolkit in a console application

Usually, you call VBScript programs by invoking the 'Windows Script Host' (either WSCRIPT.EXE or CSCRIPT.EXE). The ActiveXperts Scripting Toolkit directly communicates with the VBScript Engine of the operating system. Some of the benefits of using ActiveXperts Scripting Toolkit instead of using the Windows Scripting Host:

Some benefits of using ActiveXperts Scripting Toolkit instead of the Windows Scripting Host:

  • Function results can be used directly in any application
  • Standard Output and Standard Error are stored in variables, without the need to redirect
  • Call functions directly instead of writing 'stub' code
  • Pass function parameters dynamically - pass the function parameters 'on the fly', directly from your own application or script
  • Set a timeout to prevent functions from not returning, for instanceas a result of an endless loop
  • Intercept program errors that would normally crash the Windows Scripting Host
  • Customize your error messages
  • Support for Windows Services and Web Applications - call a VBScript function directly from a Windows Service or a Web Application

Some benefits of using ActiveXperts Scripting Toolkit instead of executing a command-line tools from a console window:

  • Standard Output and Standard Error are stored in variables, without the need to redirect
  • Set a timeout to prevent a command-line tool from not returning, for instance as a result of an endless loop
  • Support for Windows Services and Web Applications - call a command-line tool directly from a Windows Service or a Web Application

ActiveXperts Scripting Toolkit can be distributed easily to any Windows computer. Once you have purchased the license, you copy the AxScript.dll (or AxScriptx64.dll) to the workstations or servers and register the DLL on those machines.

The ActiveXperts Scripting Toolkit component can be used by any of these development/scripting languages:

  • Microsoft Visual Studio .NET: Visual Basic .NET, Visual C# .NET, ASP .NET
  • Microsoft Visual Studio: Visual Basic 5.x or higher, Visual C++ 5.x or higher
  • Borland Delphi 7.x or higher, Borland C++ Builder 6.x or higher
  • ASP 2.x, HTML, Javascript
  • PHP
  • VBScript
  • Any other development platform that supports ActiveX/COM components

System Requirements

ActiveXperts Scripting Toolkit is available as a 32-bit component and as a 64-bit component (both part of the product):

  • AxScript.dll - 32-bit component;
  • AxScriptx64.dll - 64-bit component.

ActiveXperts Scripting Toolkit runs on the following Operating Systems:

  • Windows 2008 (32 and 64 bit);
  • Windows 2003 (32 and 64 bit);
  • Windows 2000 Server and Professional (32 bit only);
  • Windows 7 (32 and 64 bit);
  • Windows Vista (32 and 64 bit);
  • Windows XP (32 and 64 bit).

Code Snippets and Sample Applications

The following code snippets illustrate how to use the Scripting object.

Visual C# .NET sample showing how to run a VBScript program

using System;
using System.Collections.Generic;
using System.Text;
using AxScript;

namespace Scripting
{
  class Program
  {
    static void Main(string[] args)
    {
      VBScript objScripting = new VBScript ();

      Microsoft.Win32.RegistryKey regKey;

      // Display Version Info
      Console.WriteLine("Scripting Toolkit Version: " + objScripting.Version);
      Console.WriteLine("Scripting Toolkit Build  : " + objScripting.Build);
      Console.WriteLine("Scripting Toolkit Module : " + objScripting.Module);
      Console.WriteLine("Expiration date          : " + objScripting.ExpirationDate + "\r\n");

      // Set Scriptfile
      objScripting.ScriptFile = "Date.vbs";
      regKey.Close();
                 
      // Specify Function
      objScripting.Function = "GetDateString";

      // Set Parameters
      objScripting.Parameter1 = "\"New Datum: \"";
      objScripting.Parameter2 = "10";
      
      // Run Script
      VBScriptResult objResult = objScripting.Run() as VBScriptResult;

      // Display Result
      Console.WriteLine("{0}", objScripting.ScriptFile);

      Console.WriteLine("Completion Code              : {0}", objResult.RunResultCode);
      Console.WriteLine("Completion Description       : {0}", objResult.RunResultDescription);

      if (objResult.RunResultCode == 0)
      {
          Console.WriteLine("Return String   : {0}", objResult.FunctionReturnString);
          Console.WriteLine("Return Number   : {0}", objResult.FunctionReturnNumber);
      }
      else
      {
          Console.WriteLine("Error Source    : {0}", objResult.ErrorSource);
          Console.WriteLine("Error Description : {0}", objResult.ErrorDescription);
          Console.WriteLine("Error Line      : {0}", objResult.ErrorLineNum);
          Console.WriteLine("Error Char      : {0}", objResult.ErrorCharPos);
          Console.WriteLine("Error Code      : {0,8:X}", objResult.ErrorCode);
      }
    }
  }
}
VB .NET sample shoeing how to execute a remote command

using System;
using System.Collections.Generic;
using System.Text;
using AxScript;

namespace RemoteCommandDemo
{
  class Program
  {
    static void Main(string[] args)
    {
      RemoteCommand objRemoteCmd = new RemoteCommand();

      Console.WriteLine("Scripting Toolkit Version: " + objRemoteCmd.Version);
      Console.WriteLine("Scripting Toolkit Build  : " + objRemoteCmd.Build);
      Console.WriteLine("Scripting Toolkit Module : " + objRemoteCmd.Module);
      Console.WriteLine("Expiration date          : " + objRemoteCmd.ExpirationDate + "\r\n");

      // Clear all paramaters
      objRemoteCmd.Clear();

      // Set hostname of remote computer
      objRemoteCmd.Host = Ask("Hostname of remote computer", false);

      // Set user account
      objRemoteCmd.UserName = Ask("User account on remote computer", true);

      // Set user password
      objRemoteCmd.Password = Ask("Password on remote computer", true);

      // Set remote command
      objRemoteCmd.Command  = Ask("Enter command to execute on remote computer", false);

      // Set command timeout
      objRemoteCmd.CommandTimeout = 5000;

      // Set Logfile
      objRemoteCmd.Logfile = System.Environment.CurrentDirectory + "LogFile.Txt";

      // Run the command
      objRemoteCmd.Run();

      Console.WriteLine("StdOut received: {0}", objRemoteCmd.StdOut);
      Console.WriteLine("StdErr received: {0}", objRemoteCmd.StdErr);
      Console.WriteLine("Executed command, result: {0})", objRemoteCmd.LastError);
      Console.WriteLine("Ready.");

      Console.ReadKey();
    }

    static private string Ask(string strTitle, bool bAllowEmpty)
    {
      String strInput, strReturn = "";

      Console.WriteLine(strTitle);
      do
      {
        Console.Write("  > ");
        strInput = Console.ReadLine();
        if (strInput.Length > 1)
           strReturn = strInput;
      } 
      while (strReturn == "" && !bAllowEmpty);

      return strReturn;
    }
  }
}

Click here for more samples.


More information

To read more about ActiveXperts Scripting Toolkit, use one of the following links: