Robert Smith
Robert Smith

Reputation: 634

Accessing windows service account username/password

I need to access the windows service account username/password (From within the code of the service itself) to be used to connect to another remote application. My question is, how do I programmatically access the credentials of the currently specified "Log On" account for the windows service I am running. This is the account that is setup in the "Log On" tab of the windows service. The windows service is written in C#.

Upvotes: 0

Views: 642

Answers (1)

Emanuele
Emanuele

Reputation: 888

You can access to username with System.DirectoryServices.AccountManagement.UserPrincipal.Current.Name.

I think that you cannot retrieve password so simply, because of security issues. In fact, if that is possible, any program can access to that (and using that for admin purpose for example).

Upvotes: 2

Related Questions