I am creating an In/Out system tray application that interacts with the Microsoft Lync Server through the Microsoft Lync API. Is there a way to pass the username and password of the current windows user to the Lync API so users will be automatically logged in instead of having them enter the credentials every time?
No, unlike e.g. accessing a web service, there is no way to force Lync to use the logged-on users credentials. You can see this with the Lync client itself the first time you run it on your machine - you will be prompted for domain credentials, even if you are logged on to the machine as a domain user.
All is not lost, though, as Lync (by default) will save credentials as they are entered, and then present them back to the server each time it logs on as that user. You can check to see if Lync is set to save passwords in the registry:
[HKEY_CURRENT_USER\Software\Microsoft\Communicator]
"SavePassword"=dword:00000001
To take advantage of this in the API, you need to:
Now - if your user has not logged in to Lync (or your app) previously, you will get a CredentialRequested event.
(I can't remember off the top of my head which method out of 2 or 3 above is the recommended approach - best to try both and see which you have most luck with)
Next time that user logs in (assuming SavePassword is set to true in the registry), the saved credentials will be passed, so user will log in without the CredentialRequested event firing.
This MSDN article covers the process quite nicely (I'm assuming that you're running Lync in UI Supressed mode, as this is only an issue in suppressed mode)