/// <summary> /// Determines if a script engine with the input name exists. /// </summary> /// <param name="language">The language.</param> /// <returns>true if the engine exists; false otherwise.</returns> public static Version GetVersion(string language) { if (language == null) { throw new ArgumentNullException("language"); } Type engine; Guid clsid = ConvertUtilities.ToGuid(language); if (clsid != Guid.Empty) { engine = Type.GetTypeFromCLSID(clsid, false); } else { engine = Type.GetTypeFromProgID(language, false); } if (engine == null) { return(null); } IActiveScript scriptEngine = Activator.CreateInstance(engine) as IActiveScript; if (scriptEngine == null) { return(null); } IActiveScriptProperty scriptProperty = scriptEngine as IActiveScriptProperty; if (scriptProperty == null) { return(new Version(1, 0, 0, 0)); } int major = GetProperty(scriptProperty, SCRIPTPROP_MAJORVERSION, 0); int minor = GetProperty(scriptProperty, SCRIPTPROP_MINORVERSION, 0); int revision = GetProperty(scriptProperty, SCRIPTPROP_BUILDNUMBER, 0); Version version = new Version(major, minor, Environment.OSVersion.Version.Build, revision); Marshal.ReleaseComObject(scriptProperty); Marshal.ReleaseComObject(scriptEngine); return(version); }
/// <summary> /// Initializes a new instance of the <see cref="ScriptEngine"/> class. /// </summary> /// <param name="language">The scripting language. Standard Windows Script engines names are 'jscript' or 'vbscript'.</param> public ScriptEngine(string language) { if (language == null) { throw new ArgumentNullException("language"); } Type engine; Guid clsid = ConvertUtilities.ToGuid(language); if (clsid != Guid.Empty) { engine = Type.GetTypeFromCLSID(clsid, true); } else { engine = Type.GetTypeFromProgID(language, true); } _engine = Activator.CreateInstance(engine) as IActiveScript; if (_engine == null) { throw new ArgumentException(language + " is not an Windows Script Engine", "language"); } Site = new ScriptSite(); _engine.SetScriptSite(Site); // support 32-bit & 64-bit process if (IntPtr.Size == 4) { _parse32 = (IActiveScriptParse32)_engine; _parse32.InitNew(); } else { _parse64 = (IActiveScriptParse64)_engine; _parse64.InitNew(); } }