Skip to main content

NightWatchman Enterprise 7.3

Write power-off scripts

Setting the script running order

In the scripting reference , we discussed the process you should go through to develop a NightWatchman power-off script. This section describes the mechanics of NightWatchman scripts and how these can be put together to implement a new power-off script.

The functionality of the NightWatchman service can be extended by creating additional power-off scripts. Administrators can write Windows scripts in VBScript to handle the intelligent shutdown of applications so that no data is lost when performing a user log-off.

During power-off, the scripts will attempt to save current versions of all open and edited files. Any open dialogs in the currently running applications are also handled in order to execute the closure of the application in a safe way. At next log-on, the user will be notified that backups have been made and given the option of accepting or rejecting these.

To run correctly, scripts must be saved in the NightWatchman scripts directory, immediately below the NightWatchman installation directory:

C:\Program Files\1E\NightWatchman\Scripts

If all the scripts are present in the root of the NightWatchman script directory, they will be run in an arbitrary order. You can control the order in which the scripts can be run, by creating specifically named subfolders in this directory and placing scripts in the sub directories.

NightWatchman supports ten sub directories named Sub0 up to Sub9. The scripts in Sub0 are run first then the ones in Sub1 and so on up to Sub9. After the scripts in the sub directories have been run, NightWatchman will then run any scripts in the main scripts directory.

Writing NightWatchman scripts

NightWatchman comes with pre-defined scripts that handle the following products: Microsoft Outlook, Microsoft Word, Microsoft PowerPoint, Microsoft Excel and Notepad. To handle other applications you can either contact 1E or write your own scripts – see Windows NightWatchman API.

How the script phase works

The power-off script phase of the NightWatchman system contains the following steps:

  • NightWatchman compiles a list of all the applications running.

  • For each application found, it searches for a script with the same base name as the application executable.

  • NightWatchman then executes this script to handle the closing of the application.

For example, a user is logged on when NightWatchman initiates a power-off, and that user has been editing a Microsoft Word document. NightWatchman first detects that Microsoft Word is running, the executable being winword.exe.

It then searches the NightWatchman scripts directory for winword.js. If it fails to find this, it will then search for winword.vbs. If it finds this script, it will then execute it to handle the closing of Microsoft Word.

Note

It is also possible to write scripts that are version specific. For example, winword.900.53.9.0.vbs

A script helper

In order to perform certain operations and to simplify the creation of application power-off scripts, the NightWatchman installation includes a script helper object called NWMScriptHelper.ocx. This is an ActiveX scripting object intended to be instantiated from within a Windows Scripting Host file. For detailed information on NightWatchman scripting see Windows NightWatchman API.

The helper object provides methods that can be called from within a script. These methods cover the following general areas:

  • To remove the delays that are sometimes explicitly added to scripts when waiting to ensure a particular window appears. Scripts can now use the helper to wait for a window to appear or disappear; see WaitForWindow and WaitWindowGone .

  • Scripts can start working on an application in an indeterminate state – the helper can Cancel, Close or OK dialogs. See CloseActiveAppDialogs .

  • The scripts can be very much more window aware when they use the helper. The helper ensures that the process being controlled contains the active window; see ActivateApp , GetAccItem , SelectAccItem and SelectSubItem .

  • The helper enables regular expressions to be used in power-off scripts for matching window names to allow more generalized matching with in the fields. See FindWindowLike .

  • The helper allows actions to be performed in response to expected events without a lot of difficult scripting. see ExpectWindow .

  • The helper supports the automatic creation of backup names. See MakeNWMFilename .

  • Other functions have been added which may be part of the WScript.Shell object or the FileScriptingObject. This will allow calls to be logged consistently.