14

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?

8
  • Are you aware of HTAs? That would be a way of making the GUI part entirely in HTML/CSS/JS, at least. Commented Aug 31, 2010 at 14:25
  • @Andreas: Yeah, I think it works similarly to Windows Script Host (probably uses cscript.exe etc). So I'm still not sure if it's enough to do what I need. Commented Aug 31, 2010 at 14:30
  • 5
    JavaScript is NOT a browser engine, it's a scripting language. There might be implementations of it which are bound to a particular browser, but at least V8 is a "vanilla" engine without any particular bindings. Take a look at Node.js for one example of non browser usage. Commented Aug 31, 2010 at 16:24
  • @Lucas: Javascript is not exactly a programming language - ok put it back on you - name one program that is written in Javascript that is used everywhere - the answer is zero - it is embedded into the browser - and I stand by that statement - fact! Why do you think the web pages have javascript? You can never do pointers, memory management in Javascript... need I go on... file input/output... you're pretty limited by what you say - you know javascript better - why not do it in C as you say? What do you have against it? You say you knew C pretty well...so what's stopping you from doing it? Commented Sep 1, 2010 at 16:24
  • 6
    @tommieb75: I've actually used JavaScript for writing portions of Windows desktop apps. I've also used C++, C#, and a handful of other languages for this purpose. There are pros and cons to each, but being limited to in-browser apps is definitely not one that applies to JS. You accuse Luca of being shallow and fixated, but this seems to be an affliction you yourself suffer from - you seem unable to believe that others have had any success using tools you yourself were unwilling or unable to use effectively. Commented Sep 1, 2010 at 23:42

11 Answers 11

10

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.

Sign up to request clarification or add additional context in comments.

Comments

4

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.

8 Comments

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: 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.
@Pekka: Dunno, it wasn't me :)
@Andy E: Awesome. Do you have good DOCs for this? I would appreciate some UI tutorials as well :)
@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.
|
4

It seems that nobody mentioned JSDB.

JSDB offers a command line environment which you can execute arbitrary javascript code. You can easily compile to a .exe file by using the command copy /b jsdb.exe+program.zip program.exe

It's important to know that you've got to call your main js file main.js within a standard zip file. Not sure if the name program.zip is required.

I haven't actually tried making GUI applications with this yet - although it seems to support various APIs like ActiveX.

It's possible that by using the copy /b command mentioned above, you could compile a script from the wscript.exe file - but I tried and couldn't get it working. Let me know if anybody tries and has success somehow.

Comments

3

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

4 Comments

i still need the runtime... that's an extra overhead i would like to avoid
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.
There's also Rhino, but it requires Java, which is quite bloated: developer.mozilla.org/en/Rhino_documentation
I like this, runtime or not. I didn't know AIR does this.
3

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

2 Comments

+1, I like the look of Prism. Kind of like how HTAs should have been done :-)
@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!
2

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.

1 Comment

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.
0

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

6 Comments

JScript is a Microsoft's flavour of JavaScript/ECMAScript. Most people actually just refer to JScript as JavaScript.
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.
I think the languages are pretty much identical at this level (without the DOM etc.). What are the differences?
While it does follow ECMAScript, because it's Microsoft it also introduces other things that don't follow the standard: msdn.microsoft.com/en-us/library/4tc5a343(v=VS.85).aspx
@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.
|
0

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.

6 Comments

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.
idiomatic javascript and idiomatic c# are almost complete opposites.
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...
#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).
@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).
|
0

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

Comments

0

Chromium Embedded Framework (CEF) may give you some help. i have not clearly know how, but i realy found many Apps using this framework.

http://code.google.com/p/chromiumembedded/

Introduce for CEF are: The Chromium Embedded Framework (CEF) is an open source project founded by Marshall Greenblatt in 2008 to develop a Web browser control based on the Google Chromium project. CEF currently supports a range of programming languages and operating systems and can be easily integrated into both new and existing applications. It was designed from the ground up with both performance and ease of use in mind. The base framework includes C and C++ programming interfaces exposed via native libraries that insulate the host application from Chromium and WebKit implementation details. It provides close integration between the browser control and the host application including support for custom plugins, protocols, JavaScript objects and JavaScript extensions. The host application can optionally control resource loading, navigation, context menus, printing and more, while taking advantage of the same performance and HTML5 technologies available in the Google Chrome Web browser.

Numerous individuals and organizations contribute time and resources to support CEF development, but more involvement from the community is always welcome. This includes support for both the core CEF project and external projects that integrate CEF with additional programming languages and frameworks (see the "External Projects" section below).

Comments

-1

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...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.