/// <summary> /// Saves the given Network Credential into Windows Credential store /// </summary> /// <param name="Target">Name of the application/Url where the credential is used for</param> /// <param name="credential">Credential to store</param> /// <param name="type">CredentialType</param> /// <param name="persistenceType">PersistenceType</param> /// <returns></returns> public static bool SaveCredentials(string Target, NetworkCredential credential, CredentialType type, PersistenceType persistenceType) { // Go ahead with what we have are stuff it into the CredMan structures. Credential cred = new Credential(credential); cred.Target = Target; cred.PersistenceType = persistenceType; cred.Type = type; bool ret = cred.Save(); int lastError = Marshal.GetLastWin32Error(); if (!ret) { throw new Win32Exception(lastError, "CredWrite throw an error"); } return(ret); }