VMware Tools Help : VMware Tools Control Panel : Using VMware Tools Scripts : Use Custom VMware Tools Scripts

Use Custom VMware Tools Scripts
You can use scripts to automate guest operating system operations when you change the power state of a virtual machine. You can also edit default scripts or associate custom scripts with power operations.
On most guest operating systems, if VMware Tools is installed, you can configure settings so that one or more scripts run when the power state changes. For example, when you power off a virtual machine, by default the poweroff-vm-default script runs if the virtual machine is set to shut down the guest rather than abruptly power off.
Scripts are run by the VMware Tools service, or daemon (vmtoolsd). Because vmtoolsd is run as root on Linux, Solaris, and FreeBSD and as System on Windows, the scripts are run in a separate session from the session of the logged-in user. The VMware Tools daemon has no knowledge of desktop sessions, which means that it cannot display graphical applications. Do not attempt to use custom scripts to display graphical applications.
Important
Scripts cannot be run in Windows 95 and NetWare guest operating systems.
 
Prerequisites
Perform one or more of the following tasks, as necessary:
On Linux, Solaris, and FreeBSD guests, to edit a script, make sure xterm and vi are installed in the guest and are in your PATH, or specify which editor to use by setting the EDITOR environment variable.
Procedure
1
2
You can also use the Edit button on the Scripts tab.
If you edit a default script and do not change the name, the script is overwritten during the next VMware Tools update.
3
Click the Scripts tab in the VMware Tools control panel.
4
In the ScriptEvent list, select the power operation to associate with the script.
5
Select the Use Script check box, select Custom script, and click Browse to locate the script.
6
If you run a script and it executes successfully, the script might still fail later. Because the script is run as the logged-in user, the script might fail when run by the VMware Tools daemon during a power operation. This failure happens because the script might have a different working directory when it is run during a power operation, as a different logged-in user.