mScriptBox Tutorials
Introduction into COM Objects

Written by Hammer
Published with permission.

Table Of Contents

  1. Object Concepts
  2. $com() Syntax
  3. $com() Properties
  4. Show Me How It Works
  5. SendKeys Example
  6. Spell Checking Example
  7. Folder Size Example
  8. Starting/Timing Notepad Maximized
  9. Useful COM Objects
  10. Collection of COM Identifiers
  11. Conclusion

1. Object Concepts  Back to Top

COM stands for Component Object Model. The most important word for you to understand is "object." Object-Oriented Programming (OOP) has been around for a long time now. This tutorial is not designed to cover what IS and what IS NOT a COM object. It won't even really cover where to find all the COM objects available on your system, but it will give you somewhere to start learning on your own.

First, you must understand what an object is and what it can do. An object can be anything that has been modeled in some sort of a programming language by a knowledgeable programmer, but for the sake if an introduction to them, let's first consider just a normal, real-world object: a car. We'll just assume (for now) that some very clever programmer has coded one into a computer.

By examining our car closely, we can discover many pieces of information, or data, about what it is, how it is currently set to operate and possibly some limitations it inherently possesses. It is candy-apple red, it is a Ferrari Testarossa (since it's our car, we might as well think big), it has a 12-cyclinder engine, it currently has its lights and engine turned off, and it can go 175mph if we could find someplace to drive it that fast, safely and legally. These are some of the properties our car we can discover by examination.

Our car can perform many different kinds of actions, like starting and stopping the engine. It can engage, change and disengage the gears in the transmission to modify how the engine affects the speed of the car. It can turn its lights on and off. Each of these functions has some method of making the car do what we want it to, some sort of user interface. In a real car, these would be done by using car keys, buttons, pedals, switches and the like by whoever is controlling the car.

There are also ways to group some of the car's attributes together. For example, below the steering column of the car, there will usually be found a collection of three pedals: the clutch, the brake and the accelerator. Elsewhere in the car, we have a small collection of seats, one on each side of the car, but essentially the same otherwise. We also have a complete collection of gauges located in the dashboard, each of which tells us something important about the way the car is functioning.

These three groups make up the three most important things about objects you need to understand: properties, methods and collections. Properties are what you can find out about your object, methods are how you change how it operates and collections hold groups of similar sub-objects. In normal object notation (which you will see used in all documentation about the objects you want to use), you will see the object name, followed by a period (full stop, or dot), followed by a property name, a method name and possibly its parameters, or even a collection associated with that object.

Our very clever programmer has given us a Vehicle class that includes cars, trucks, boats, planes, trains, and just about every other kind of vehicle imaginable, and has installed it on our system. We can create an instance of that car and assign it the properties we want. Sometimes, the programmer will allow you to set the values directly into the property; sometimes, there is a method to do so. In either case, you won't always be able to tell the difference.

Here is a VBScript example of how you might see an object used in some of the documentation you will run across. Following the VBScript example, we'll translate it from VBScript into mIRC script (minus all the normal error checking that you would do).


   ' Create the car object.
   Set car = Server.CreateObject("Vehicle.Car")

   ' Assign values to some of the car object's properties.
   car.Color = "red"
   car.Make = "Ferrari"
   car.Model = "Testarossa"
   car.Cylinders = 12
   car.TopSpeed = 175

   ' Use some of the car object's methods.

   car.StartEngine           ' Start the engine!
   car.DepressGasPedal(0.25) ' Depress the gas pedal 1/4 of the way to the floor
   car.EngageClutch(True)    ' Engage the clutch pedal
   car.Lights(1)             ' Parking lights
   car.Lights(2)             ' Normal beam
   car.Lights(3)             ' High beam
   car.Lights(0)             ' Turn light off
   car.EngageClutch(False)   ' Release the clutch pedal
   car.DepressGasPedal(0.0)  ' Release the gas pedal
   car.StopEngine            ' Stop the engine

   ' We're done with it for now, so release the memory used to create the car.
   Set car = Nothing

That should be fairly straightforward and easy to understand. Now let's do exactly the same thing, except we'll use mIRC script, instead of VBScript.
Note: "!.echo -q" (see below) is a null command, which means "do nothing with the information returned"; it is a very handy concept.
Don't worry about what all the parameters mean for now, just try to grasp what you can. Each of the parameters will be covered later.


  ; Create the car object.
   comopen car Vehicle.Car

   ; Assign values to some of the car object's properties.
   !.echo -q $com(car, Color, 4, bstr, red)
   !.echo -q $com(car, Make, 4, bstr, Ferrari)
   !.echo -q $com(car, Model, 4, bstr, Testarossa)
   !.echo -q $com(car, Cylinders, 4, int, 12)
   !.echo -q $com(car, TopSpeed, 4, int, 175)

   ; Use some of the car object's methods.
   !.echo -q $com(car, StartEngine, 1)
   !.echo -q $com(car, DepressGasPedal, 1, r4, 0.25)
   !.echo -q $com(car, EngageClutch, 1, bool, True)
   !.echo -q $com(car, Lights, 1, int, 1)
   !.echo -q $com(car, Lights, 1, int, 2)
   !.echo -q $com(car, Lights, 1, int, 3)
   !.echo -q $com(car, Lights, 1, int, 0)
   !.echo -q $com(car, EngageClutch, 1, bool, False)
   !.echo -q $com(car, DepressGasPedal, 1, r4, 0.0)
   !.echo -q $com(car, StopEngine, 1)

   ; We're done with it for now, so release the memory used to create the car.
   comclose car

For the programmers already familiar with objects, this little example alone should be enough to give you a very good start on how to go about translating the examples you read on web pages or in books from VBScript examples into mIRC script.


2. $com() Syntax  Back to Top

Syntax: $com(Name,Member,Method,Type1,Value1,...,TypeN,ValueN)

Parameter Description
Name The first parameter of $com() is the name of your object you comopened.
Member This second parameter names the method (or property) that we want to work with.
Method The third parameter is the kind of action you're requesting from the object. These are defined as follows:
1 (Method) as the second parameter means that you are invoking an object method named in the third parameter, actually asking the object to do something on your behalf.
2 (PropertyGet) means that you are asking for the current state of an object's parameter named in the third parameter.
4 (PropertyPut) means that you are trying to set a value into the object's parameter named in the third parameter.
8 (PropertyPutRef) means that you are assigning a value by reference, not by value. This is how you would set a parameter that requires another object as its value.

These numbers can be added together if necessary. Some objects require that you set a variable's value using both PropertyPut (2) and Method (1), which means you must use 3 as your second parameter. You will find this out when 2 doesn't work and neither does 1.
TypeN or
ValueN
For each parameter you need to give a method or property, you must define what kind of data it is first, followed by the data itself. Normally, parameters only take one piece of data, so there will only be one type/value pair. Methods can take quite a few parameters, and each one must be given in a type/value pair in the same order in which the method expects to receive it.

The data types you can use are the ones most programming languages allow you to use, and are defined as follows:

Data Type Description
i1, i2, i4,
ui1, ui2, ui4, int, uint
Integers are numbers which have no mantissa; that is, no decimal or fraction portion. 1, 0, -15, 255 are all integers. These values can be signed (i1, i2, i4 and int), as in the case of -15, or unsigned (ui1, ui2, ui4 and uint). The number after the i indicates the size of the integer, in bytes, to be used.

i1 is signed char in C. i2 is an Integer in VB and a short in C. i4 is a Long in both VB and C. ui1 is a Byte in both VB and C. ui2, ui4 and uint correspond to ushort, ulong and uint in C.

r4, r8 Real numbers have a mantissa, a decimal or fraction part. 0.25 is an example of a real number. As with the integers, the 4 or 8 after the r indicates the size of the variable in bytes.

r4 is a Single in VB and a float in C, while r8 is a Double in both VB and C.

cy cy is a type of real number data type. This is a precise currency value that has 15 digits to the left of the decimal point and 4 to the right. Its range is 922337203685477.5807 to -922337203685477.5808.

cy is type Currency in both VB and C.

date These are, well, dates! They are used in the format m/d/yyyy.

date is type Date in both VB and C.

decimal Decimal variables are stored as 96-bit (12-byte) unsigned integers scaled by a variable power of 10. The power of 10 scaling factor specifies the number of digits to the right of the decimal point, and ranges from 0 to 28.
bool Boolean values have only one of two possible values: True or False.

bool is of type Boolean in VB and type variant_bool in C.

bstr The basic string, or binary string, just a normal string of characters.

bstr is of type String in VB and bstr in C.

variant Variants are when you must pass a parameter by value and not by reference, and you must also specify one of the other data types of the data you are going to pass. That additional data type cannot, itself, be a variant.

variant is of type Variant in both VB and C.

dispatch IDispatch is a pointer that can be used to create a new COM object, using "dispatch* newname" as the final parameter of your $com() call. It indicates that there is an IDispatch object available which may or may not be a COM object. If the object doesn't get created, it's not a COM object and can't be used directly as one.

dispatch is of type Object in VB and type IDispatch in C.

unknown IUnknown means that there is a pointer to some sort of object available, but what kind is not specified. All you know is that it implements the IUnknown interface.

unknown is of type Object in VB and of type IUnknown in C.

error This is the HResult used to return error information.

error is of type SCODE in C.

Remember, the data type you use must match what the method or parameter you're trying to affect expects to receive, not just whatever you feel you should pass in. Some smaller data types can be passed into larger data types without problems, but the reverse is not always true. Trying to pass in an extremely large integer value into a method that is expecting an i1 will, at the very least, cause data loss and will occasionally cause the method to fail entirely. It's up to you to figure out what that method expects to receive and give it the smallest data type that will work.


3. $com() Properties  Back to Top

NOTE: $com( ) itself returns only 1 for a successful call to $com, or 0 if it was unsuccessful.

There are only a few $com(name).properties available, but most of them are very useful. They are: .progid, .dispatch, .unknown, .result, .error, .errortext and .argerr.

Property Description
.progid This is the object named as the second parameter to your comopen command. /comopen wsh WScript.Shell
.dispatch This returns either $true or $false. If it is $true, then there is an IDispatch pointer available that you might be able to use to create another COM object.
.unknown Like .dispatch, this returns either $true or $false. If it returns $true, then there is an IUnknown pointer available.
.result If your call is supposed to return a value, this is where it will be. When you try to PropertyGet a property's value, this is how you'll retrieve the information you are seeking.
.error If there was an error, this is the error number.
.errortext If there was an error, this is the text of the error message in human-readable(?) form.
.argerr If there was an error, this is the number of the parameter which caused the error.


4. Show Me How It Works  Back to Top

In the following sections, we're just going to pick a couple of simple tasks and code them in mIRC script. In the comments for each command, I'll show how the command might look in VBScript. For simplicity, the first two just use the SendKeys method of the WScript.Shell object. So, first, we need to know a little bit about the SendKeys method.


5. SendKeys Example  Back to Top

Sends one or more keystrokes to the active window (as if typed on the keyboard).
object.SendKeys(string)

Arguments
    object
        WshShell object.

    string
        String value indicating the keystroke(s) you want to send.

Remarks
  Key              Argument 
  Shift            + 
  Ctrl             ^ 
  Alt              % 
  Caps Lock        {CAPSLOCK} 
  Left Arrow       {LEFT} 
  Right Arrow      {RIGHT} 
  Up Arrow         {UP} 
  Down Arrow       {DOWN} 
  Enter or Return  {ENTER} 
  Home             {HOME} 
  End              {END} 
First, let's do something simple: turn the Caps Lock key on and off through an alias.
alias ToggleCapsLock {

   ;   Set Caps = Server.CreateObject("WScript.Shell")
   .comopen Caps WScript.Shell

   ;   Caps.SendKeys("{CAPSLOCK}")
   !.echo -q $com(Caps, SendKeys, 3, bstr, {CAPSLOCK})

   ;   Set Caps = Nothing
   .comclose Caps
} 

In this next example, we'll do something slightly more complex. First, we'll open the File Options (Alt+O). Since we can't know the state of the options tree on the left, the first thing we will do is close the tree down completely, then open it completely (both for the practice and to get it into a known state). Then it is a simple matter to use the arrow keys to get to the option page we want to change something on and then use either Tab to get to the option we want, or use the Alt-letter shortcut to jump straight to it.

alias Toggle.Multi-Line.Editboxes {

   ;   Set MLEs = Server.CreateObject("WScript.Shell")
   .comopen MLEs WScript.Shell

   ;   MLEs.SendKeys("%O{END}")
   !.echo -q $com(MLEs, SendKeys, 3, bstr, % $+ O{END})

   ;   Send 14 Left arrows to close everything down.
   !.echo -q $com(MLEs, SendKeys, 3, bstr, {LEFT 14})

   ;   Send 34 Right arrows to open everything up.
   !.echo -q $com(MLEs, SendKeys, 3, bstr, {RIGHT 34})

   ;   Since we're at the bottom, Send 2 Up Arrows to get to the Display/Options page.
   !.echo -q $com(MLEs, SendKeys, 3, bstr, {UP 2})

   ;   3 Tabs will get us into the Multi-line editboxes checkbox.
   !.echo -q $com(MLEs, SendKeys, 3, bstr, {TAB 3})

   ;   Press the spacebar to toggle it.
   !.echo -q $com(MLEs, SendKeys, 3, bstr, $chr(32))

   ;   Click the OK button to Save and Close Options.
   !.echo -q $com(MLEs, SendKeys, 3, bstr, {ENTER})

   ;   Set MLEs = Nothing
   .comclose MLEs
} 
Had I wanted to, I could have sent the whole thing in one string, like this:

$com(MLEs, SendKeys, 3, bstr, % $+ o{END}{LEFT 14}{RIGHT 34}{UP 2}{TAB 3} {ENTER})

You could write yourself a Setup script to automatically make all the settings changes you wish to always set up for your mIRC when you install it into a new directory. To do that, you would definitely want to use the keyboard shortcuts for each of the controls you wish to modify; tabbing is a bad idea because the order of the controls might change between versions. Indeed, Khaled frequently adds new controls for us to play with, so skip using the multiple-tab idea for any such script. I used it here simply as an example.


6. Spell Checking Example  Back to Top

This next example uses a different object than we've yet used. Microsoft Word allows us access to its CheckSpelling method. If you are actually going to use something like this frequently in mIRC, then do not keep opening and closing the Word.Application object. Startup for it is slow. Better to put the comopen for it in an on START event, then leave it open the entire time you're in mIRC, closing it in an on EXIT event. This, however, will be a very simple example of how to spell check a sentence. Comments have been omitted since this is quite simple, once you see how it is done.

The Word.Application methods are: CheckSpelling, Help, Move, Resize, Quit and SendFax.

CheckSpelling

Checks a string for spelling errors. Returns True if errors are found, False if no errors. It does not display the errors or enable you to correct them.
(Note: mIRC translates these backwards: $true if no errors, $false if there are.)
alias SpellCheck {

   IF (!$1) { RETURN }

   .comopen Word Word.Application

   !.echo -q $com(Word, CheckSpelling, 1, bstr, $1-)

   IF ($com(Word).result) 
   { 
   	 echo -abflirtc info2 * No spelling errors found! Good job.
   }

   ELSE { echo -abflirtc ctcp * Spelling errors found!! Break out the dictionary. }

   !.echo -q $com(Word, Quit, 1)

   .comclose Word
}

Incidentally, you can accomplish the same thing using Excel.Application and the CheckSpelling method. Its methods are: Calculate, CheckSpelling, Evaluate, MailSystem (MailSession, MailLogoff, MailLogon, SendMail), Quit and Undo.


7. Folder Size Example  Back to Top

Let's do something with yet another object: the Scripting.FileSystemObject (found in scrrun.dll). The quickest way to discover how large a folder and all of its subfolders is would be to simply check the Folder.Size property. This will be a grand way to discover how to use dispatch* to create new COM objects as they are needed, too.

alias GetFolderSize {

   ;   If there is no supplied folder, don't even try. Use $nofile( ) to strip off any accidentally supplied filename.
   IF (!$nofile($1)) { return }

   ;  Open the FileSystemObject object to be able to use it's GetFolder method.
   .comopen FSO Scripting.FileSystemObject

   ;   Get the folder specified, creating a Folder object in the process.
   !.echo -q $com(FSO, GetFolder, 3, bstr, $nofile($$1-), dispatch* Folder)

   ;   Now we can use the Folder object we've just created to check its Size property.
   !.echo -q $com(Folder, Size, 2)

   ;   Save the result to return after closing the 2 objects.
   VAR %Size = $com(Folder).result

   ;   Close both objects, we're done with them.
   .comclose Folder
   .comclose FSO

   ;   Return the size parameter without using $bytes(%Size, 3).suf in case the calling script wants to do math on it later.
   RETURN %Size
}


8. Starting/Timing Notepad Maximized  Back to Top

Now let's use a method that has multiple parameters. For this example, we'll use the WScript.Shell object's Run method. For this example, we'll use the bWaitOnReturn to show how long a notepad window, which we will open maximized, was open.

Run Method

Runs a program in a new process.

object.Run(strCommand, [intWindowStyle], [bWaitOnReturn])

Arguments

object
WshShell object.
strCommand
String value indicating the command line you want to run. You must include any parameters you want to pass to the executable file.
intWindowsStyle
Optional. Integer value indicating the appearance of the program's window. Note that not all programs make use of this information.
bWaitOnReturn
Optional. Boolean value indicating whether the script should wait for the program to finish executing before continuing to the next statement in your script. If set to true, script execution halts until the program finishes, and Run returns any error code returned by the program. If set to false (the default), the Run method returns immediately after starting the program, automatically returning 0 (not to be interpreted as an error code).
Remarks

The Run method returns an integer. The Run method starts a program running in a new Windows process. You can have your script wait for the program to finish execution before continuing. This allows you to run scripts and programs synchronously. Environment variables within the argument strCommand are automatically expanded. If a file type has been properly registered to a particular program, calling run on a file of that type executes the program. For example, if Word is installed on your computer system, calling Run on a *.doc file starts Word and loads the document. The following table lists the available settings for intWindowStyle.

intWindowStyle Description
0 Hides the window and activates another window.
1 Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time.
2 Activates the window and displays it as a minimized window.
3 Activates the window and displays it as a maximized window.
4 Displays a window in its most recent size and position. The active window remains active.
5 Activates the window and displays it in its current size and position.
6 Minimizes the specified window and activates the next top-level window in the Z order.
7 Displays the window as a minimized window. The active window remains active.
8 Displays the window in its current state. The active window remains active.
9 Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window.
10 Sets the show-state based on the state of the program that started the application.

Source: MSDN's Run method

alias NotePad {
  
   ;   Set WSH = Server.CreateObject("WScript.Shell")
   .comopen WSH WScript.Shell
  
   ;   Show when the Notepad window opened.
   echo -abflirtc info * /Notepad window opened. $time
  
   ;   WSH.Run("Notepad.exe", 3, True)
   !.echo -q $com(WSH, Run, 1, bstr, Notepad.exe, i1, 3, bool, True)
  
   ;   Show when the Notepad window closed.
   echo -abflirtc info2 * /NotePad window closed. $time
  
   ;   Set WSH = Nothing
   .comclose WSH
}
Note: You can use %EnvronmentVariables% directly in the Run command provided you back the leading % off with $+ so it does not evaluate as a variable.
   $com(WSH, Run, 1, bstr, % $+ comspec% /c ping > output.txt, i1, 0, bool, True)
will work just fine.


9. Useful COM Objects  Back to Top

Here are some of the more useful objects you can use with mIRC scripting. This list is not intended to be in any way complete; it is merely someplace to get started learning $com and is mainly intended as a good place to come look for the links to the documentation for these objects. Learning how to find the information is as important as using it once you find it. While COM objects are incredibly numerous, they are also hard to find and frequently, the documentation for them is somewhat cryptic until you get the hang of working with it.

Any object that has no link is one that mIRC will not be able to /comopen. Also, not all objects are given here, though the root page for their object model has been included. Only objects, methods, properties and collections that I have used or seen used (and not all of those!) are documented here. This is a starting point, not a destination.

Come back often! As new mIRC-scriptable COM are identified as being useful, they will be added here with appropriate references to the documentation you'll need to get started using them.

Windows Scripting Host (WSH)

Windows Scripting Host objects are what you use to do things with your computer's shell (like you saw in the SendKeys and Run examples).

FileSystemObject - ProgID: Scripting.FileSystemObject
     Drive
     File
     Folder

WshShell - ProgID: WScript.Shell
     WshScriptExec
     WshShortcut
     WshUrlShortcut


Local database access through ADO and ADOX

ActiveX Data Objects (ADO) is the object model you use when you want to have your script connect to a local database (such as an .mdb).

ADODB.Connection object
     Methods and Properties
             Open method

ADODB.Recordset object
   Methods and Properties
         Open method
         BOF and EOF properties
         MoveFirst, MoveLast, MoveNext, MovePrevious methods
         RecordCount property
         Collect property

NOTE: The Collect is a hidden property that you can use to retrieve the data inside the fields you have retrieved from the database. It is 0-based, not 1-based, so to get the value in the first field, you use objRecordset.Collect(0); and, you will have to know the order the fields show up in, based on your SQL call or the order in which the fields were created in the table.

ActiveX Extensibility Objects (ADOX) is how you get information about the structure of the database.

Catalog object
    Tables collection
        Table object
             Columns collection
                 Column object
                     Name property
             Properties collection

NOTE: Each of the collections in the ADOX object model can be iterated numerically, such as in a while loop. The ADODB.Recordset.Fields cannot be, since they all require a key for the Item() method. In order to access the fields that way, you would need to get a list of the fields available using ADOX, or know what they are by looking at the structure of the database yourself. Assuming we know the database structure, we can access the fields by name. Like this (in mIRC script):

.comopen objConnection ADODB.Connection
!.echo -q $com(objConnection, Open, 1, *bstr, Provider=Microsoft.JET.OLEDB.4.0;Data Source=C:\mIRC\Test.mdb)

.comopen objRecordset ADODB.Recordset
!.echo -q $com(objRecordset, Open, 1, *bstr, SELECT * FROM TableName WHERE TableID = 1, dispatch, objConnection)

; Drill down to the field we want the data from, object by object.
!.echo -q $com(objRecordset, Fields, 2, dispatch* objFields)
!.echo -q $com(objFields, Item, 2, *bstr, Nickname, dispatch* objNickname)
!.echo -q $com(objNickname, Value, 2)
VAR %Nickname = $com(objNickname).result

WHILE $com(1) { .comclose $ifmatch } 

where the database is C:\mIRC\Test.mdb, the table is TableName, and it has at least two fields: TableID and Nickname.

If you wanted to show what was in all the fields of every record in the table, but didn't know their names to use in the objFields.Item(), you could collect them all from the ADOX catalog and then use them to retrieve each record's data, Item by Item. Note that you must close each objItem after you have used it in order to reuse the same objname again for the next field - or, you can use separately named obj names, as shown in the above example.


10. Collection of COM Identifiers  Back to Top

Thanks to Yochai for submitting and SpyroNet for writing these functions.

$regwrite(Key, Value, Value type)

The Key use these abbreviations:

HKCU -> HKEY_CURRENT_USER
HKLM -> KKEY_LOCAL_MACHINE
HKCR -> HKEY_CLASSES_ROOT
HKEY_USERS and HKEY_CURRENT_CONFIG have no abbreviation
Value type must be:
REG_SZ or REG_EXPAND_SZ for strings
REG_BINARY or REG_DWORD for numeric types
alias regwrite {
  .comopen reg WScript.Shell
  VAR %t = $iif($istok($3,REG_BINARY,REG_DWORD),int,bstr)
  VAR %r = $com(reg,RegWrite,3,bstr,$1,%t,$2,bstr,$3)
  .comclose reg
  RETURN %r
}



$GetEnvStr(String)
Allows you to get environment variables:
eg: $GetEnvStr(WinDir)
Try too: ComSpec, PATH, TMP/TEMP, SYSTEMDRIVE (winnt & 2000) ...
alias GetEnvStr {
  .comopen env WScript.Shell
  VAR %r = $com(env,ExpandEnvironmentStrings,3,bstr,$+(%,$1,%))
  IF (%r) { %r = $com(env).result }
  .comclose env
  RETURN $iif(%r == $+(%,$1,%),$null,%r)
}


$SpecialFolder(String)
The special folders are:
- AllUsersDesktop
- AllUsersStartMenu
- AllUsersPrograms
- AllUsersStartup
- Desktop
- Favorites
- Fonts
- MyDocuments
- NetHood
- PrintHood
- Programs
- Recent
- SendTo
- StartMenu
- Startup
- Templates
Some of these special folders only work on NT,2000,XP
alias SpecialFolder {
  .comopen spe WScript.Shell
  VAR %r = $com(spe,SpecialFolders,3,bstr,$1)
  IF (%r) { %r = $com(spe).result }
  .comclose spe
  RETURN %r
}


$NetInfo(info)
info must be: UserDomain, ComputerName, UserName
Note: UserDomain doesn't work on 98/ME
alias NetInfo {
  .comopen inf WScript.Network
  VAR %r = $com(inf,$1,3)
  IF (%r) { %r = $com(inf).result }
  .comclose inf
  RETURN %r
}


11. Conclusion  Back to Top

The examples we've done here are just the beginning glimpse of the tip of the iceberg in your $com coding experience. However, they should be enough to get you started using whichever object you want to use. There are many, many, many COM objects already on your computer; all you have to do is find them, learn what their properties, methods and collections are, and how they are meant to be used. It helps a great deal to get very familiar with MSDN and how to find what you are looking for there.

MSDN's The Component Object Model is a great place to start looking at COM more thoroughly. MSDN has all the documentation you could ever need (or want .. or possibly even understand or use) on most all of the COM objects you can find on your system.

Windows Scripting Host is a really good way to get your feet wet; the objects are all fairly simple to use.


This document was written by Hammer

If you have any questions regarding this document, you can always email me. I hope that you have learned a little bit from this. Thank you for reading.

Send comments to: mScriptBox Team

Copyright ©2005 by Merlin. - All rights reserved.