title: Loading the TypeScript compiler into ClearScript, "WScript is undefined", impossible task?
body: <p>I tried using <a href="http://clearscript.codeplex.com/" rel="noreferrer">ClearScript</a> to load the <a href="http://www.typescriptlang.org/" rel="noreferrer">TypeScript</a> compiler in order to compile some basic TypeScript code.</p>
  
  <p>Unfortunately, when executing the TypeScript compiler source I get this error:</p>
  
  <blockquote>
    <p>'WScript' is undefined</p>
  </blockquote>
  
  <p>This is the <a href="http://linqpad.net" rel="noreferrer">LINQPad</a> program I've used, place the ClearScript dll's and the <a href="http://typescript.codeplex.com/SourceControl/changeset/view/2bee84410e02#bin/tsc.js" rel="noreferrer">TypeScript compiler file</a> alongside the .linq program:</p>
  
  <pre><code>void Main()
  {
      using (var js = new Microsoft.ClearScript.Windows.JScriptEngine(Microsoft.ClearScript.Windows.WindowsScriptEngineFlags.DisableSourceManagement))
      {
          var typeScriptSource = File.ReadAllText(Path.Combine(Path.GetDirectoryName(Util.CurrentQueryPath), "tsc.js"));
          js.Execute(typeScriptSource);
          const string typeScriptCode = @"
              class Greeter {
                  greeting: string;
                  constructor(message: string) {
                      this.greeting = message;
                  }
                  greet() {
                      return ""Hello, "" + this.greeting;
                  }
              }
              function test()
              {
                  var greeter = Greeter(""world"");
                  return greeter.greet();
              }
          ";
          js.Script.TypeScript.Compile(typeScriptCode);
  
          object result = js.Script.test();
          result.Dump();
      }
  }
  
  #region Copy ClearScript to correct location
  
  static UserQuery()
  {
      foreach (var filename in new[] { "ClearScriptV8-32.dll", "ClearScriptV8-64.dll", "v8-ia32.dll", "v8-x64.dll" })
      {
          try
          {
              string sourcePath = Path.Combine(Path.GetDirectoryName(Util.CurrentQueryPath), filename);
              string targetPath = Path.Combine(Path.GetDirectoryName(typeof(Util).Assembly.Location), filename);
  
              File.Copy(sourcePath, targetPath, true);
          }
          catch (IOException ex)
          {
              unchecked
              {
                  const int fileInUseHresult = (int)0x80070020;
                  if (ex.HResult != fileInUseHresult)
                      throw;
              }
          }
      }
  }
  
  #endregion
  </code></pre>
  
  <p>The error occurs on this line:</p>
  
  <pre><code>js.Execute(typeScriptSource);
  </code></pre>
  
  <p>I have created a .zip file with everything, you need <a href="http://linqpad.net" rel="noreferrer">LINQPad</a> to load the .linq file and experiment. The ClearScript dll's are created from the unmodified source but if you don't trust me you should be able to reproduce those yourself (if you don't have them that is).</p>
  
  <p>It is available here: <a href="https://dl.dropboxusercontent.com/u/8341541/Stack%20Overflow/SO19023498.zip" rel="noreferrer">Dropbox Link to SO19023498.zip</a>.</p>
  
  <p>What I've tried:</p>
  
  <ol>
  <li><p>I tried executing this code first:</p>
  
  <pre><code>var WScript = new ActiveXObject("WSH.WScript");
  </code></pre>
  
  <p>This only produced this error: <code>Automation server can't create object</code></p>
  
  <p>I did not see <code>WSH.WScript</code> in the registry under HKEY_CLASSES_ROOT so that might be it.</p></li>
  <li><p>I tried figuring out how to create the object from .NET and setting it into the script context, but I am apparently not looking in the right place.</p></li>
  </ol>