Change status of Lync by script
Asked Answered
T

4

9

Is it possible to change status of Microsoft Lync 2010 by script?

I want Script which works on Win XP and change status to available after fixed interval.Tried to search in internet but was not successful in finding one.

Temporize answered 25/4, 2013 at 11:47 Comment(0)
M
12

According to the documentation, the Lync binary does not offer that feature. However, you could use the Lync SDK to achieve what you want by writing a small helper application (or incorporating the relevant code in your current application).

According to an MVP in the Microsoft forums, this also is not available out-of-the-box.

However, according to the documentation, a PowerShell script like this one should be able to do the trick:

import-module "C:\Program Files (x86)\Microsoft Lync\SDK\Assemblies\Desktop\Microsoft.Lync.Controls.Dll"

$availability = [Microsoft.Lync.Controls.ContactAvailability]::Available

$contactInfo = new-object 'System.Collections.Generic.Dictionary[Microsoft.Lync.Model.PublishableContactInformationType, object]'
$contactInfo.Add([Microsoft.Lync.Model.PublishableContactInformationType]::Availability, 
                $availability)

$ar = $self.BeginPublishContactInformation($contactInfo, $null, $null)
$self.EndPublishContactInformation($ar)

This script requires the Lync SDK or the Lync SDK redistributable to be installed.

Much of this information has been taken from here.

Motor answered 2/5, 2013 at 16:54 Comment(1)
Lync sucks. Although this works it will be ignored as soon as the PC gets locked and inactive, from MSDN: These programmatically set availability values are overridden by the Lync 2013 client when the local user has not touched the keyboard or mouse for some time.Gilkey
H
3

The above post does not work. More DLL modules are needed. But i've made the following changes below so it works. Then you can use TaskSch to get it to run automatically. Still needs the 2010 Lync SDK installing.

Set 15550 to mean 'Off-Work' not 'Away'. More useful.

See - http://blogs.technet.com/b/heyscriptingguy/archive/2012/08/11/weekend-scripter-use-the-windows-task-scheduler-to-run-a-windows-powershell-script.aspx

Note this code does not check if LYNC is signed in. If it is not it will not run.

import-module "C:\Program Files (x86)\Microsoft Lync\SDK\Assemblies\Desktop\Microsoft.Lync.Controls.Dll"
import-module "C:\Program Files (x86)\Microsoft Lync\SDK\Assemblies\Desktop\Microsoft.Lync.Model.Dll"

# Obtain the entry point to the Lync.Model API
$client = [Microsoft.Lync.Model.LyncClient]::GetClient()

$self = $client.Self;

#Set Details of Personal Note and Availability
#Useful availability codes for use below - 3500 Available, 15500 Away (converted to "Off Work" in this script by setting activity ID), 6500 Busy, 9500 Do not disturb, 12000 Be Right Back) 
$availability = 3500
$date = [DateTime]::Now
$message = "Remote Work. UK Time +5 hours EST (US), -5.5 IST (India). Availability script last run $date"

#Publish personal note and presence availability of the local user
$contactInfo = new-object 'System.Collections.Generic.Dictionary[Microsoft.Lync.Model.PublishableContactInformationType, object]'
$contactInfo.Add([Microsoft.Lync.Model.PublishableContactInformationType]::PersonalNote, 
            $message)
$contactInfo.Add([Microsoft.Lync.Model.PublishableContactInformationType]::Availability, 
            $availability)
If ($availability -eq 15500) {$contactInfo.Add([Microsoft.Lync.Model.PublishableContactInformationType]::ActivityId, 
            "off-work")}

$ar = $self.BeginPublishContactInformation($contactInfo, $null, $null)
$self.EndPublishContactInformation($ar)
Haematothermal answered 11/10, 2014 at 15:27 Comment(1)
2013 Lync SDK - the DLL's are at C:\Program Files (x86)\Microsoft Office\Office15\LyncSDK\Assemblies\Desktop\Graycegrayheaded
G
1

Ok - This is what I did

  1. Install 2013 SDK (This works with Skype for Business too BTW)
  2. use the code from Pete above except change the assemblies directories to C:\Program Files (x86)\Microsoft Office\Office15\LyncSDK\Assemblies\Desktop\ for both of those
  3. I had to add config files per this page (run as administrator http://tfl09.blogspot.com/2010/08/using-newer-versions-of-net-with.html
  4. Change the message in the script of Pete's
  5. Automate with Task Scheduler the .ps1 script
Graycegrayheaded answered 9/7, 2015 at 23:34 Comment(1)
Also if you're using .ps1 as Visual Studio post build action make sure that have executionpolicy for powershell x86 version set correctly.Sodium
S
1

For Lync 2013 this PowerShell script works. You'll need to install the Lync 2013 SDK first. The SDK installer might say you need to install Silverlight 4, but don't worry about that, it's not necessary.

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process -Confirm:$false
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser -Confirm:$false

Import-Module "C:\Program Files\Microsoft Office\Office15\LyncSDK\Assemblies\Desktop\Microsoft.Lync.Model.dll"
Import-Module "C:\Program Files\Microsoft Office\Office15\LyncSDK\Assemblies\Desktop\Microsoft.Lync.Controls.dll"

$client = [Microsoft.Lync.Model.LyncClient]::GetClient()

$availability = [Microsoft.Lync.Controls.ContactAvailability]::Away

$contactInfo = (New-Object "System.Collections.Generic.Dictionary[Microsoft.Lync.Model.PublishableContactInformationType,object]") -As "System.Collections.Generic.IEnumerable[System.Collections.Generic.KeyValuePair[Microsoft.Lync.Model.PublishableContactInformationType,object]]"
$contactInfo.Add([Microsoft.Lync.Model.PublishableContactInformationType]::Availability, $availability)

$ar = $client.Self.BeginPublishContactInformation($contactInfo, [System.AsyncCallback]$null, [object]$null)
$client.Self.EndPublishContactInformation($ar)

That sets the status to "Appear Away", but you can change [Microsoft.Lync.Controls.ContactAvailability]::Away into this [Microsoft.Lync.Controls.ContactAvailability]::None to reset the status.

Sanborne answered 19/4, 2018 at 17:41 Comment(1)
+One ... Finally someone who links to a crucial part of this idea (the SDK!)Inflammatory

© 2022 - 2024 — McMap. All rights reserved.