How to get the current logged in UserName and Password in Excel VSTO temlate in C#

Bharat Veer 1 Reputation point
2021-12-02T10:02:46.07+00:00

I have created an Excel VSTO Template project with Excel 2016 version. Its working fine. In this Excel VSTO template we create some transaction or you can say records.

Now we need to identify the record with user so that we could know whos created which record.

For it we need to get the Current User Name and Password of the logged in user in VSTO excel template154417-excel-user-info.jpg.

Please see the attached image and we need to get the Current logged in user ( I have put in yellow mark) in my code C#.

Microsoft 365 and Office | Development | Other
Developer technologies | C#
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 122.6K Reputation points
    2021-12-02T19:25:28.497+00:00

    To get the current user, try Environment.UserName.

    To get the full name, add a reference to System.DirectoryServices.AccountManagement (maybe using NuGet) and try System.DirectoryServices.AccountManagement.UserPrincipal.Current.DisplayName.

    To get the password, see other answers.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.