大网数据广告活动
Windows 系统接口

Scripting with COM Objects

· 52CE 我爱测

A *scripting language* is a programming language that is parsed at run time by a *scripting engine*, a component that translates scripts written in that language into machine code. Each scripting engine translates a specific scripting language. A *scripting host* is an application, such as a Web browser, that hosts a scripting engine to run scripts. If…

A scripting language is a programming language that is parsed at run time by a scripting engine, a component that translates scripts written in that language into machine code. Each scripting engine translates a specific scripting language. A scripting host is an application, such as a Web browser, that hosts a scripting engine to run scripts. If your scripting host supports COM, you can write scripts that use COM objects. The following topics describe scripting hosts that support COM objects, common scripting languages, and how to translate between scripting languages.

A scripting language differs from a compiled language in that it is translated into machine code at run time. This means that each time you run a script, the scripting engine first parses the code and then runs it. In contrast, compiled languages, such as C++, are translated to machine code once, during compilation. When you run a compiled application, the operating system simply runs the precompiled code.

Because a scripting engine must reparse a script each time it runs, scripting languages are typically slower and less efficient than their precompiled counterparts. The advantage of scripts, however, is they are easy to write and maintain. Scripting languages are usually simpler than precompiled languages, and when a script changes, it does not need to be recompiled. For lightweight and rapidly changing applications, such as webpages, scripting languages are ideal.

There are several host environments in which you can write scripts that use COM objects, as described following:

In each of the host environments mentioned preceding, a scripting engine parses and runs the script. Because the engine for each scripting language is a separate component, you can add a new scripting language to an environment by adding a new engine.

The most commonly used scripting languages are:

  • Microsoft Visual Basic Scripting Edition (VBScript), a subset of Visual Basic.
  • JavaScript, the Netscape scripting language, formerly known as LiveScript.
  • Microsoft JScript development software, the Microsoft implementation of the ECMA 262 language specification.

Microsoft provides scripting engines for JScript and VBScript. Other software companies provide ActiveX scripting engines for languages such as PerlScript, PScript, Python, and others.

For more information see the ECMA 262 language specification.

Note that most scripting languages, such as VBScript and JScript, cannot access or modify files. This inability prevents the script from altering data on client computers. COM objects, however, have no such limitations. Once they are downloaded and installed on client computers, they can perform any standard application action. Thus, users should only download and run ActiveX controls from trusted sources.

For information on translating between scripting languages, see the following topics:

Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Win32 documentation
适用范围
Windows Win32 API · Source date 05/31/2018
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。