1

I get access denied error when I'm trying to connect to a remote cluster using the below code. I wanted to establish connection without supplying username/password in the code. I stored them in Windows Credential Manager. This works when I provide username and password in the code. How should I make it to read from the credentials manager?

ConnectionOptions Options = new ConnectionOptions(); 
//String Domain = "mydomain"; 
String Domain = ""; 
//Options.Username = "administrator"; 
//Options.Password = "mypassword";

Options.Authority = "ntlmdomain:" + Domain;
Options.Authentication = AuthenticationLevel.PacketPrivacy;

ManagementScope Scope = new ManagementScope(@"\\win2012cluster\root\cimv2", Options); 
Scope.Connect();
Hem
  • 619
  • 13
  • 26

1 Answers1

1

You have to use interop to use the Credential Management API in .NET: http://www.microsoft.com/indonesia/msdn/credmgmt.aspx

Community
  • 1
  • 1
Kveld Ulf
  • 707
  • 7
  • 9
  • May be I should have been more clear. For me, user stores the credentials in "Windows Credentials" part of Credential Manager and I have to read from them. The link provided by you serves the purpose only if the credentials are stored in "Generic Credentials" part of Credential Manager. If they are not under it, I only get the username and not the password. Also credentials stored under Generic do not help other apps to connect automatically. They must be read and used. – Hem Aug 19 '13 at 13:53
  • Is there a way that I can make your answerer as "not an answer"? I'd like others to look into it. – Hem Aug 20 '13 at 06:26
  • I am sure there is, however, I am new enough that I do not know it. Check the FAQ. In addition, the link I post mentioned the generic credentials, but I'd suggest trying it modified for windows instead of generic. I haven't used the windows portion myself, as I tend to authenticate against active directory when I do the windows based creds. – Kveld Ulf Aug 20 '13 at 13:19
  • I replaced Generic with Windows Credentials. I could only get username but not password. – Hem Aug 20 '13 at 17:27