Methods for creating an. exe or. dll file by using JScript _javascript tips

Source: Internet
Author: User
Tags reserved
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) (JavaScript Shell scripting:c:\> cscript jslint.js in WSH). The latest version of JScript (JScript.NET) is based on ECMAScript 4.0 and can be compiled in a. NET environment.
The. NET framwork contains a JScript compiler: Jscriptcompiler (C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\jsc.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.
Copy Code code as follows:

JSC [Options] < source files > [[options] < source files ...]

JScript Compiler Options

– Output file-
/out:<file> 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:<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:<path> specify additional directories in which to search for references
/r[eference]:<file list> references metadata from the specified assembly file <file List>: <assembly name>[;<assembly Name>

Resources
/win32res:<file> Specifies the Win32 resource file (. res)
/res[ource]:<info> embedding the specified resource <info>: <filename>[,<name>[,public|private]]
/linkres[ource]:<info> link the specified resource to this assembly <info>: <filename>[,<name>[,public|private]]

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

Miscellaneous
@<filename> for more options, please read the response file
/? Show Help
/help Display Help
/d[efine]:<symbols> Define conditional Compilation symbols
/NOLOGO does not show compiler copyright banner
/print[+|-] provides the print () function

High
/codepage:<id> Open the source file with the specified code page ID
/lcid:<id> the specified LCID for the message and default code page
/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:\test\helloWorld.js), which reads as follows:

var date = new Date (); Print (' Hello world! \ntoday is ' + date);

Then we compile:

C:\TEST&GT;JSC Helloworld.jsmicrosoft (R) JScript Compiler version 8.00.50727for Microsoft (r). NET Framework version 2.0. 50727Copyright (C) Microsoft Corporation 1996-2005. All rights reserved.
You will be surprised to find that the C:\test directory more than a HelloWorld.exe file, very simple bar, hehe

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

C:\test>helloworldhello 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:
Copy Code code as follows:

Package LIBHW {
Class HelloWorld {
function Run () {
var date = new Date ();
Return ' Hello world! \ntoday is ' + date;
}
}
}

Compile statement:

C:\test>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 ();p rint (Hw.run ());
Then compile the consumer.js file and execute Consumer.exe:

C:\TEST&GT;JSC Consumer.jsmicrosoft (R) JScript Compiler version 8.00.50727for Microsoft (r). NET Framework Version 2.0.50 727Copyright (C) Microsoft Corporation 1996-2005. All rights reserved. C:\test>consumerhello 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:
Copy Code code 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:\test>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
    • "JavaScript Shell scripting"

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.