/// <summary> /// Updates the user credentials for the entry. /// </summary> /// <param name="key">The pre-shared key to update.</param> /// <param name="value">The value to set.</param> /// <returns><b>true</b> if the operation was successful, otherwise <b>false</b>.</returns> /// <remarks> /// <para> /// <b>Windows XP and later: This method is supported.</b> /// </para> /// </remarks> public bool UpdateCredentials(RasPreSharedKey key, string value) { if (this.Owner == null) { ThrowHelper.ThrowInvalidOperationException(Resources.Exception_EntryNotInPhoneBook); } NativeMethods.RASCREDENTIALS credentials = new NativeMethods.RASCREDENTIALS(); credentials.password = value; switch (key) { case RasPreSharedKey.Client: credentials.options = NativeMethods.RASCM.PreSharedKey; break; case RasPreSharedKey.Server: credentials.options = NativeMethods.RASCM.ServerPreSharedKey; break; case RasPreSharedKey.Ddm: credentials.options = NativeMethods.RASCM.DdmPreSharedKey; break; } return RasHelper.Instance.SetCredentials(this.Owner.Path, this.Name, credentials, false); }
/// <summary> /// Retrieves the credentials for the entry. /// </summary> /// <param name="key">The pre-shared key to retrieve.</param> /// <returns>The credentials stored in the entry, otherwise a null reference (<b>Nothing</b> in Visual Basic) if the credentials did not exist.</returns> /// <remarks> /// <para> /// <b>Windows XP and later: This method is supported.</b> /// </para> /// </remarks> /// <exception cref="System.InvalidOperationException">The entry is not associated with a phone book.</exception> /// <exception cref="System.UnauthorizedAccessException">The caller does not have the required permission to perform the action requested.</exception> public NetworkCredential GetCredentials(RasPreSharedKey key) { if (this.Owner == null) { ThrowHelper.ThrowInvalidOperationException(Resources.Exception_EntryNotInPhoneBook); } NativeMethods.RASCM value = NativeMethods.RASCM.None; switch (key) { case RasPreSharedKey.Client: value = NativeMethods.RASCM.PreSharedKey; break; case RasPreSharedKey.Server: value = NativeMethods.RASCM.ServerPreSharedKey; break; case RasPreSharedKey.Ddm: value = NativeMethods.RASCM.DdmPreSharedKey; break; } return RasHelper.Instance.GetCredentials(this.Owner.Path, this.Name, value); }