Automate VM Log Out

You are here:

Boot Runner 2 supports auto-login to launch virtual machine operating systems automatically. When users log out, shutdown or suspend a virtual machine, it will not log the user out of the OS X account automatically. Boot Runner 2 contains hooks that will help automate the logout of a virtual machine from the host OS X account andreturn to the Boot Runner Selection Screen.

The basic setup involves setting a Windows logout scriptto generatea particular file whenever the user logs out, shuts down or suspends the virtual machine. Boot Runner sees the file andruns a script toimmediatelylog out of the OS X host account.

Depending on how the virtual host is configured you may need to create a share that can be read from and written to by both Windows and OS X. This share will contain a file that, when created, triggers the OS X account logout.

The file created by the Windows logout script is located at/Users/Shared/.com.twocanoes.bootrunnerlogout or defined by LogoutFile” preference key. Boot Runner sees the file andruns a OS X script locatedat /Library/Application Support/Twocanoes/Boot Runner/logoutscript or path defined by VMPostrunScript preference key. You may modify the Boot Runner logout script to include other actions.

By default the logout script at/Library/Application Support/Twocanoes/Boot Runner/logoutscript simply logs out the user:

osascript -e ’tell application “loginwindow” to event aevtrlgo’

[Note: see this project for a customizable Logout On Idle app]

In Windows, create a batch file that generates afile in/Users/Shared/.com.twocanoes.bootrunnerlogout file (please note the “.” at the beginning of the file name which make this file invisible and less likely to be inadvertently deleted or tampered with by users).

There are multiple ways to generatea file in Windows. In this example, the batch file script creates the file .com.twocanoes.bootrunnerlogout by inserting the text “deleteme” into the file stored in a shared location between OS X and Windows (the “deleteme” text is not required, just included for illustration). The share is represented by a volume named psf. The syntax is:

echo deleteme > \psfshared.com.twocanoes.bootrunner.logout

Place the batch file in C:UsersPublicDocuments. To set this batch script to run whenever logging out of Windows, go to Run-> gpedit.msc and select Windows Settings-> Scripts-> Logoff

Click Add and browse to the batch file, select and it will appear in the scripts window.

Now, when a user logs off of the Windows virtual machine, the file .com.twocanoes.bootrunnerlogout will be created in the shared location. Boot Runner will detect the existence of the file and run a script to log out of the host OS X account, placing the user back at the Boot Runner Selection Screen. Forcleanup, Boot Runner deletes thefile.com.twocanoes.bootrunnerlogout.

Note:

If you touch a file at “/Users/Shared/.com.twocanoes.bootrunnerlogout you will be logged out. You can configure the file using the keyLogoutFile but you must also change the value in the launch agent:
Terminal: cat /Library/LaunchAgents/com.twocanoes.bootlauncher.plist
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE plist PUBLIC “-//Apple//DTD PLIST 1.0//EN” “http://www.apple.com/DTDs/PropertyList-1.0.dtd“>
<plist version=”1.0″>
<dict>
<key>Label</key>
<string>com.twocanoes.bootlauncher</string>
<key>ProgramArguments</key>
<array>
<string>/Library/PrivilegedHelperTools/Boot Runner.app/Contents/Resources/bootlauncher</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>WatchPaths</key>
<array>
<string>/Users/Shared/.com.twocanoes.bootrunnerlogout</string>
</array>
</dict>
</plist>