TeamViewer 12 Deployment
Heads up: this post is from 2016. The tools and versions it covers may have changed since.
Over the past week our college purchased and began testing TeamViewer version 12. This version was to bring new deployment features and make a simple one click install to deploy host to all machines. Sounds easy right? Well unfortunately there are settings that are not set and you have to create some scripts in order to perform the assignment of the device to your account. In this post I will highlight the scripts I used and how I am now able to deploy TeamViewer 12 without requiring the user to log out.
So first if you haven’t already you should create a Host deployment version so that you can download your prebuilt host package. Once downloaded go ahead and import it into Munki. Once imported we are going to make some changes. Firstly, we will need a preinstall script that performs the following:
- Sets your Unattended Access Password
- Sets your Password to change preferences
- Turns off the inital TeamViewer Dialog
- Allows connections to the system whether you are logged on or not
- Always Sends Crash Reports
The last one I added because I was tired of users always getting the crash reports. This way, TeamViewer gets these crash reports and the user is no longer bothered by them. We are also going to remove any old TeamViewer preference files from the system should they still exist. Listed below is my preinstall script that you can take and use in your environment:
PreInstall Script
#!/usr/bin/python
# pylint:disable=C0103, W0703, E0611, W0107
'''TeamViewer 12 PreInstall'''
# This will configure our initial settings for
# TeamViewer version 12 and prepare for install
# Joshua D. Miller - [email protected]
# December 2, 2016 - The Pennsylvania State University
from Foundation import (CFPreferencesSetValue,
CFPreferencesSynchronize,
kCFPreferencesAnyUser,
kCFPreferencesCurrentHost)
from os import listdir, path, remove
from shutil import rmtree
from time import strftime
def main():
'''Main function that will lay down a configuration
using pyObjC's CFPreferencesSetValue and CFPreferencesAppSynchronize
so that these settings will be applied when TeamViewer first runs'''
teamviewer_bundle = 'com.teamviewer.teamviewer.preferences'
tv_prefs = {}
# Set the password Binary decoded from Hex
# Obtain this by setting the password manually on
# TeamViewer 8 and using /usr/bin/defaults read
# on SecurityPasswordAES. You will of course need
# to remove all the spaces and the brackets
tv_prefs['SecurityPasswordAES'] = (
'YourBinaryHere').decode('hex') # #gitignore
# tv_prefs['SecurityPasswordAES'] = ('passwordbinaryhere').decode('hex')
# Set the Options Password Binary decoded from Hex
# Use same method as above to obatain but look for
# OptionsPasswordAES
tv_prefs['OptionsPasswordAES'] = (
'YourBinaryHere').decode('hex') # #gitignore
# tv_prefs['OptionsPasswordAES'] = ('optionbinaryhere').decode('hex')
# Create a timestamp
tv_prefs['Date'] = strftime("%a %b %e %X %Z %Y")
# Remove initial Dialog
tv_prefs['HostInfoDialog'] = 0
# Full Access even when logged out
tv_prefs['ACFullAccessOnLoginScreen'] = 1
# Always Send Crash Reports so users don't see this dialog
tv_prefs['SendAlwaysCrashLogReport'] = 1
# Old TeamViewer configs to look for
old_config_names = ['com.TeamViewer8.Settings',
'com.teamviewer.teamviewer9',
'com.teamviewer.teamviewer10']
# Remove old TeamViewer Config Files
# from /Library/Preferences should they exist
for item in old_config_names:
for filename in listdir('/Library/Preferences/'):
if item in filename:
try:
old_config = path.join(
'/Library/Preferences/', filename)
remove(old_config)
except Exception:
continue
# Remove TeamViewer 8 Application folder if it
# was left behind
try:
rmtree('/Applications/TeamViewer 8/')
except Exception:
pass
try:
remove('{0:}{1:}{2:}'.format(
'/Library/Preferences/', teamviewer_bundle, '.plist'))
except StandardError:
pass
try:
for key, value in tv_prefs.items():
if 'AES' in key:
CFPreferencesSetValue(key, buffer(value), teamviewer_bundle,
kCFPreferencesAnyUser,
kCFPreferencesCurrentHost)
else:
CFPreferencesSetValue(key, value, teamviewer_bundle,
kCFPreferencesAnyUser,
kCFPreferencesCurrentHost)
CFPreferencesSynchronize('com.teamviewer.teamviewer.preferences',
kCFPreferencesAnyUser, kCFPreferencesCurrentHost)
except Exception as error:
print error
exit(1)
if __name__ == '__main__':
main()
Once the installation completes we want to set our attribute that will allow the customization pieces we defined in the management console to download and be applied to the client. (Note: The attribute part is completely optional as if you import your package into Munki with the IDC attached in the name you do not need to use the xattr command.) These include:
- Logo
- Custom Text
- Custom Title
Before I was modifying the MainMenuHost.nib file to remove the ability to exit TeamViewer. This is definitely not best practice but we want to make sure TeamViewer continues to run in case a user decides to close it. When exiting TeamViewer it also stops the launch agents. In order to accomplish this I have added the creation of a launchagent in the postinstall script that will relaunch the TeamViewer services should they be closed. See below for the complete script:
PostInstall Script
#!/usr/bin/python
# pylint:disable=C0103
'''TeamViewer 12 PostInstall Script'''
# This will add our congifuration ID to the application
# bundle so that any custom host module visual modifications
# will be downloaded from the site for each user. It will
# also create a launchagent that will keep the TeamViewer
# client running when a user is logged in even if they exit.
# Joshua D. Miller - [email protected]
# December 2, 2016 - The Pennsylvania State University
from __future__ import print_function
from os import path
from plistlib import writePlist
from xattr import setxattr
def main():
'''This function will apply our configuration ID so that
customizations are added to TeamViewer from our module created
in the management console. It will also create our persistant
launchagent.'''
tv_app_path = '/Applications/TeamViewerHost.app'
# TeamViewer Config ID
tv_conf_id = 'com.TeamViewer.ConfigurationId'
# Custom Attribute from custom pkg
attribute = 'idcYourIDHere' # gitignore
# attribute = 'idcYourIDHere'
# Apply the xattr to TeamViewer's App file for customization
try:
setxattr(tv_app_path, tv_conf_id, attribute)
except StandardError as error:
print(error)
exit(1)
# Create LaunchAgent if it doesn't already exist
service_la = ('/Library/LaunchAgents/com.teamviewer.client.plist')
if path.isfile(service_la):
print('LaunchAgent exists. No creation is needed...')
else:
la_plist = dict(
Disabled=False,
KeepAlive=True,
Label='com.teamviewer.client',
ProgramArguments=[
'/bin/launchctl', 'load',
'com.teamviewer.teamviewer.plist',
'com.teamviewer.teamviewer_desktop.plist'],
RunAtLoad=True,
WorkingDirectory='/Library/LaunchAgents',
)
writePlist(la_plist, service_la)
if __name__ == '__main__':
main()
With the changes made above, we no longer need to require a logout to install TeamViewer. Thanks to Greg Neagle and Michael Lynn it was recommended to use CFPrefs instead of plistlib when modifying the preferences of TeamViewer. This means that the changes we make are immediately committed to the system. Now we move to the activation that will assign the device to your account which includes:
- Policies
- Adding the ID to your Management Account folder
To perform the activation TeamViewer includes an executable that must be run to activate the client with your management account. Thankfully with Munki we are able to automate this process. First you will want to create a DMG file with the activation file in it. Once created, you can import this into Munki and use this pkginfo file for reference. In order to get the installer hash or md5 you will need the following commands:
- md5 /Path/To Your File
- shasum -a256 /Path/To Your DMG
PKGInfo File
<?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>autoremove</key>
<false/>
<key>catalogs</key>
<array>
<string>testing</string>
</array>
<key>category</key>
<string>Administrative Tools</string>
<key>description</key>
<string>This script will activate TeamViewer 12 for remote support from the Carrara Education Technology Center.</string>
<key>developer</key>
<string>CETC</string>
<key>display_name</key>
<string>TeamViewer Activation</string>
<key>installer_item_hash</key>
<string>Install Item Hash</string>
<key>installer_item_location</key>
<string>Image/TeamViewer Client/TeamViewer Activation-12.0.71483.dmg</string>
<key>installer_item_size</key>
<integer>4000</integer>
<key>installer_type</key>
<string>copy_from_dmg</string>
<key>installs</key>
<array>
<dict>
<key>md5checksum</key>
<string>MD5 Here</string>
<key>path</key>
<string>/Library/Application Support/TeamViewer Host/TeamViewer_Assignment</string>
<key>type</key>
<string>file</string>
</dict>
</array>
<key>items_to_copy</key>
<array>
<dict>
<key>destination_path</key>
<string>/Library/Application Support/TeamViewer Host/</string>
<key>source_item</key>
<string>TeamViewer_Assignment</string>
</dict>
</array>
<key>minimum_os_version</key>
<string>10.8.5</string>
<key>installcheck_script</key>
<string>#!/usr/bin/python
# pylint:disable=C0103, E0611
'''TeamViewer 12 Activation Check'''
# This script will check to see if preferences have been
# sent down to the machine after being assigned to an account.
# If that is not the case than the machine will be marked for
# reinstall.
# Joshua D. Miller - [email protected]
# December 6, 2016 - The Pennsylvania State University
from Foundation import CFPreferencesCopyAppValue
from os import path
def main():
'''Main function to check for assignment of TeamViewer
client to our account.'''
# TeamViewer Bundle Identifier
tv_bundle = "com.teamviewer.teamviewer.preferences"
# Path to Preference File
tv_prefs = '/Library/Preferences/{0:}.plist'.format(tv_bundle)
if path.isfile(tv_prefs):
# Check for Policies downloaded to the machine
policy = CFPreferencesCopyAppValue(
'Remote_Settings_TVClientSetting_Policy', tv_bundle)
if policy is not None:
exit(1)
else:
exit(0)
else:
exit(0)
if __name__ == '__main__':
main()
</string>
<key>postinstall_script</key>
<string>#!/usr/bin/python
# pylint:disable=C0103, E0611, W0107, W0703
'''TeamViewer Activation'''
# This script will perform activation of TeamViewer 12 and
# assign it to our account. This will allow us to send policies
# to the machine for TeamViewer and grant us easy remote access
# Joshua D. Miller - [email protected]
# Dec 2, 2016 - The Pennsylvania State University
from subprocess import (check_output, PIPE)
from SystemConfiguration import (SCPreferencesCreate,
SCPreferencesGetValue)
def main():
'''main function to perform activation and assignment of
the TeamViewer 12 Client'''
# Configuration ID
config_id = 'Your Config ID from TeamViewer without the IDC' # #gitignore
# config_id = 'Your Config ID from TeamViewer without the IDC'
# API Token
api_token = '1851753-rcxWXTqOAQ8juF5nXaD9' # #gitignore
# api_token = 'Your API Token obtained from your custom module'
# Datafile Path
datafile_path = '{0:}{1:}{2:}'.format(
'/Library/Application Support/TeamViewer Host/Custom Configurations/',
config_id, '/AssignmentData.json')
# Get Computer Name from socket
# We are using a replace to remove the domain if it is attached
sc_prefs = SCPreferencesCreate(None, "SystemConfiguration", None)
computer_name = SCPreferencesGetValue(
sc_prefs, "System")["System"]["ComputerName"]
try:
check_output(['/Library/Application Support'
'/TeamViewer Host/TeamViewer_Assignment',
'-apitoken', api_token, '-datafile', datafile_path,
'-devicealias', '{0:}'.format(computer_name)],
stderr=PIPE)
except Exception as error:
print error
exit(1)
if __name__ == '__main__':
main()
</string>
<key>name</key>
<string>TeamViewer Activation</string>
<key>unattendedinstall</key>
<true/>
<key>uninstall_method</key>
<string>remove_copied_items</string>
<key>uninstallable</key>
<true/>
<key>update_for</key>
<array>
<string>TeamViewer Host-12.0.71483</string>
</array>
<key>version</key>
<string>12.0.71483</string>
</dict>
</plist>
Once completed, TeamViewer should be deployed on your systems without any user intervention. While working on this I asked TeamViewer how I could set certain preferences and of course I got this response:
Dear Joshua,
Thank you for your message.
We are glad that you have found this feature useful. For the unattended access password with this new deployment method is not possible on any platform at this time.
With the other deployment method for windows only, they have the ability to export a registry file and import on the other windows machines, unfortunately, this ability does not exist on MAC.
The idea with this deployment is that you are given easy access as soon as the device is assigned. so that there is not a single password/point of failure, as far as security, with this new method.
I can submit a feature request on your behalf for this if you wish. If you have any further questions, do not hesitate to contact us.
Best regards,
Support Engineer
Clearly it is possible but they still don’t seem to make macOS deployment a priority. Please submit issues to TeamViewer and advise them to make even more strides towards a fully deployable piece of software.