本文介绍了CredWrite 返回 Win32 错误代码 2 (ERROR_INVALID_FUNCTION)“不正确的函数".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试调用 CredWrite,但它正在返回 ERROR_INVALID_FUNCTION.我可以调用 CredRead 来获取凭据密码存储,我可以使用 CredUIPromptForCredentials 存储新凭据.

i'm trying to call CredWrite, but it is returning ERROR_INVALID_FUNCTION. i can call CredRead to fetch credentials out of the password store, and i can store new credentials by using CredUIPromptForCredentials.

但我不知道如何让 CredWrite 工作.

But i cannot figure out how to get CredWrite to work.

我使用的代码是:

var
   Target, Username, Password: WideString;
begin
   Target := 'StackOverflowSomething';
   Username := 'IanBoyd'; 
   Password := 'password69';

   ZeroMemory(@Credentials, SizeOf(Credentials));

   Credentials.TargetName := PWideChar(Target);
   Credentials.Type_ := CRED_TYPE_GENERIC;
   Credentials.UserName := PWideChar(Username);
   Credentials.Persist := CRED_PERSIST_ENTERPRISE;
   Credentials.CredentialBlob := PByte(Password);
   Credentials.CredentialBlobSize := 2*(Length(Password));
   Credentials.UserName := PWideChar(Username);

   if not CredWriteW(@Credentials, 0) then
      RaiseLastWin32Error;

GetLastError 返回 1 (ERROR_INVALID_FUNCTION)

And GetLastError is returning 1 (ERROR_INVALID_FUNCTION)

这个功能不正确吗?它甚至没有返回 ERROR_INVALID_PARAMETER,而是返回功能不正确".什么是不正确的?

Is this function incorrect? It's not even returning ERROR_INVALID_PARAMETER, it's returning "Incorrect function". What is incorrect?

是否有任何调用 CredWrite 的示例代码?

Is there any sample code out there that calls CredWrite?

注意事项

  • 我尝试调用 Ansi 版本 (CredWriteA),结果相同
  • 我尝试过使用 CRED_PERSIST_SESSIONCRED_PERSIST_LOCAL_MACHINE,以及 CRED_PERSIST_ENTERPRISE
  • i've tried calling the Ansi version (CredWriteA), same result
  • i've tried using CRED_PERSIST_SESSION and CRED_PERSIST_LOCAL_MACHINE, in addition to CRED_PERSIST_ENTERPRISE

推荐答案

没关系,我想通了.

这不是 API 调用的错,也不是我的参数的错.

And it's not the fault of the API call, or my parameters.

我只是傻.

我想生闷气,不用说我做了什么:(

And i want to sulk off, without having to say what i did :(

这篇关于CredWrite 返回 Win32 错误代码 2 (ERROR_INVALID_FUNCTION)“不正确的函数".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 08:41