예제 #1
0
        /// <summary>
        /// 创建Windows凭据
        /// </summary>
        /// <param name="key">IP或者网络地址</param>
        /// <param name="userName">用户名</param>
        /// <param name="password">用户密码</param>
        /// <returns></returns>
        public static bool CreateCred(string key, string userName, string password)
        {
            //用于标记凭据添加是否成功 i=0:添加成功;i=1:添加失败
            int i = 0;

            try
            {
                i = NativeCredMan.WriteCred(key,
                                            userName,
                                            password,
                                            CRED_TYPE.DOMAIN_PASSWORD,
                                            CRED_PERSIST.LOCAL_MACHINE);
            }
            catch
            {
                i = 1;
            }
            if (i == 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }