/// <summary> /// 查询凭据是否存在 /// </summary> /// <param name="targetName">IP或者网络地址</param> /// <returns>是否存在</returns> public static bool QueryCred(string targetName) { IntPtr intPtr = new IntPtr(); bool flag = false; try { flag = NativeCredMan.WReadCred(targetName, CRED_TYPE.DOMAIN_PASSWORD, 1, out intPtr); } catch { flag = false; } return(flag); }
/// <summary> /// 删除凭据 /// </summary> /// <param name="targetName">IP或者网络地址</param> /// <returns>是否删除成功</returns> public static bool DeleteCred(string targetName) { bool flag = false; try { IntPtr intPtr = new IntPtr(); if (NativeCredMan.WReadCred(targetName, CRED_TYPE.DOMAIN_PASSWORD, 1, out intPtr)) { flag = NativeCredMan.DeleteCred(targetName.Trim(), CRED_TYPE.DOMAIN_PASSWORD, 0); } else { flag = true; } } catch { flag = false; } return(flag); }