CredRead()不能跨登录会话的工作 [英] CredRead() not working across login sessions

查看:242
本文介绍了CredRead()不能跨登录会话的工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的凭据管理器API按照这个答案。引用相关的代码片段:

I am using the Credential Manager API as per this answer. Quoting relevant code snippet:

public static Credential ReadCredential(string applicationName)
{
    IntPtr nCredPtr;
    bool read = CredRead(applicationName, CredentialType.Generic, 0, out nCredPtr);
    if (read)
    {
        using (CriticalCredentialHandle critCred = new CriticalCredentialHandle(nCredPtr))
        {
            CREDENTIAL cred = critCred.GetCredential();
            return ReadCredential(cred);
        }
    }

    return null;
}



它的伟大工程,除了当我注销我的Windows帐户,然后登录再次,CredRead()返回false和 Marshal.GetLastWin32Error()给我 1168 ERROR_NOT_FOUND

为什么这种行为?请问凭据管理API的工作只为当前会话,还是我做错了什么。

Why this behaviour? Does the Credential Management API work only for the current session, or am I doing something wrong?

修改:评论下方的this问题说:

用于凭证管理的API的文件似乎表明这些凭证与一个登录会话相关联。也许LogonUser的结果在一个新的登录会话,所以凭据不存在那里。

The documents for the credential management APIs seem to indicate that these credentials are associated with a logon session. Perhaps LogonUser results in a new logon session, so the credentials don't exist there.

不过,我还没有找到任何证据该凭证管理会话特定的。我认为这将是非常无用的,如果是这样的话

However I haven't yet found any evidence that Credential Management is session-specific. I think it would be pretty useless if that were the case.

编辑2 :为了记录,如果你需要得到错误说明为什么CredRead()失败,请检查ReadCred()方法中的这篇文章

Edit 2: Just for the record, if you need to get the error number indicating why CredRead() is failing, check ReadCred() method in this article.

推荐答案

您可以配置凭据是通过设置坚持属性

You can configure how the credential is persisted by setting the Persist property

从MSDN(的 http://msdn.microsoft.com/en-us/library/windows/desktop/aa374788(v = vs.85)的.aspx

CRED_PERSIST_SESSION
CRED_PERSIST_LOCAL_MACHINE
CRED_PERSIST_ENTERPRISE

这篇关于CredRead()不能跨登录会话的工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