3

We have a javascript that i would like to compile to a exe.

I am using the jsc.exe to do this. However, i get the following error when attempting to compile.

error JS1135: Variable 'WScript' has not been declared

Here is the segment of code:

var omgShell = WScript.CreateObject( "WScript.Shell" );

What is the problem here?

Thanks

prolink007
  • 33,872
  • 24
  • 117
  • 185
  • Have you tried the solution at this link? http://social.msdn.microsoft.com/Forums/nl/netfxjscript/thread/6f6846e1-80ac-49cd-8f79-07c44f717c3c they reccommend `new ActiveXObject("WScript.Shell");` instead of `WScript.CreateObject` – captncraig Mar 28 '12 at 18:52
  • I saw that, but i didn't think it was related to my issue. lol. I will give it a try and see what happens. – prolink007 Mar 28 '12 at 18:54
  • What about everywhere else that i am using WScript? For instance `WScript.Echo(...);`. I know very little about the `javascript` world, just trying to get this script to work. =) – prolink007 Mar 28 '12 at 18:57
  • I actually just realized that the problem i was having was unrelated to this. I no longer need to compile it to `exe`. I got everything to compile with the above mentioned suggestions of `new ActiveXObject("WScript.Shell");`. I also changed all my references of `WScript` to `omgShell` and it seemed to work. But i figured out that was not the problem at all and just solved my other problem. Please post this as the answer CMP and i will accept it, as it was helpful. Thanks – prolink007 Mar 28 '12 at 20:34

2 Answers2

5

WScript is a variable that is not available in the context of jsc.exe. See this post for more info.

In your case simply use var omgShell = new ActiveXObject("WScript.Shell");, and replace all references to WScript with omgShell

or simply do var WScript = new ActiveXObject("WScript.Shell");

captncraig
  • 22,118
  • 17
  • 108
  • 151
3

JScript.NET is not the same thing as WSH. You will need to modify your code to use the .NET objects instead of the WSH objects.

Alex Turpin
  • 46,743
  • 23
  • 113
  • 145