|   |
ActiveXperts Scripting Toolkit Table of Contents1. Introduction 2. System Requirements 3. Installation 4. How to use ActiveXperts Scripting Toolkit 5. Scripting object 6. Completion object 7. Error Codes 8. Samples 9. Troubleshooting 10. License Agreement 11. Purchase and Product Activation 1. Introduction1.1. What is ActiveXperts Scripting Toolkit?ActiveXperts Scripting Toolkit enables IT administrators and Software Developers to call VBScript functions without invoking the 'Windows Scripting Host'.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 benefits of using ActiveXperts Scripting Toolkit:
1.2. ActiveXperts Scripting Toolkit ArchitectureActiveXperts Scripting Toolkit makes use of the Microsoft VBScript Engine. It only makes use of the engine; it doesn't replace any VBScript engine components.The core of ActiveXperts Scripting Toolkit consists of one file:
ActiveXperts Scripting Toolkit can be distributed easily to multiple PC's. Once you have purchased the licenses, you copy the AxScript.dll to the PCs and register the DLL on that PC. 2. System Requirements2.1. ASP .NET, VB .NET, VC# .NET, ASP, VB, Visual C++ and moreThe ActiveXperts Scripting Toolkit component can be used by any of these development/scripting languages:
2.2. .NET FrameworkTo use ActiveXperts Scripting Toolkit in an ASP .NET, Visual Basic .NET or Visual C#. NET environment, the .NET Framework must be installed on the system. The .NET Framework is part of the Windows 2003 Operating System. On Windows 2000, Windows 98, Windows ME, Windows NT, Windows Server 2003, Windows XP, it's available as a separate installation. Please visit the Technology Information for the .NET Framework page to download the .NET Framework.2.3. Internet Information ServerInternet Information Server (IIS) Setup installs the Visual Basic Script and Java Script engines.To run ASP pages on NT4 Servers, IIS 4.x must be installed. IIS 4.x ships with the NT4 Option Pack CD's. To run ASP pages on Windows 2000 Servers, IIS 5.x must be installed. IIS is part of the Windows 2000/2003 Operating System. 2.4. Internet Explorer 4.x or higherThe Internet Explorer 4.x Setup (or higher) installs the Visual Basic Script and Java Script engines.You can use the ActiveXperts Scripting Toolkit component from within the client HTML code. 2.5. Windows Scripting HostActiveXperts Scripting Toolkit can be used in VBScript scripts. VBScripts can be used by passing the script-file as a parameter to the scripting host ( either 'cscript' or 'wscript').WSH relies on the Visual Basic Script and Java Script engines provided with Internet Explorer 4.x or later. WSH is also installed as part of Windows 98, Windows 2000, and Internet Information Services 4.0. A separate setup program is provided for Windows 95. 2.6. Visual BasicActiveXperts Scripting Toolkit can be used in Visual Basic 5.x or higher.2.7. Visual C++ActiveXperts Scripting Toolkit can be used in Visual C++ 5.x or higher.3. InstallationThe ActiveXperts Scripting Toolkit package consists of 3 components; any combination of components can be installed:
3.1. Installation on a single computerSimply run the AxScript.exe Setup program. The InstallShield wizard will guide you through the rest of the setup.If you choose the ActiveXperts Scripting Toolkit COM component, the Setup program can perform the registration of the COM component for you. But it will also give you the opportunity to register the object yourself. Any subsequent installation of ActiveXperts Scripting Toolkit can be performed either manually or by using the Setup program. 3.2. Installation on multiple computersAny subsequent installations can be performed using the setup program.But since the installation of the core components is very simple, you may want to do it manually, or integrate it into your companies software distribution program. If you choose to install the COM component manually on other machines, simply perform the following actions:
4. How to use the ActiveXperts Scripting Toolkit object4.1. IntroductionThe following code snippets illustrate how to use ActiveXperts Scripting Toolkit. Calling a VBScript function from a VC++ application
int main(int argc, char* argv[])
{
HRESULT hResult;
IXScripting *pScript = NULL;
IXCompletion *pResponse = NULL;
LONG lResult = 0L, lLastError = 0L;
BSTR bstrTemp = NULL;
VARIANT vtVar;
VariantInit ( &vtVar );
hResult = CoInitialize (NULL); // Initialize COM
if (FAILED (hResult)) goto _EndMain;
// Create an instance of the 'ActiveXperts.Scripting' class
hResult = CoCreateInstance ( CLSID_XScripting, NULL, CLSCTX_INPROC_SERVER, IID_IXScripting, (void**) &pScript);
if (FAILED (hResult)) goto _EndMain;
pScript->Clear (); // Clear the object
// Assign the actual VBScript program file that contains the function you want to call
pScript->put_ScriptFile ( _bstr_t ( "C:\\My Scripts\Script.vbs" ) );
// Assign function name
pScript->put_Function( L"GetDirectorySize");
// Assign paramater(s). Use Parameter1, Parameter2, .., Parameter8
pScript->put_Parameter1( L"\"C:\\Windows\"" );
// No run the script
pScript->Run ( &vtVar );
// If Run didn't return a valid VARIANT pointer then exit
if( vtVar.vt != VT_DISPATCH || ( pResponse = ( IXCompletion* ) vtVar.pdispVal ) == NULL )
goto _EndMain;
// Get the results ...
pResponse->get_CompletionCode ( &lResult );
printf ( "Completion Code = %ld\n", lResult );
pResponse->get_CompletionDescription ( &bstrTemp );
printf ( "Completion Description = %ls\n", bstrTemp );
SysFreeString ( bstrTemp );
if( lResult == 0 )
{
pResponse->get_FunctionReturnNumber( &lResult );
printf ( "Function Return Number = %ld\n", lResult );
pResponse->get_FunctionReturnString( &bstrTemp );
printf ( "Function Return String = %ls\n", bstrTemp );
SysFreeString ( bstrTemp );
pResponse->get_FunctionReturnInfo( &bstrTemp );
printf ( "Function Return Info = %ls\n", bstrTemp );
SysFreeString ( bstrTemp );
}
else
{
pResponse->get_CompletionErrorSource( &bstrTemp );
printf ( "CompletionErrorSource = %ls\n", bstrTemp );
SysFreeString ( bstrTemp );
pResponse->get_CompletionErrorDescription( &bstrTemp );
printf ( "CompletionErrorDescription = %ls\n", bstrTemp );
SysFreeString ( bstrTemp );
pResponse->get_CompletionErrorLine( &lResult );
printf ( "CompletionErrorLine = %ld\n", lResult );
pResponse->get_CompletionErrorChar( &lResult );
printf ( "CompletionErrorChar = %ld\n", lResult );
pResponse->get_CompletionErrorCode( &lResult );
printf ( "CompletionErrorCode = %ld\n", lResult );
}
_EndMain:
VariantClear ( &vtVar );
return 0;
}
Calling a VBScript function from a VBScript program
Set objScripting = CreateObject( "ActiveXperts.Scripting" )' Create a new Scripting instance
objScripting.ScriptFile = "C:\My Scripts\Script.vbs" ' Set script file
objScripting.Function = "GetDateAndTime" ' Set script function
Set objCompletion = objScripting.Run ' Run the script
WScript.Echo "CompletionCode : " & objCompletion.CompletionCode ' Result (numeric) of the script execution
WScript.Echo "CompletionDescr. : " & objCompletion.CompletionDescription ' Result (friendly string) of the script execution
If( objCompletion.CompletionCode = 0 ) Then
WScript.Echo "FunctionReturnNumber : " & objCompletion.FunctionReturnNumber ' Return value (Number) of the function
WScript.Echo "FunctionReturnString : " & objCompletion.FunctionReturnString ' Return value (String) of the function
WScript.Echo "FunctionReturnInfo : " & objCompletion.FunctionReturnInfo ' Return value (Variant) of the function
Else
WScript.Echo "CompletionErrorSource : " & objCompletion.CompletionErrorSource ' Shows in which script the error occured
WScript.Echo "CompletionErrorDescription : " & objCompletion.CompletionErrorDescription ' Gives a short description of the error
WScript.Echo "CompletionErrorLine : " & objCompletion.CompletionErrorLine ' Shows in which line the error occured
WScript.Echo "CompletionErrorChar : " & objCompletion.CompletionErrorChar ' Shows on which character position the error occured
WScript.Echo "CompletionErrorCode : " & objCompletion.CompletionErrorCode ' Shows the Microsoft VBScript Engine error code
End If
4.2. How to use ActiveXpert Scripting Toolkit in Visual Basic .NETFirst, make sure the ActiveXperts Scripting Toolkit component (AxScript.dll) is registered on the machine. In case you didn't use the installation program, be sure you used the REGSVR32.EXE program to register to component.Then, add a reference to the ActiveXpert Scripting Toolkit component using the Visual Basic .NET Solution Explorer:
Imports AxScriptDeclare and create an object like this: Dim objScripting As XScripting ' Declaration Dim objCompletion As XCompletion ' Declaration objScripting = New XScripting() ' Creation ... objCompletion = objScripting.Run() ' Run returns an XCompletion objectThe product installation contains working VB .NET samples. They can also be found online: ftp.activexperts-labs.com/samples/axscript. 4.3. How to use ActiveXperts Scripting Toolkit in Visual C# .NETFirst, make sure the ActiveXperts Scripting Toolkit component (AxScript.dll) is registered on the machine. In case you didn't use the installation program, be sure you used the REGSVR32.EXE program to register to component.Then, add a reference to the object using the Visual C# Solution Explorer:
using AxScript;and declare and create an object like this: XScripting objScripting = new XScripting(); // Declaration XCompletion objCompletion; // Declaration ... objScripting = new Scripting(); // Creation ... objCompletion = objScripting.Run(); // Run returns an XCompletion objectAfter the declaration and creation of the object, you can use the object in your Visual C# .NET code. Visual C# .NET samples are part of the product installation. They can also be found online: ftp.activexperts-labs.com/samples/axscript. 4.4. How to use ActiveXperts Scripting Toolkit in Visual BasicActiveXperts Scripting Toolkit can be used in Visual Basic 5.x or higher. In Visual Basic, go to the 'Project/References...' menu item and check the box next to ActiveXpert Scripting Toolkit Type Library. Now, you can declare and create ActiveXpert Scripting Toolkit objects.Create a new ActiveXpert Scripting Toolkit object using the 'CreateObject' function: Dim objScripting As AxScript.XScripting ' Declaration Dim objCompletion As AxScript.XCompletion ' Declaration ... Set objScripting = CreateObject( "ActiveXperts.Scripting") ' Creation ... objCompletion = objScripting.Run() ' Run returns an XCompletion objectAfter the declaration and creation of the object, you can use the object in your Visual Basic code. Visual Basic samples are part of the product installation. They can also be found online: ftp.activexperts-labs.com/samples/axscript. 4.5. How to use ActiveXperts Scripting Toolkit in Visual C++ActiveXperts Scripting Toolkit can be used in Visual C++ projects. Include the *.h and *.c file provided by ActiveXperts to bind your code to the ActiveXperts Scripting Toolkit component. These files are located in the Include directory of the Visual C++ samples directory. These are the files:
IXScripting *pScript; // Declaration IXCompletion *pCompletion // Declaration ... CoCreateInstance ( CLSID_XScripting , NULL, CLSCTX_INPROC_SERVER, IID_IXScripting, (void**) &pScript); // Creation ... pScript->Run ( &vtVar ); ' Run copies an IXCompletion object pCompletion = ( IXCompletion* ) vtVar.pdispVal; ...After the declaration and creation of the object, you can use the object in your Visual C++ code. Visual C++ samples are part of the product installation. They can also be found online: ftp.activexperts-labs.com/samples/axscript. 4.6. How to use ActiveXpert Scripting Toolkit in an ASP 2.x environment
<html>
<body>
Version:
<script language=vbscript runat=server>
Set objScripting = CreateObject( "ActiveXperts.Scripting" )
Response.Write objScripting.Version
</script>
</body>
</html>
ASP samples are part of the product installation.They can also be found online: ftp.activexperts-labs.com/samples/axscript. 5. Scripting Object
5.1. Scripting object - Properties and Functions Overview
5.2. ActiveXpert Scripting Toolkit object - PropertiesVersion property Description:Version information of ActiveXpert Scripting Toolkit. This property is read-only; you cannot assign a value to it.Example:
Set objScripting = CreateObject("ActiveXperts.Scripting") ' Create a new Scripting instance
WScript.Echo "Version: " & objScripting.Version
ExpirationDate property Description:Expiration date of ActiveXpert Scripting Toolkit. This property is read-only; you cannot assign a value to it.
|
|
Set objScripting = CreateObject("ActiveXperts.Scripting") ' Create a new Scripting instance
...
objScripting.ScriptFile = "c:\my scripts\myscript.vbs" ' myscript.vbs is the script that holds function 'Func1'
objScripting.Function = "Func1" ' Call 'Func1' when Run is invoked
...
Set objCompletion = objScripting.Run() ' Run the function
If( objCompletion.CompletionCode = 0 )
WScript.Echo "Sucess!"
Else
WScript.Echo "CompletionCode : " & objCompletion.CompletionCode ' Completion information of the function call
WScript.Echo "CompletionDescription : " & objCompletion.CompletionDescription ' Completion information of the function call
End If
...
Set objScripting = CreateObject("ActiveXperts.Scripting") ' Create a new Scripting instance
...
objScripting.ScriptFile = "c:\my scripts\myscript.vbs" ' myscript.vbs is the script that holds function 'Func1'
objScripting.Function = "Func1" ' Call 'Func1' when Run is invoked
...
Set objCompletion = objScripting.Run() ' Run the function
If( objCompletion.CompletionCode = 0 )
WScript.Echo "Return String : " & objCompletion.FunctionReturnString ' Return value of the function call (only if type is numeric)
WScript.Echo "Return Number : " & objCompletion.FunctionReturnNumber ' Return value of the function call (only if type is a string)
WScript.Echo "Return Info : " & objCompletion.FunctionReturnInfo ' Return value of the function call (only if type is a Variant)
Else
WScript.Echo "CompletionCode : " & objCompletion.CompletionCode
WScript.Echo "CompletionDescription : " & objCompletion.CompletionDescription
End If
...
Set objScripting = CreateObject( "ActiveXperts.Scripting" )' Create a new Scripting instance
objScripting.ScriptFile = "C:\My Scripts\Script.vbs" ' Set script file
objScripting.Function = "GetDateAndTime" ' Set script function
Set objCompletion = objScripting.Run ' Run the script
WScript.Echo "CompletionCode : " & objCompletion.CompletionCode ' Result (numeric) of the script execution
WScript.Echo "CompletionDescr. : " & objCompletion.CompletionDescription ' Result (friendly string) of the script execution
If( objCompletion.CompletionCode = 0 ) Then
WScript.Echo "FunctionReturnNumber : " & objCompletion.FunctionReturnNumber ' Return value (Number) of the function
WScript.Echo "FunctionReturnString : " & objCompletion.FunctionReturnString ' Return value (String) of the function
WScript.Echo "FunctionReturnInfo : " & objCompletion.FunctionReturnInfo ' Return value (Variant) of the function
Else
WScript.Echo "CompletionErrorSource : " & objCompletion.CompletionErrorSource ' Only set if CompletionCode <> 0; shows in which script the error occured
WScript.Echo "CompletionErrorDescription : " & objCompletion.CompletionErrorDescription ' Only set if CompletionCode <> 0; gives a short description of the error
WScript.Echo "CompletionErrorLine : " & objCompletion.CompletionErrorLine ' Only set if CompletionCode <> 0; shows in which line the error occured
WScript.Echo "CompletionErrorChar : " & objCompletion.CompletionErrorChar ' Only set if CompletionCode <> 0; shows on which character position the error occured
WScript.Echo "CompletionErrorCode : " & objCompletion.CompletionErrorCode ' Only set if CompletionCode <> 0; shows the Microsoft VBScript Engine error code
End If
| Website: | http://www.activexperts.com/support | |
| Email: | support@activexperts.com | |
Set objScripting = CreateObject("ActiveXperts.Scripting") ' Create a new Scripting instance
objScripting.Activate XXXXX-XXXXX-XXXXX" ' Replace XXXXX-XXXXX-XXXXX by your own registration code