Skip to main content

NightWatchman Enterprise 7.3

NightWatchman scripts
Configuring NightWatchman scripts

There are four types of scripts which give administrators complete flexibility to ensure that computers can be powered down, whatever the circumstances. All scripts are run in the context of the logged on user. These script types are:

  • Pre-run

  • Power-off

  • Run always

  • Run on resume.

PreRun script

This script is set to run before all other actions. At the start of any scheduled event and depending on the status of the -prerun option, NightWatchman runs this script to have control over whether the scheduled event continues.

  • If it fails (exits with a non-zero error code), the scheduled event is automatically postponed and will retry after the standard period defined in retryinterval.

  • If it succeeds and shutdownaction is Standby or Hibernate, the machine is put into one of these states.

  • If it succeeds and shutdownaction is Normal, Reboot or Logoff, the process exception list is checked. If any of the processes in the exception list are currently running, the scheduled event is aborted.

During a NightWatchman installation, a default PreRun script is created that explicitly performs no action and only returns a success code. The script is commented to enable the functionality to be customized easily.

The script can be run prior to displaying the countdown dialog to enable you to carry out pre-flight checks. If any of these checks fail, the NightWatchman power down can be silently cancelled without notifying the end-user. This script is enabled by running - prerun=ON on the command-line.

Power-off scripts

Runs when powering-off or restarting a computer, depending on whether their associated application is running at the time.

  • If a user is logged onto the system and a power-off starts, an attempt is made to save all currently open and edited documents. This is implemented using application power-off scripts – there must be a script for each application that is open. If an application has no corresponding script and has unsaved data, the event is aborted.

  • If the log-off action is Active, all power-off scripts must succeed before the event takes place

  • If the log-off action is Force, the system is powered off regardless of whether the power-off scripts are successful or not

The scripts are ensure that managed applications are gracefully closed and user data is saved. This occurs prior to a log-off or system power-off initiated by NightWatchman. These scripts handle eventualities such as saving current versions of all open files as well as making backups of previously saved versions so users can back out of latest changes if they prefer not to keep them. Any open dialogs are also handled in order to execute the closure of the application in a safe way. Scripting NightWatchman for Mac requires knowledge of AppleScript – it does not use a similar mechanism to the script helper provided for NightWatchman for Windows.

RunAlways script

Runs after the countdown dialog and after all the other scripts during a power-off, logoff or reboot depending on the status of runalways. It may also be run on Hibernate and Standby actions depending on the status runalwaysforsleep option.

Refer to NightWatchman command-line switches for details of referenced switches.

  • If it fails (exits with a non-zero error code), the scheduled event is automatically postponed and will retry after the standard period defined in retryinterval

  • If it succeeds and the NightWatchman shutdownaction is Standby or Hibernate, the machine is put into one of these states

  • If it succeeds and the NightWatchman shutdownaction is power-off, Reboot or Logoff, the process exception list is checked. If any of the processes in the exception list are currently running, the scheduled event is aborted.

This script can be run at the end of this process unlike the application power-off scripts (which will only run if the application to which they relate to is also running) – it will always execute, if it exists on disk and -runalways=ON is set. If you want the RunAlways script to run prior to a NightWatchman initiated hibernate or standby, set -runalwaysforsleep=ON from the command-line.

RunOnResume script

Runs on resuming from a low-power state depending on the status of runonresume. The success or failure of the script has no effect on the resumption of the computer. The RunOnResume script can be used to refresh network connections for running applications. For example, restarting Outlook on resumption if it is running in non-cached mode.

Note

  • The PreRun script is not executed if a user power off is initiated from the Start menu or by a <CTRL-ALT-DEL>.

  • The PreRun and power-off scripts are not executed during hibernate or standby, or if a power-off is initiated from the Start menu or by a <CTRL-ALT-DEL>

  • The –runalways and –runalwaysforsleep settings can be enabled independently of one another

To run correctly, scripts must be saved in the NightWatchman scripts directory on the clients:

  • On Windows – %program files%\1E\Agent\NightWatchman\Scripts

  • On Mac – /Library/Application Support/1E/Scripts (at the root of the system disk.)

Writing NightWatchman power-off scripts

NightWatchman for Windows comes with pre-defined scripts that handle the following products and tools: Microsoft Outlook, Microsoft Word, Microsoft PowerPoint, Microsoft Excel, Microsoft Management Consoles (MMC), Internet Explorer, and Notepad. To handle other applications you can either contact 1E or write your own additional scripts using the details provided in the NightWatchman scripting reference .

Power off scripts language support

Sample scripts for Windows are provided for the following language variant versions of Microsoft Office:

  • Microsoft Office 2016, Office 365, Office 2013, Office 2010 and Office 2007 in English, French and German

  • The default language is en-US. The 1E Agent attempts to detect the user or system preferred UI language set by the administrator in the Regional and Language Options control panel item. The 1E Agent assumes that the same language variant of the Microsoft Office has been installed and executes the scripts for that language on a power down action.

French and German scripts are stored in the following locations on the clients:

  • %program files%\1E\Agent\NightWatchman\Scripts\fr

  • %program files%\1E\Agent\NightWatchman\Scripts\de

The OS language in use defines which scripts are chosen, therefore it is expected that the Microsoft Office MUI matches the OS MUI. If this is not the case, then copy the correct set of Office scripts from the language folder into the user or system UI language folder.

For example, if installing onto a French OS with an English copy of Microsoft Office, the scripts from the English folder should be copied into the French folder.