• 大小: 53KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-10
  • 语言: C#
  • 标签: c#  

资源简介

C#利用ScriptControl动态执行JS和VBS脚本,默认JavaScript脚本语言

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MSscriptControl;

namespace WindowsFormsApplication1
{
    /// 

    /// 脚本类型

    /// 


    public enum scriptLanguage
    {

        /// 

        /// Jscript脚本语言

        /// 


        Jscript

        /// 

        /// vbscript脚本语言

        /// 


        vbscript

        /// 

        /// javascript脚本语言

        /// 


        javascript

    }

    /// 

    /// 脚本运行错误代理

    /// 


    public delegate void RunErrorHandler();

    /// 

    /// 脚本运行超时代理

    /// 


    public delegate void RunTimeoutHandler();

    /// 

    /// scriptEngine类

    /// 


    public class scriptEngine
    {

        private scriptControl msc;

        //定义脚本运行错误事件

        public event RunErrorHandler RunError;

        //定义脚本运行超时事件

        public event RunTimeoutHandler RunTimeout;

        /// 

        ///构造函数

        /// 


        public scriptEngine()
            : this(scriptLanguage.vbscript)
        {

        }

        /// 

        /// 构造函数

        /// 


        /// 脚本类型

        public scriptEngine(scriptLanguage language)
        {

            this.msc = new scriptControl();

            this.msc.UseSafeSubset = true;

            this.msc.Language = language.ToString();

            ((DscriptControlSource_Event)this.msc).Error += new DscriptControlSource_ErrorEventHandler(scriptEngine_Error);

            ((DscriptControlSource_Event)this.msc).Timeout += new DscriptControlSource_TimeoutEventHandler(scriptEngine_Timeout);

        }

        /// 

        /// 运行Eval方法

        /// 


        /// pression“>表达式

        /// 函数体

        /// 返回值object

        public object Eval(string expression string codeBody)
        {

            msc.AddCode(codeBody);

            return msc.Eval(expression);

        }

        /// 

        /// 运行Eval方法

        /// 


        /// 脚本语言

        /// pression“>表达式

        /// 函数体

        /// 返回值object

        public object Eval(scriptLanguage language string expression string codeBody)
        {

            if (this.Language != language)

                this.Language = language;

            return Eval(expression codeBody);

        }

        /// 

        /// 运行Run方法

        /// 


        /// 入口函数名称

        /// 参数

        /// 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      17408  2013-08-07 15:24  scriptControl-Example\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe

     文件      36352  2013-08-07 15:24  scriptControl-Example\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.pdb

     文件      11600  2013-08-07 15:26  scriptControl-Example\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe

     文件        490  2010-03-17 22:39  scriptControl-Example\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe.manifest

     文件       5921  2013-08-07 15:53  scriptControl-Example\WindowsFormsApplication1\Class1.cs

     文件       2382  2013-08-07 15:23  scriptControl-Example\WindowsFormsApplication1\Form1.cs

     文件      10645  2013-08-07 15:21  scriptControl-Example\WindowsFormsApplication1\Form1.Designer.cs

     文件       5817  2013-08-07 15:21  scriptControl-Example\WindowsFormsApplication1\Form1.resx

     文件       2855  2013-08-07 14:12  scriptControl-Example\WindowsFormsApplication1\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6420  2013-08-07 15:38  scriptControl-Example\WindowsFormsApplication1\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        862  2013-08-07 15:26  scriptControl-Example\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.csproj.FileListAbsolute.txt

     文件        975  2013-08-07 15:21  scriptControl-Example\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.csproj.GenerateResource.Cache

     文件      17408  2013-08-07 15:24  scriptControl-Example\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.exe

     文件        180  2013-08-07 15:21  scriptControl-Example\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.Form1.resources

     文件      36352  2013-08-07 15:24  scriptControl-Example\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.pdb

     文件        180  2013-08-07 14:41  scriptControl-Example\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.Properties.Resources.resources

     文件        505  2013-08-07 14:12  scriptControl-Example\WindowsFormsApplication1\Program.cs

     文件       1380  2013-08-07 14:12  scriptControl-Example\WindowsFormsApplication1\Properties\AssemblyInfo.cs

     文件       2900  2013-08-07 14:12  scriptControl-Example\WindowsFormsApplication1\Properties\Resources.Designer.cs

     文件       5612  2013-08-07 14:12  scriptControl-Example\WindowsFormsApplication1\Properties\Resources.resx

     文件       1111  2013-08-07 14:12  scriptControl-Example\WindowsFormsApplication1\Properties\Settings.Designer.cs

     文件        249  2013-08-07 14:12  scriptControl-Example\WindowsFormsApplication1\Properties\Settings.settings

     文件       3970  2013-08-07 14:41  scriptControl-Example\WindowsFormsApplication1\WindowsFormsApplication1.csproj

     文件        914  2013-08-07 14:12  scriptControl-Example\WindowsFormsApplication1.sln

    ..A..H.     22528  2013-08-07 16:18  scriptControl-Example\WindowsFormsApplication1.suo

     目录          0  2013-08-07 14:12  scriptControl-Example\WindowsFormsApplication1\obj\x86\Debug\TempPE

     目录          0  2013-08-07 15:24  scriptControl-Example\WindowsFormsApplication1\obj\x86\Debug

     目录          0  2013-08-07 14:15  scriptControl-Example\WindowsFormsApplication1\bin\Debug

     目录          0  2013-08-07 14:12  scriptControl-Example\WindowsFormsApplication1\obj\x86

     目录          0  2013-08-07 14:12  scriptControl-Example\WindowsFormsApplication1\bin

............此处省略7个文件信息

评论

共有 条评论