Skip to content
Skip to breadcrumbs
Skip to header menu
Skip to action menu
Skip to quick search
Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Sign Up
Dashboard
Groovy
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<table class="wysiwyg-macro" data-macro-name="excerpt" data-macro-parameters="atlassian-macro-output-type=BLOCK|hidden=true" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2V4Y2VycHQ6aGlkZGVuPXRydWV8YXRsYXNzaWFuLW1hY3JvLW91dHB1dC10eXBlPUJMT0NLfQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="RICH_TEXT"><tr><td class="wysiwyg-macro-body"><p>script Windows ActiveX and COM components with Groovy</p></td></tr></table><table class="wysiwyg-macro" data-macro-name="note" data-macro-parameters="title=Under Construction" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e25vdGU6dGl0bGU9VW5kZXIgQ29uc3RydWN0aW9ufQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="RICH_TEXT"><tr><td class="wysiwyg-macro-body"><p>The <strong>Scriptom</strong> documentation is changing to reflect the new <strong>Maven</strong> build and artifacts.<br /> This is going to take some time. In the meantime, please take what you read with a grain of salt,<br /> and pardon the messiness.<br /> Rest assured that while there will be some restructuring of the documentation, the previous<br /> builds will still be available for anyone who needs them, ongoing, indefinitely.</p></td></tr></table><h1>Introduction</h1><p><strong>Scriptom</strong> is an optional Groovy module originally developed by <a href="http://glaforge.free.fr/weblog">Guillaume Laforge</a>. It combines the elegant "syntactical sugar" of Groovy with the power of the <a href="http://sourceforge.net/projects/jacob-project/">Jacob library (<strong>Ja</strong>va <strong>CO</strong>M <strong>B</strong>ridge)</a>. <strong>Scriptom</strong> lets you use <strong>ActiveX</strong> or <strong>COM</strong> Windows components from Groovy. The result is something that looks eerily similar to <em>VBScript </em>- only groovier.</p><p>You can use <strong>Scriptom</strong> to automate <strong>Word</strong> or <strong>Excel</strong> documents, control <strong>Internet Explorer</strong>, make your PC talk using the <strong>Microsoft Speech API</strong>, monitor processes with <strong>WMI</strong> (Windows Management Instrumentation), or browse the <strong>Windows Registry</strong> using <strong>WShell</strong> - and much more. <strong>Scriptom</strong> also provides an easy way to talk to custom <strong>VB6</strong> or <strong>Microsoft.NET</strong> libraries. </p><p>Of course, <strong>Scriptom</strong> can be used only on <strong>Microsoft Windows</strong>.</p><p><strong>Scriptom</strong> is included as an option in the <a href="http://groovy.codehaus.org/Download">Windows Installer</a>, and <strong>Scriptom</strong> can be downloaded from this page (see below). The <strong>Scriptom</strong> codebase is stable and feature-complete. The <strong>Jacob</strong> project - <strong>Scriptom</strong>'s foundation <strong>-</strong> was started in 1999 and is being used in countless production Java applications worldwide. <strong>Scriptom</strong> is now in wide use as well, and has proven to be stable and mature. </p><p><strong>Scriptom</strong> gives you all the <strong>COM</strong>-scripting power of <strong>Jacob</strong>, only it is a lot easier. See <a class="confluence-link" href="/display/GROOVY/Getting+Started+with+COM" data-linked-resource-id="47841297" data-linked-resource-type="page" data-linked-resource-default-alias="Getting Started with COM" data-base-url="http://docs.codehaus.org">Getting Started with COM</a> for some tips to get you started.</p><h1>Requirements</h1><p>The following are required to run <strong>Scriptom</strong>:</p><ul><li><strong>Groovy 1.5</strong> or <strong>1.6</strong></li><li><strong>Java 1.5</strong> or later</li><li><strong>Windows</strong> and <strong>Java</strong> for <strong>x86</strong> or <strong>x64</strong> (<strong>AMD64</strong>) architectures. <strong>Itanium</strong> (<strong>IA-64</strong>) is not supported.</li></ul><h1>Maven-Generated Documentation</h1><p>Maven-generated documentation is available at <a href="http://groovy.codehaus.org/modules/scriptom/1.6.0/index.html">http://groovy.codehaus.org/modules/scriptom/1.6.0/index.html</a>. This contains useful information from the build, including JavaDoc for all projects.</p><h1>Installation</h1><p><strong>Scriptom</strong> is part of the <a href="http://groovy.codehaus.org/Download">Windows Installer</a>. If you are running Groovy scripts on <strong>Windows</strong>, you are all set.</p><h2>"Just the (Arti)facts, Ma'am."</h2><p>If you are running Groovy outside the <strong>Windows Installer</strong>, and you aren't using <strong>Maven</strong> or <strong>Grape</strong>, you probably just need the pre-packaged JAR files and associated binaries. You've come to the right place.</p><p>Note that as of release <strong>1.6.0</strong>, the distribution archive is formatted differently. The new format matches the folder structure needed by the <strong>Windows Installer</strong>. Source code, build scripts, and documentation are no longer included in the distribution.</p><ul><li><img class="emoticon emoticon-yellow-star" data-emoticon-name="yellow-star" border="0" src="/s/en_GB/3278/15/_/images/icons/emoticons/star_yellow.png" alt="(star)" title="(star)" /> <a href="http://repository.codehaus.org/org/codehaus/groovy/modules/scriptom/scriptom-all-assembly/1.6.0/scriptom-all-assembly-1.6.0.zip">Scriptom 1.6.0</a> (4/8/2009) - No new features or bug fixes. Distribution for <strong>Windows Installer</strong>. Includes only compiled artifacts. Supports <strong>Groovy 1.5</strong> and up.</li><li><a class="confluence-link unresolved" data-filename="scriptom-1.5.4.zip" data-linked-resource-default-alias="scriptom-1.5.4.zip" href="#">scriptom-1.5.4.zip</a> Build 12 (12/26/2008) - Full project including source. Supports <strong>Groovy 1.5</strong> and up.</li></ul><h2>Adding <strong>Scriptom</strong> to a <strong>Maven</strong> Project</h2><p>You can add <strong>Scriptom</strong> to a <strong>Maven</strong> project. Because there is JNI involved, it isn't quite as simple as adding a dependency, but it is doable. <strong>Need to come up with an example of creating an assembly with GMaven.</strong></p><ol><li><p>Add the <strong>Scriptom</strong> dependency to your <strong>Maven</strong>project.</p><table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre><dependency> <groupId>org.codehaus.groovy.modules.scriptom</groupId> <artifactId>scriptom</artifactId> <version>1.6.0</version> </dependency> </pre></td></tr></table></li><li><p>Add the <strong>Jacob</strong> JAR dependency. This JAR must be loaded only once, so if you are working in a server application like <strong>Tomcat</strong> or <strong>GlassFish</strong>, you need to ensure that <strong>Jacob</strong>'s JAR is only loaded by the system classloader. <strong>Need more explicit instructions on this...</strong></p><table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre><dependency> <groupId>net.sf.jacob-project</groupId> <artifactId>jacob</artifactId> <version>1.14.3</version> <type>jar</type> </dependency> </pre></td></tr></table></li><li><p><strong>Jacob</strong> requires a DLL. It's a JNI project, after all. But <strong>Jacob</strong> actually supports two versions of the DLL it needs, one for 32-bit x86 systems, and one for the AMD x64 architecture (works with 64-bit Intel chips too). The easiest way to get this to work is to put both DLLs somewhere on the system path. <strong>Jacob</strong> will automatically pick the one it needs. <strong>Need to detail the other ways to specify the Jacob DLL.</strong></p><table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre><dependency> <groupId>net.sf.jacob-project</groupId> <artifactId>jacob</artifactId> <version>1.14.3</version> <type>dll</type> <classifier>x64</classifier> </dependency> <dependency> <groupId>net.sf.jacob-project</groupId> <artifactId>jacob</artifactId> <version>1.14.3</version> <type>dll</type> <classifier>x86</classifier> </dependency> </pre></td></tr></table></li></ol><p><strong>Need to detail the TLB projects, constants, etc.</strong></p><h2>The Old Way to Install (deprecated)...</h2><p><strong>Download</strong> the project archive and extract the files.</p><ul><li><img class="emoticon emoticon-thumbs-up" data-emoticon-name="thumbs-up" border="0" src="/s/en_GB/3278/15/_/images/icons/emoticons/thumbs_up.png" alt="(thumbs up)" title="(thumbs up)" /> <a class="confluence-link unresolved" data-filename="scriptom-1.5.4.zip" data-linked-resource-default-alias="scriptom-1.5.4.zip" href="#">scriptom-1.5.4.zip</a> Build 12 (12/26/2008) - <strong>Scriptom</strong> JAR file, <strong>Scriptom-1.5.4bX-32.dll</strong>, <strong>Scriptom-1.5.4bX-64.dll</strong>, Java source code, ANT build script, examples, tests, utilities, and documentation.</li></ul><p>Install the jar file and DLL file(s) into your project, and optionally install an update from Microsoft:</p><ol><li><p>Add the <strong>Scriptom</strong> jar file (<strong>scriptom-1.5.4bX-XX.jar</strong>) into your Java classpath. It contains both <strong>Scriptom</strong> and <strong>Jacob</strong> class files, so you must not include <strong>jacob.jar</strong>.</p><table class="wysiwyg-macro" data-macro-name="warning" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e3dhcm5pbmd9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="RICH_TEXT"><tr><td class="wysiwyg-macro-body"><p><strong>Scriptom</strong> contains a full (current) version of the <strong>Jacob</strong> library. If you are using <strong>Jacob</strong> directly elsewhere in your project, remove all references to it and use the version built in to <strong>Scriptom</strong>.</p></td></tr></table></li><li><p>Copy both <strong>Scriptom-1.5.4bX-XX.dll</strong> files to somewhere on your <strong>java.library.path</strong>. (usually somewhere on the system 'PATH').</p><table class="wysiwyg-macro" data-macro-name="info" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2luZm99&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="RICH_TEXT"><tr><td class="wysiwyg-macro-body"><p>The <strong>Scriptom DLL</strong> naming convention allows multiple versions of <strong>Scriptom</strong> to run on the same machine. However, you can only run a single version of <strong>Scriptom</strong> <strong>JAR</strong> in any given project.</p></td></tr></table></li><li><p>To avoid the dreaded <strong>java.lang.UnsatisfiedLinkError</strong>, download and install one of the following updates from Microsoft: <a href="http://www.microsoft.com/downloads/details.aspx?familyid=200B2FD9-AE1A-4A14-984D-389C36F85647&displaylang=en">Microsoft Visual C++ 2005 SP1 Redistributable Package (x86)</a>or <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=eb4ebe2d-33c0-4a47-9dd4-b9a6d7bd44da&DisplayLang=en">Microsoft Visual C++ 2005 SP1 Redistributable Package (x64)</a>. <strong>Scriptom</strong> doesn't support the <strong>IA-64</strong> (<strong>Itanium</strong>) architecture at this time, mainly due to lack of interest. If you are wondering about the different processor architectures, check out the <a href="http://en.wikipedia.org/wiki/X86-64">x86-64 wiki</a>. It is usually necessary to install these updates on <strong>Windows Server 2003</strong> and <strong>Windows 2000</strong>, and we've found that it may also be necessary for <strong>Windows XP</strong> and even <strong>Vista</strong>.</p><table class="wysiwyg-macro" data-macro-name="note" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e25vdGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="RICH_TEXT"><tr><td class="wysiwyg-macro-body"><p>A project can only use one version of <strong>Scriptom</strong> at a time. If you have installed <strong>Groovy</strong> using the <strong>Groovy Windows Installer</strong>, you must remove any versions of <strong>Scriptom</strong> <strong>JAR</strong> files or replace them with the latest version. A version of <strong>Scriptom</strong> is installed as part of the <strong>Groovy Windows Installer</strong> installation.</p></td></tr></table><p><strong>Scriptom 1.5</strong> is not supported for <strong>Groovy 1.0</strong> and earlier (<strong>Scriptom 1.2</strong> is still available). </p></li></ol><h1>Building from Source</h1><p>The project source is managed by <strong>Subversion</strong>. The projects are already set up to work with <strong>Eclipse</strong>, but it isn't hard to get them working with other IDEs, and you can get by with Notepad. The project trunk is located at <a href="http://svn.codehaus.org/groovy/modules/scriptom/trunk">http://svn.codehaus.org/groovy/modules/scriptom/trunk</a>. This is a <strong>Maven</strong> build. Because the tests are dependent on <strong>Windows</strong> technologies, there are some rather strange software requirements:</p><ul><li><strong>Windows XP</strong> or later.</li><li><strong>Visual C# Express 2008</strong> or <strong>Visual Studio 2008</strong></li><li><strong>Java 1.5.x</strong> or later. <strong>Java 1.6.x</strong> recommended.</li><li><strong>Maven 2.0.9</strong> or better.</li><li>A <strong>Subversion</strong>client. I recommend you get one or both of:<ul><li><strong>Tortoise</strong></li><li><strong>SlikSVN</strong></li></ul></li></ul><p>To build, use the following command line:</p><table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>C:\work\groovy\modules\scriptom\trunk>mvn clean install </pre></td></tr></table><p>The latest build requires <strong>Groovy 1.5</strong> or better.</p><p><strong>Scriptom</strong> includes source files and compiled DLLs (Windows libraries compiled from C++) from <strong>Jacob</strong> version <strong>1.14</strong>. You don't need to download sources and binaries from the <strong>Jacob</strong> project on <strong>SourceForge.net</strong>, though you can do so if you need to build the entire project yourself.</p><p>To build the project on Windows, run <strong><em>project</em></strong><strong>/build/make.bat</strong>. Since <strong>Scriptom</strong> is a Windows-specific module, there isn't a shell script for building on other operating systems.</p><p>The build process requires <strong>Java 1.5</strong> or higher (<strong>Java 1.6</strong> recommended) and <strong>ANT 1.6.5</strong> or better.</p><h1>Changes from Scriptom 1.2</h1><p><strong>Scriptom</strong> <strong>1.5</strong> is a substantial upgrade to previous versions of <strong>Scriptom</strong>, and <em>is not backward compatible</em>. We hope you will agree that it is worth a little code rework to get all these great new features! <strong>Scriptom 1.2</strong> is the version that is documented in <em>Groovy in Action</em>.</p><ul><li>Provides simplified helper methods for dealing with COM apartment threading models.</li><li><strong>ActiveXProxy</strong> name changed to <strong>ActiveXObject</strong> to match WSH convention.</li><li><strong>VariantProxy</strong> no longer exists (the functionality was refactored into <strong>ActiveXObject</strong>).</li><li>Variant values are converted to and from the equivalent Java type; no more calling <strong>.value</strong> on everything!</li><li>Supports COM event callbacks using closures (this is still a work in progress, but usable as is).</li><li>Supports indexed properties, including multiple indexes.</li><li>Supports typed, multi-dimensional SafeArrays.</li><li>Supports pass-byref (in/out) values, both in method calls and event handler callbacks.</li><li>Supports COM enumerable types (so you can use <strong>.each</strong>, for example).</li><li>Supports missing arguments (for optional parameters) in method/property calls and events.</li><li>Includes constant definitions for several popular Windows applications, derived from these type libraries (see JavaDoc):<ul><li>Microsoft Office 2003 (works with other versions as well)<ul><li>Word 2003</li><li>Excel 2003</li><li>Outlook 2003</li><li>Access 2003</li><li>PowerPoint 2003</li></ul></li><li>Microsoft Internet Explorer 6 (works with other versions as well)</li><li>Microsoft Scripting (i.e., FileSystemObject)</li><li>Microsoft Speech API</li><li>Windows Scripting Host (WSH)</li><li>WbemScripting (WMI - Windows Management Instrumentation)</li></ul></li><li>Supports the latest features from <strong>Jacob 1.14</strong>, including new support for the <strong>Decimal</strong> data type and 64-bit integers.</li></ul><h1>Migrating from Previous Versions of Scriptom</h1><p><strong>Scriptom 1.5</strong> is not backward compatible with previous versions of <strong>Scriptom</strong>. To get your scripts running again, do this:</p><ul><li>Change all references to <strong>ActiveXProxy</strong> into <strong>ActiveXObject</strong>.</li><li>Wrap any code that references an <strong>ActiveXObject</strong> in <strong>Scriptom.inApartment { ... }</strong>, which replaces the way Scriptom previously handled COM threading. </li><li>Remove all references to <strong>.value</strong> property references. </li><li>Remove any statically typed references to <strong>VariantProxy</strong>.</li><li>Support for COM events is greatly improved in this version - and also greatly changed. Refer to the <strong>Events</strong> section below for more information.</li></ul><h1>Quick Start</h1><p>Let's say you want an application that talks. Pure Java implementations aside (this is, after all, a Groovy/COM tutorial), and ignoring the fact that the default voice on pre-Vista machines sounds like <a href="http://en.wikipedia.org/wiki/Dr._Zoidberg">Dr. Zoidberg</a> with a sinus infection, you could use the <strong>Microsoft Speech API</strong> (<strong>SAPI</strong>) to get the job done.</p><p>You start by creating an <strong>ActiveXObject</strong> with the prog-id for <strong>SpVoice</strong>. Now you can call any of the methods it supports. By default, <strong>SpVoice</strong> will block until it is done speaking, but we're also going to have it speak asynchronously and wait until it is done.</p><table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>import org.codehaus.groovy.scriptom.* import static org.codehaus.groovy.scriptom.tlb.sapi.SpeechVoiceSpeakFlags.* import static org.codehaus.groovy.scriptom.tlb.sapi.SpeechRunState.* //Definitive proof that you CAN talk and chew gum at the same time. Scriptom.inApartment { def voice = new ActiveXObject('SAPI.SpVoice') //This runs synchronously. voice.speak "Hello, GROOVY world!" //This runs asynchronously. voice.speak "GROOVY and SCRIPT um make com automation simple, fun, and groovy, man!", SVSFlagsAsync while(voice.Status.RunningState != SRSEDone) { println 'Chew gum...' sleep 1000 } } println 'Speaker is done.' </pre></td></tr></table><p>If you have scripted COM before, you are probably used to using "magic numbers" throughout your code in place of COM constants. In this code sample, we're using fully-qualified constants instead.</p><p><strong>Scriptom</strong> includes fully JavaDoc'd constant and interface definitions from a number of commonly used type-libraries, and you can even create your own. The source code for generating COM type library definitions for <strong>Groovy</strong> is written in <strong>Groovy</strong><img class="emoticon emoticon-smile" data-emoticon-name="smile" border="0" src="/s/en_GB/3278/15/_/images/icons/emoticons/smile.png" alt="(smile)" title="(smile)" /> , and it's included in the project. It may not seem like a big deal to replace a couple of numbers, but it will be a lot easier in 10 years to find relevant information on <strong>SpeechVoiceSpeakFlags.SVSFlagsAsync</strong> than on the number <strong>1</strong> (Google returns a little more than 9 billion hits for the number '1', and about 1,000 for 'SpeechVoiceSpeakFlags.SVSFlagsAsync,' including hits on this paragraph). And besides, the code reads better.</p><p>Speaking of interfaces, it turns out that <strong>SpVoice</strong> supports several. You can test an <strong>ActiveXObject</strong> to see if it supports a given interface using <strong>.supportsInterface</strong>, and you can cast an <strong>ActiveXObject</strong> to a given interface using <strong>.toInterface</strong>. </p><p>This next example displays the COM interfaces that <strong>SpVoice</strong> supports (within the <strong>SAPI</strong> library only):</p><table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>import org.codehaus.groovy.scriptom.*; import org.codehaus.groovy.scriptom.tlb.sapi.SpeechLib; Scriptom.inApartment { def voice = new ActiveXObject('SAPI.SpVoice') SpeechLib.interfaces.each {name, iid -> if(voice.supportsInterface(iid)) println "SpeechLib.$name - $iid"} } </pre></td></tr></table><h1>Programmer's Guide </h1><table class="confluenceTable"><tbody><tr><td class="confluenceTd"><p><a class="confluence-link" href="/display/GROOVY/The+Least+You+Need+to+Know+about+COM" data-linked-resource-id="24576229" data-linked-resource-type="page" data-linked-resource-default-alias="The Least You Need to Know about COM" data-base-url="http://docs.codehaus.org">The Least You Need to Know about COM</a></p></td><td class="confluenceTd"><img class="editor-inline-macro" src="/plugins/servlet/confluence/placeholder/macro?definition=e2V4Y2VycHQtaW5jbHVkZTpUaGUgTGVhc3QgWW91IE5lZWQgdG8gS25vdyBhYm91dCBDT018bm9wYW5lbD10cnVlfQ&locale=en_GB&version=2" data-macro-name="excerpt-include" data-macro-parameters="nopanel=true" data-macro-default-parameter="The Least You Need to Know about COM"></td></tr><tr><td class="confluenceTd"><p><a class="confluence-link" href="/display/GROOVY/COM+Data+Types+in+Scriptom" data-linked-resource-id="24576234" data-linked-resource-type="page" data-linked-resource-default-alias="COM Data Types in Scriptom" data-base-url="http://docs.codehaus.org">COM Data Types in Scriptom</a></p></td><td class="confluenceTd"><img class="editor-inline-macro" src="/plugins/servlet/confluence/placeholder/macro?definition=e2V4Y2VycHQtaW5jbHVkZTpDT00gRGF0YSBUeXBlcyBpbiBTY3JpcHRvbXxub3BhbmVsPXRydWV9&locale=en_GB&version=2" data-macro-name="excerpt-include" data-macro-parameters="nopanel=true" data-macro-default-parameter="COM Data Types in Scriptom"></td></tr><tr><td class="confluenceTd"><p><a class="confluence-link" href="/display/GROOVY/COM+Methods+and+Properties+in+Scriptom" data-linked-resource-id="24576238" data-linked-resource-type="page" data-linked-resource-default-alias="COM Methods and Properties in Scriptom" data-base-url="http://docs.codehaus.org">COM Methods and Properties in Scriptom</a></p></td><td class="confluenceTd"><img class="editor-inline-macro" src="/plugins/servlet/confluence/placeholder/macro?definition=e2V4Y2VycHQtaW5jbHVkZTpDT00gTWV0aG9kcyBhbmQgUHJvcGVydGllcyBpbiBTY3JpcHRvbXxub3BhbmVsPXRydWV9&locale=en_GB&version=2" data-macro-name="excerpt-include" data-macro-parameters="nopanel=true" data-macro-default-parameter="COM Methods and Properties in Scriptom"></td></tr><tr><td class="confluenceTd"><p><a class="confluence-link" href="/pages/viewpage.action?pageId=27328519" data-linked-resource-id="27328519" data-linked-resource-type="page" data-linked-resource-default-alias="Passing Values by Reference (in-out)" data-base-url="http://docs.codehaus.org">Passing Values by Reference (in-out)</a></p></td><td class="confluenceTd"><img class="editor-inline-macro" src="/plugins/servlet/confluence/placeholder/macro?definition=e2V4Y2VycHQtaW5jbHVkZTpQYXNzaW5nIFZhbHVlcyBieSBSZWZlcmVuY2UgKGluLW91dCl8bm9wYW5lbD10cnVlfQ&locale=en_GB&version=2" data-macro-name="excerpt-include" data-macro-parameters="nopanel=true" data-macro-default-parameter="Passing Values by Reference (in-out)"></td></tr><tr><td class="confluenceTd"><p><a class="confluence-link" href="/display/GROOVY/COM+Events" data-linked-resource-id="27328520" data-linked-resource-type="page" data-linked-resource-default-alias="COM Events" data-base-url="http://docs.codehaus.org">COM Events</a></p></td><td class="confluenceTd"><img class="editor-inline-macro" src="/plugins/servlet/confluence/placeholder/macro?definition=e2V4Y2VycHQtaW5jbHVkZTpDT00gRXZlbnRzfG5vcGFuZWw9dHJ1ZX0&locale=en_GB&version=2" data-macro-name="excerpt-include" data-macro-parameters="nopanel=true" data-macro-default-parameter="COM Events"></td></tr><tr><td class="confluenceTd"><p><a class="confluence-link" href="/display/GROOVY/All+About+Arrays" data-linked-resource-id="27983890" data-linked-resource-type="page" data-linked-resource-default-alias="All About Arrays" data-base-url="http://docs.codehaus.org">All About Arrays</a></p></td><td class="confluenceTd"><img class="editor-inline-macro" src="/plugins/servlet/confluence/placeholder/macro?definition=e2V4Y2VycHQtaW5jbHVkZTpBbGwgQWJvdXQgQXJyYXlzfG5vcGFuZWw9dHJ1ZX0&locale=en_GB&version=2" data-macro-name="excerpt-include" data-macro-parameters="nopanel=true" data-macro-default-parameter="All About Arrays"></td></tr></tbody></table><h1>Examples</h1><p>Here is a simple example that uses the Microsoft <strong>ScriptControl</strong> to evaluate a JScript expression. This is a very indirect way to add 2 and 2.</p><table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>import org.codehaus.groovy.scriptom.* Scriptom.inApartment { def scriptControl = new ActiveXObject("ScriptControl") scriptControl.Language = "JScript" println scriptControl.Eval('2.0 + 2.0;') } </pre></td></tr></table><p>There are many, many potential uses for <strong>Scriptom</strong> - far to many to try to maintain as part of this documentation. So we've included a whole slew of meaty examples in the project archive for you to play with. We'd like to encourage you to go look at those examples, run them, and modify them. And if you come up with an especially interesting example, let us know about it. We may even include it in a future release! </p><p>Some additional examples included with <strong>Scriptom</strong>:</p><ul><li>Automated writing to and reading from <strong>Excel</strong> spreadsheets. Includes COM events example.</li><li>Navigation in <strong>Internet Explorer</strong>. Includes COM events example. </li><li>Gathering information about processes and Windows NT services using <strong>WMI</strong>.</li><li>Parsing a <strong>*.msg</strong> file with <strong>Microsoft Outlook</strong>.</li></ul><p>Consuming <strong>Visual Basic 6</strong> (VB6) and <strong>Visual Basic.NET</strong> COM-enabled DLLs.</p><h1>Articles</h1><p><img class="editor-inline-macro" src="/plugins/servlet/confluence/placeholder/macro?definition=e2luY2x1ZGU6U2NyaXB0b20gQXJ0aWNsZXN9&locale=en_GB&version=2" data-macro-name="include" data-macro-default-parameter="Scriptom Articles"></p><h1>Post Scriptom</h1><p>All known (unresolved) issues and feature requests are listed in the <a href="http://jira.codehaus.org/secure/IssueNavigator.jspa?reset=true&mode=hide&pid=10242&sorter/order=DESC&sorter/field=priority&resolution=-1&component=11335">Scriptom Jira</a> database.</p><p>Changes to each build are summarized in the <a class="confluence-link" href="/display/GROOVY/Change+Log" data-linked-resource-id="27983882" data-linked-resource-type="page" data-linked-resource-default-alias="Change Log" data-base-url="http://docs.codehaus.org">Change Log</a>.</p><p>Recent builds of <strong>Scriptom</strong> can be found <a href="http://docs.codehaus.org/pages/viewpageattachments.action?pageId=24576222">here</a>. Older versions are archived:</p><p><img class="editor-inline-macro" src="/plugins/servlet/confluence/placeholder/macro?definition=e2luY2x1ZGU6U2NyaXB0b20gQXJjaGl2ZX0&locale=en_GB&version=2" data-macro-name="include" data-macro-default-parameter="Scriptom Archive"></p><h1>Progids</h1><p><strong>Scriptom</strong> uses late binding. Visual Basic and VBA uses early binding by default, but they also support late binding (with <strong>CreateObject</strong>). If you are translating working Visual Basic code and if your <strong>Scriptom</strong> code fails at the point where you've got your call</p><table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> ActiveXObject oSDO = new ActiveXObject("SageDataObject140.SDOEngine") </pre></td></tr></table><p> (or whatever your object is) with an error message</p><table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>Caught: org.codehaus.groovy.scriptom.ActiveXObject$CreationException: Could not create ActiveX object: 'SageDataObject140.SDOEngine'; Can't get object clsid from progid </pre></td></tr></table><p> then the chances are the progid "Sage...." that you are using is the wrong one.</p><p>So you need to go and look in the registry to find what it might be. One way to do this is with Microsoft's new Powershell cmd utility which you can download from the ms web site. Install this and run the command line</p><table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>dir REGISTRY::HKEY_CLASSES_ROOT\CLSID -include PROGID -recurse | foreach {$_.GetValue("")} </pre></td></tr></table><p>It will produce a ream of different progids which you can sort and search for one that looks a likely candidate. In my case it was SDOEngine.14</p><p>Alternatively if you have used the scriptom utility ExtractTlbInfo.groovy to generate name maps for the com object you could read the source code for the (in my case SageDateObject140.java) class and you might find some code and/or comment like this:</p><table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>/** * A {@code Map} of CoClass names to prog-ids for this type library.<p> * * Note that some objects that support events do not publish a prog-id. * This is a known limitation of this library that we hope to resolve in * a future release.<p> * * Supported prog-ids: * <ul> * <li><b>SDOEngine</b> = SDOEngine.14</li> * </ul> */ public final static Map progIds; static { TreeMap v = new TreeMap(); v.put("SDOEngine", "SDOEngine.14"); progIds = Collections.synchronizedMap(Collections.unmodifiableMap(v)); } </pre></td></tr></table><p>Additionally, you can use the <em>Object Browser</em> included with Visual Basic (I recommend the one with VBA) to figure out possible progids and then search the registry. This is a good way to associate interfaces (and their methods) with a particular progid. If there are <em>VBScript</em> or <em>JScript</em> examples available, they will include the correct progids, since these languages are always late-bound.</p><p>If all else fails, hit the Groovy mailing lists. There are lots of people out there with COM experience who can point you in the right direction.</p>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced