问题
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.
回答1:
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.
回答2:
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)
回答3:
Ok - This is what I did
- Install 2013 SDK (This works with Skype for Business too BTW)
- 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 - 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
- Change the message in the script of Pete's
- Automate with Task Scheduler the
.ps1
script
回答4:
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.
来源:https://stackoverflow.com/questions/16213916/change-status-of-lync-by-script