views:

189

answers:

10

I'm currently in the need of developing a Windows application. I want to keep things simple (in the spirit of uTorrent) and I would like the result program to be a single .exe file containing all that it needs.

The program is simple. It just needs some UI. It needs to run for a long period of time (lay there as a tray icon). It needs to do some routine tasks like simple I/O. It also needs to access the internet, specifically some web server.

Apart from these small requirements I would like to write all of it in JavaScript, as I feel more comfortable with it than any other language.

I know there's things like Windows Script Host that let you run JavaScript programs and interact with some Win32 API, but will I be able to do everything I need with Windows Script Host? Can I pack all of the Windows Script Host in a single .exe?

If not, what alternatives do I have for JavaScript?

A: 

I'm not 100% but I believe WSH uses JScript or WScript, not JavaScript.

Angelo R.
JScript is a Microsoft's flavour of JavaScript/ECMAScript. Most people actually just refer to JScript as JavaScript.
Andy E
JScript and JavaScript are the same thing - they're both ECMAScript. But Microsoft didn't want to interfere with Sun's trademark on "Java" so they called their ECMAScript implementation "JScript." But it's the same language.
EAMann
I think the languages are pretty much identical at this level (without the DOM etc.). What are the differences?
Luca Matteis
@Lucas lack of litigation. Same reason J# isn't called Java#.
David Lively
While it does follow ECMAScript, because it's Microsoft it also introduces other things that don't follow the standard: http://msdn.microsoft.com/en-us/library/4tc5a343(v=VS.85).aspx
Angelo R.
@Angelo: likewise, many flavours introduce things that aren't part of the standard. Many things on that list are now compliant and/or part of the spec. Mozilla also implement a lot of non-standard features, such as the ability to call a regular expression as if it were a function.
Andy E
A: 

Or you can install a Apache (or any other http server) on your Windows and run a webpage directly using this and you web browser ?

Shahor
+2  A: 

Aside from Windows Script Host, there are

Both are written with standard web technologies, HTML, JavaScript, Flash, etc. They can also be extended with COM objects/ActiveX controls such as FileSystemObject, WMI, WScript or even ones that you write yourself. Windows Desktop Gadgets have access to a separate API/namespace with various Win32-esque properties and methods.

Andy E
Ok. I'm not that comfortable with the entire COM object API, but can I do I/O and HTTP requests with it? The internet seems to lack major documentation on these. What about UI and Windows Script Host... couldn't find much of that either.
Luca Matteis
@Luca: You can create cross domain web requests using XMLHttpRequest in HTAs and Windows Desktop Gadgets. However, I/O will require a higher level interface such as a COM component. You can use WinHTTPRequests from WSH, but they have to be synchronous in most cases.
Andy E
Why the downvote? This is fine input.
Pekka
@Pekka: Dunno, it wasn't me :)
Luca Matteis
@Andy E: Awesome. Do you have good DOCs for this? I would appreciate some UI tutorials as well :)
Luca Matteis
@Luca: I linked to the Docs for HTAs and WDGs, both those pages have introductory tutorials but I think you'll probably find Google to be a more useful resource than my brain for tutorials on WinHTTP :-)
Andy E
This is probably getting downvoted because it features evil Micro$oft technology. I have no other explanation.
Pekka
@Pekka: either that or the other people downvoted here assumed I downvoted them and are being vengeful/petty. In either case, as long as the OP finds it useful it doesn't matter how many votes it gets. Thanks for having my back ;-)
Andy E
@Andy E: Actually I do find it very useful thanks. Most of the recent answers have nothing to do with my question, and the most up-voted is about AIR which also seems unrelated due to me wanting a simple .exe and not an entire runtime as a dependency.
Luca Matteis
+2  A: 

Internet Explorer introduced the concept of Hypertext Applications in IE 5. It never made a big breakthrough, so resources and documentation are scarce.

Mozilla-backed competitor Prism seems to be alive and well, though, and is definitely worth a look.

Prism is an application that lets users split web applications out of their browser and run them directly on their desktop

