JScript Tutorial: Using JScript to create an. exe or. dll file

Source: Internet
Author: User
Tags date net reserved resource version variable

Article Introduction: JScript is an Active scripting language developed by Microsoft and is implemented based on the ECMASCRIPT specification. JavaScript in Internet Explorer, in effect, refers to JScript. JScript has been supported by Windows Script Host (WSH). The latest version of JScript (JScript.NET) is based on ECMAScript 4.0, which is not yet finalized, and can be in. NET Environment

What is JScript?

JScript is an Active scripting language developed by Microsoft and is implemented based on the ECMASCRIPT specification. JavaScript in Internet Explorer, in effect, refers to JScript. JScript has been supported by Windows Script Host (WSH). The latest version of JScript (JScript.NET) is based on ECMAScript 4.0, which is not yet finalized, and can be in. NET environment.

The. NET framwork contains a JScript compiler: Jscriptcompiler (C:windowsmicrosoft.netframeworkv2.0.50727jsc.exe), which enables JScript The file is compiled to an. exe or. dll file.

For ease of use, we can add the Jscriptcompiler path to the environment variable (environment variable –> system variable –> path). You can see the compiler-related help options by calling the command "JSC" directly in the CMD Program run window.

JSC [Options] [options] ...]

JScript Compiler Options

– Output file-
/out : Specifies the name of the binary output file
/t[arget]:exe Create a console application (default)
/t[arget]:winexe Creating Windows applications
/t[arget]:library Create library Assemblies
/platform: limits the platform on which this code can run; it must be x86, Itanium, x64, or anycpu. Default is AnyCPU

– Input File-
/autoref[+-] automatically references assemblies based on imported namespaces and fully qualified names (default sentiment
Condition is on)
/lib: Specifies additional directories in which to search for references
/r[eference]: references metadata from the specified assembly file : [; ...]

Resources
/win32res: Specify Win32 resource file (. res)
/res[ource]: embedding the specified resource : [, [, Publicprivate]]
/linkres[ource]: link The specified resource to this assembly : [, [, Publicprivate]]

– Code Generation-
/debug[+-] Emit debugging information
/fast[+-] Disable language features to enable code to better generate
/warnaserror[+-] treats warnings as errors
/w[arn]: set Warning Level (0-4)

Miscellaneous
@ For more options, please read the response file
/? Show Help
/help Display Help
/d[efine]: defining conditional compilation Symbols
/NOLOGO does not show compiler copyright banner
/print[+-] provides the print () function

High
/codepage: Open the source file with the specified code page ID
/LCID: Use the specified LCID for messages and default code pages
/nostdlib[+-] does not import the standard library (mscorlib.dll) and changes the Autoref default value to OFF
/utf8output[+-] emits compiler output in UTF-8 character encoding
/versionsafe[+-] Specify a default value for members that are not marked "override" or "Hide"

Create an. exe file

First create the JS file (c:esthelloworld.js), which reads as follows:

var date = new Date ();
Print (Hello world! 
Today is  + date);

Then we compile:

C:	est>jsc helloworld.js
Microsoft (r) JScript Compiler version 8.00.50727 for
Microsoft (r). NET Framework version 2.0.50727
Copyright (C) Microsoft Corporation 1996-2005. All rights reserved.

You will be surprised to find that the C:est directory more than a HelloWorld.exe file, very simple bar, hehe

Finally, we can execute the HelloWorld.exe file directly:

C:	est>helloworld
Hello world!
This is Fri June 3 23:13:20 utc+8 2011

Done!!

Creating a. dll file

The creation of a. dll file is also very simple:

Package LIBHW {
class HelloWorld {
function run () {
var date = new Date ();
return Hello world! 
Today is  + date;}}

Compile statement:

C:	est>jsc/t:library libhw.js

For the generated LibHW.dll file, we can call (similar to Python) by creating a new. exe file (consumer.js–> consumer.exe) to import the module.

First create the Consumer.js file:

Import LIBHW;
var hw = new Libhw.helloworld ();
Print (Hw.run ());

Then compile the consumer.js file and execute Consumer.exe:

C:	est>jsc consumer.js
Microsoft (r) JScript Compiler version 8.00.50727 for
Microsoft (r). NET Framework version 2.0.50727
Copyright (C) Microsoft Corporation 1996-2005. All rights reserved.
C:	est>consumer
Hello world!
Today's Sat June 4 00:42:35 utc+8 2011

Of course you can also create Windows applications, the Consumer.js file in the example above is modified as follows:

Import System.Windows.Forms; This has a MessageBox class
import LIBHW;
var hw = new Libhw.helloworld ();
MessageBox.Show (
hw.run (),
"dude!",
MessageBoxButtons.OK,
messageboxicon.exclamation
);

Compile statement:

C:	est>jsc/t:winexe consumer.js

Double-click on the newly generated consumer.exe file, haha, is not very fulfilling!

From the above example, you can see the potential of JScript is unlimited, not to do, only unexpected.

Extended reading:

Make your JavaScript a Windows. exe

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.