C # execute JS scripts using the msscript. ocx control

Source: Internet
Author: User
Tags microsoft website

Download Windows Script Control from Microsoft website. It is an ActiveX (R) Control, so I used Interop in. NET. After the download and installation are complete, create a C # Windows application project, select the reference node in solution Resource Manager, right-click and choose add reference from the shortcut menu, and the Add reference dialog box is displayed, click Browse to find the directory for installing Windows Script Control and select msscript. ocx file. A MSScriptControl component is added to the reference node. The following are all objects after Interop. ScriptControl provides simple interfaces for the host Script engine that supports ActiveX (TM) scripts. Next we will convertScriptControlDescribes the attributes and methods.

 

Attribute

 

Attribute DescriptionThe AllowUI is applied to the user interface elements displayed by the ScriptControl itself or the Scirpt engine, and can be read and written. The return object of CodeObject. This object is used to call the public members of a specified module. Read-only. Error returns the Error object, which contains detailed information about the last Error. Read-only. Set or return the name of the Script Language in use. Read/write. Modules is a collection of return Modules of the ScriptControl object. Read-only. Procedures returns the process set defined in the specified module. Read-only. SitehWnd is set or the hWnd in the return window. It is used to display the dialog box and other user interface elements by executing Script code. Read/write. Set the State or return the mode of the ScriptControl object. You can read and write Timeout settings or return time (MS). After this time, you can choose to stop the execution of the Script code or allow the code to continue execution. Read/write. UseSafeSubset sets or returns a Boolean value to indicate whether the host application has confidentiality requirements. If the host application requires security control, UseSafeSubset is True; otherwise, it is False. Read/write.
Method
Method DescriptionAddCode adds the specified code to the module. The AddCode method AddObject can be called multiple times to enable the host object model to use Eval expressions for the Script engine and return the result ExecuteStatement. Execute the specified statement Reset to discard all the Script code and object Run commands that have been added to ScriptControl. process
Event
Event DescriptionWhen an Error occurs during running, the Timeout event occurs. When the time specified by the Timeout attribute is exceeded and the End is selected in the result dialog box, this event occurs.
Note:
If the AllowUI attribute is set to False, statements such as the displayed dialog box do not work, for example, in VBScript MsgBoxStatement in JavaScript AlertIf the number of milliseconds in which the script is executed exceeds the TimeOut value, the dialog box indicating the time exceeds the time limit is not displayed. Otherwise, the Code loaded by AddCode is cleared when the Language attribute is reset; when the TimeOut attribute times out, ScriptControl checks the AllowUI attribute of the object to determine whether to allow display of user interface elements.

 

To make the control easier to use, use the ScriptEngine class to encapsulate the following complete code:
Code
 Using System;
Using MSScriptControl;
Using System. Text;
Namespace LCS. Web
{

/// <Summary>
/// Script Type
/// </Summary>
Public enum ScriptLanguage
{

/// <Summary>
/// JScript Language
/// </Summary>
JScript,
/// <Summary>
/// VBscript script language
/// </Summary>
VBscript,
/// <Summary>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.