Pekka
+1, I like the look of Prism. Kind of like how HTAs should have been done :-)
Andy E
@Andy yup. HTAs were a great concept, I loved it when they introduced it back in the day, but they never really got it to take off. Maybe Prism gets it done better!
Pekka
+3  A: 

I think you're looking for Adobe AIR

The Adobe® AIR® 2 runtime enables developers to use HTML, JavaScript, Adobe Flash® software, and ActionScript® to build web applications that run as standalone client applications without the constraints of a browser. ~ The AIR website

Ryan Kinal
i still need the runtime... that's an extra overhead i would like to avoid
Luca Matteis
Then go ahead and write your own C++ app which embeds V8 and write all the C++ binding code for it yourself. Or wait until someone else does it. Or, just learn C++ or anything else which works nicely on Windows. You won't improve your skills in other languages by always relying on a JavaScript solution.
Ivo Wetzel
There's also Rhino, but it requires Java, which is quite bloated: https://developer.mozilla.org/en/Rhino_documentation
Ryan Kinal
I like this, runtime or not. I didn't know AIR does this.
Pekka
A: 

I believe the best way to go is V8 JavaScript Engine provided by Google.

"V8 can run standalone, or can be embedded into any C++ application." - which I believe is perfect for your needs, because you can do most of the stuff in JavaScript and use provided interfaces to communicate with the system.

rochal
He will still have to write some amount of C++ code, which I think is the part he's afraid of, at least all of his GUI will need some interface to a native toolkit. So in the end he will have to write large amounts of binding code. Overall he will end up writing a hell lot more code just for the sake of being able to use JS.
Ivo Wetzel
A: 

Color me crazy, but its only a short step form Javascript to Java or C#. I'd suggest C# as, on a windows machine, the libraries are already there. You can just copypaste your .exe and let 'er rip.

Will
Good point. This would definitely make things easy... There are not many ways of doing this with a single .EXE with not too much overhead if you want to stay with Javascript.
Pekka
idiomatic javascript and idiomatic c# are almost complete opposites.
Matt Briggs
Are you suggesting that he run JavaScript from *within* a C# executable? (e.g., using WSH through interop and loading the scripts from resources...) Because, that actually does work pretty well. But if you're suggesting that C# is anything like JavaScript...
Shog9
#Matt syntactically they are very similar. The only true differences that a normal programmer would notice is the difference between the DOM and the framework. Advanced javascript programmers would have issues with type definitions, but I think C# is clearer rather than the way it is in Javascript (i.e., obscure).
Will
@SHog9 no, I wasn't suggesting that. You have to admit that Javascript syntax is very close to javascript. The major difference is the context (DOM vs. framework).
Will
@Will: There are similarities (more with the introduction of lambda expressions and now dynamic types), but as Matt notes the *idioms* are still quite different... For instance, a JS programmer might think nothing of creating a dynamic object and passing it in as the sole argument to a function, where it is merged with another such object to produce a set of parameters for the algorithm... A C# programmer would use either multiple, overloaded methods, an instance of a class that defaulted its members, or (with C# 4.0) named parameters. Conceptually these are the same, but the *appearance*...
Shog9
A: 

Why not use Rhino -- JavaScript on the JVM? You can even compile your scripts to .class files and package them into a JAR along with Rhino for easy distribution...

Weston C
A: 

If you want a single .EXE, what runtimes are you okay if they are required pre-requisites?

If you're okay with requiring .NET runtime to be preinstalled, then you do all your work in JScript.NET

zumalifeguard
A: 

I found that there's actually a JavaScript compiler that comes with the .NET framework called jsc.exe.

For more information:

http://www.phpied.com/make-your-javascript-a-windows-exe/

http://msdn.microsoft.com/en-us/library/7435xtz6(VS.80).aspx

I guess it's not really JavaScript since it introduces extra things like import and even some class syntax which is weird for me. But this works perfectly for me as I will just doing things as I am used to on the web.

Luca Matteis