Shortcut Menu

Skip

Main Navigation

Choose your language

You are here:

ActiveXperts.com > Scripting Component

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

Quicklinks


Integrate VBScript and Windows commands in any application

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

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

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

Some benefits of using ActiveXperts Scripting Component 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 Component 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 Component can be distributed easily to any Windows computer. Once you have purchased the license, you copy the AxScript32.dll (or AxScript64.dll) to the workstations or servers and register the DLL on those machines.

The ActiveXperts Scripting 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, Visual C++
  • Delphi, C++ Builder
  • ASP 2.x, HTML, Javascript
  • PHP
  • VBScript
  • Any other development platform that supports ActiveX/COM components


System Requirements

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

  • AxScript32.dll - 32-bit component;
  • AxScript64.dll - 64-bit component.

ActiveXperts Scripting Component runs on the following Operating Systems:

  • Windows 2012 (64 bit);
  • Windows 2008 (32 and 64 bit);
  • Windows 2003 (32 and 64 bit);
  • Windows 8 (32 and 64 bit);
  • 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.Run;

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

      Microsoft.Win32.RegistryKey regKey;

      // Display Version Info
      Console.WriteLine("Scripting Component Version: " + objScripting.Version);
      Console.WriteLine("Scripting Component Build  : " + objScripting.Build);
      Console.WriteLine("Scripting Component 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 showing how to execute a remote command

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

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

      Console.WriteLine("Scripting Component Version: " + objRemoteCmd.Version);
      Console.WriteLine("Scripting Component Build  : " + objRemoteCmd.Build);
      Console.WriteLine("Scripting Component 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 Component, use one of the following links: