-1

I am making a program in C# visual studio that requires access to the control panels web credentials. I have forced admin permission in order to do so and now just need to use the extension to acess the credentials. I am used to using Enviroment., where in order to gain access to data the code is: Console.WriteLine("Example: " + Environment.Example); and each thing has a certain name such as Machine Name and OS. when using .WebCredentials each thing also has a name but since I am new to this extension I am unsure of what that name is. Console.WriteLine("Passwords: " + WebCredentials.????); what should I type here?

I've tried .Passwords .Passwrds .Credentials .Webcredentials .browser. .show

1 Answer 1

0

If your goal is to access the Web credentials in the Credential Manager in Control Panel, Microsoft.Exchange.WebServices.Data.WebCredentials is not applicable because it is used for Exchange server authentication and does not access the Windows Credential Manager.

You need to use the PasswordVault class to meet your needs. For detailed steps, please refer to the following:

1: Create a new console application project based on .NET8.0 in VS.

2: Right-click the project in Solution Explorer and click Unload Project.

3: In the pop-up .csproj file, change <TargetFramework>net8.0</TargetFramework> to <TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>:
enter image description here

4: Save and right-click the project and click Reload Project.

5: Add the following code:

using Windows.Security.Credentials;
 
class Program
{
   static void Main()
   {
       var vault = new PasswordVault();
 
       try
       {
           // Get credentials from Credential Manager
           var credential = vault.Retrieve("example.com", "Your_user_name");
 
           //Get username
           string userName = credential.UserName;
 
           // Get password
           string password = credential.Password;
 
           Console.WriteLine("username: " + userName);
           Console.WriteLine("password: " + password);
       }
       catch (Exception ex)
       {
           Console.WriteLine("Unable to get credentials: " + ex.Message);
       }
   }
}
Sign up to request clarification or add additional context in comments.

2 Comments

I'm having problems with the reloading.
Did the problem occur after you created a new .NET 8.0 project and reloaded it? Please provide a screenshot of the error if possible. Meanwhile, I edited and added a picture in my answer, please make sure that the modified .csproj file is as shown in the picture. You can also modify .csproj without unloading and reloading the project. You can find the .csproj file in the root directory of your project in the file explorer, open it with Notepad, modify and save, and then open your project again to build it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.