Tag Archives: Methods

The LOG_EVENT method

In an earlier post we took a very brief look at some of the new properties of the SYSTEM object, and this time we thought we’d take a closer look at one of it’s new methods called LOG_EVENT.

Simply put the LOG_EVENT method allows you to write a message to the Windows Event Log without the need for you to prototype and use any Windows API functions yourself. It’s very easy to use and takes three arguments:

1) Type Info: This is a dynamic array comprised of the following fields:

   <1> Message Type (Required) : "ERROR", "WARNING" or "INFO".
   <2> Event ID     (Optional) : Integer denoting the event. Defaults to 1.
   <3> Category ID  (Optional) : Integer identifying the category. Defaults to 0.

2) Source Info: This is a dynamic array comprised of the following fields:

   <1> Event Source (Required) : Name of the Event Source (See below).
   <2> Server Name (Optional)  : UNC Name of the system to post the message to.
                                 Defaults to the local workstation.

3) Message Text: This is simply the text of the message to post to the Event Log.

Example: Post an error message to the Event Log from the “RevPS” Event Source:

   x = exec_Method( "SYSTEM", "LOG_EVENT", "ERROR", "RevPS", "FOOBAR!!!!" )

The Event Source name

So far, so good. However if you simply execute the above code you will see the message you posted in the Application Event Log, but you’ll also see that Windows has prefixed your message with some of it’s own text which refers to a missing Event ID description like so:

The reason for this is that Windows expects to find a “registered Event Source” containing the description for the Event ID that you specified.  A registered Event Source is actually a DLL containing a set of strings, each of which corresponds to an Event ID.  Without this DLL you get the warning text you see above which doesn’t look very professional and gives the impression that something is missing from your application.

For OpenInsight v10 we have provided a generic DLL called RevEventMsg.dll that you can register on your system under your desired Event Source name  – if you then use that name in your  call to the LOG_EVENT method you will see your message without any of the warning text prefixed to it.

Registering the DLL is quite simple: you need to create a new key with the name of your Event Source (We used the string “RevPS” for this example) under this path:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application\

… and set a couple of values like so (this can be automated easily via a .reg file):

Now if you call the LOG_EVENT method your Event Log entry will look like this:

Much better.

If you are interested in reading further on the subject of the Windows Event Log you can find full documentation on Microsoft’s MSDN website here,

[Edit: 24 Apr 13 – Call_Method renamed to Exec_Method]

(Disclaimer: This article is based on preliminary information and may be subject to change in the final release version of OpenInsight 10).

The new FILESYSTEM object

As we mentioned earlier the decision was taken to deprecate the Utility function, but we still needed to provide the equivalent functionality by some other means. The obvious candidate to update here was the existing SYSTEM object, but rather than overloading it with a whole raft of new members, all of which were filing-system related, we took the decision to create a new object instead, and thus the FILESYSTEM object was born.

The FILESYSTEM object, like the SYSTEM one, is managed internally by the Presentation Server and simply exposes some common Windows Shell directory and file-based functionality to Basic+. As you’ll see below there are some new properties and methods that were not part of the old Utility function, but we’ve also taken the opportunity to enhance some of the existing methods as well – they now hook into the Windows API SHFileOperation function thereby offering better system integration, such as using standard Windows copy/move dialogs and exposing “Undo” functionality.

Here’s a summary of the FILESYSTEM object interface that you’ll find in the new version:

Properties

Property Dev Run Get Set Description
CURRENTDIR X X X Provides access to the current working directory.
DRIVELIST X X Returns a dynamic array of attached drive letters.
FILEOPRESULT X X Returns the most recent result code from a FILESYSTEM object method call.
SYSTEMDIR X X Returns the OS System directory.
TEMPDIR X X Returns the user’s Temp directory.
WINDOWSDIR X X Returns the Windows directory.

Methods

Method Description
COPYDIR Copies an entire directory and sub-directories to a new location.
COPYFILES Copies one or more files to a new location.
DELETEFILES Deletes one or more files.
DIREXISTS Checks to see if a directory exists.
FILEEXISTS Checks to see if a file exists.
GETABSOLUTEPATH Returns an absolute path from a relative path
GETLONGPATH Converts a short path to its long path form
GETRELATIVEPATH Returns a relative path from an absolute path
GETSHORTPATH Converts a long path to its short path (i.e. MS-DOS “8.3”) form
GETSPECIALDIR Returns the path to a “special” OS folder such as “My Documents”, AppData and so on.
MAKEDIR Creates a directory or nested directory path.
MOVEDIR Moves an entire directory and sub-directories to a new location.
MOVEFILES Moves one or more files to a new location.
REMOVEDIR Removes a directory.
RENAMEDIR Renames a directory.
RENAMEFILE Renames a file.

Of course this is probably not a final list, so please feel free to leave us a comment if you think of anything that would make a good addition here.