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#.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
9,988 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,320 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 110.1K 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.