On Windows guest operating systems, you can write scripts to automate guest operating system operations when you change the power state of a virtual machine.

Before you begin

  • Familiarize yourself with the default VMware Tools scripts. See Default VMware Tools Scripts.

  • If you plan to script the commands used in this procedure and need to know what the exit codes are, see Exit Codes.

About this task

For Windows guest operating systems, you can write new scripts or modify default scripts and save them with new names and then configure VMware Tools to use your custom script instead of the default script.

The default scripts are located in the Program Files\VMware\VMware Tools directory.

On Windows guests, the default scripts for power-on and power-off operations are placeholders only. The script for resume operations contains a line that renews the IP address for the virtual machine. If you write a custom script for the resume operation, you must include this line first.

@%SYSTEMROOT%\system32\ipconfig /renew

The script for suspend operations contains a line that releases the IP address. If you write a custom script for the suspend operation, you must include this line first.

@%SYSTEMROOT%\system32\ipconfig /release

Scripts are run by the VMware Tools service, or daemon (vmtoolsd). Because vmtoolsd is run as root on Linux, Mac, 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 does not detect desktop sessions, which means that it cannot display graphical applications. Do not attempt to use custom scripts to display graphical applications.

Important:

You cannot run scripts on Windows NT, Me, Windows 98, and Windows 95 guest operating systems.

Procedure

  1. Write new scripts or modify default scripts and save them as .bat files with new names.

    The default scripts are located in the Program Files\VMware\VMware Tools directory.

    For suspend scripts, be sure to include the line that releases the IP address. For resume scripts, be sure to include the line that renews the IP address.

  2. Open a command prompt in the guest operating system.
  3. Change directories to the VMware Tools installation directory.

    The default installation directory is C:\Program Files\VMware\VMware Tools.

  4. Enter the command to enable the script.
    VMwareToolboxCmd.exe script script-name enable
    
  5. Enter the command to use the custom script you created.
    VMwareToolboxCmd.exe script script-name set script-path

    For script-path, use the full path to the file, such as, "C:\Temp\poweron-my-vm.bat".

  6. Enter the command to verify that the custom script you specified is now being used.
    VMwareToolboxCmd.exe script script-name current

Results

After you complete this procedure, the VMware Tools service runs the script whenever the specified power operation occurs.