CredWrite returns Win32 error code 2 (ERROR_INVALID_FUNCTION) “Incorrect function.”
문제
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.
But i cannot figure out how to get CredWrite to work.
The code i'm using is:
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;
And GetLastError is returning 1 (ERROR_INVALID_FUNCTION
)
Is this function incorrect? It's not even returning ERROR_INVALID_PARAMETER
, it's returning "Incorrect function". What is incorrect?
Is there any sample code out there that calls CredWrite?
Notes
- i've tried calling the Ansi version (CredWriteA), same result
- i've tried using
CRED_PERSIST_SESSION
andCRED_PERSIST_LOCAL_MACHINE
, in addition toCRED_PERSIST_ENTERPRISE
해결책
Nevermind, i figured it out.
And it's not the fault of the API call, or my parameters.
i'm just stupid.
And i want to sulk off, without having to say what i did :(
다른 팁
이것은 Flash에서 개별 링크 캐싱을 피하기 위해 매우 오래되고 꽤 잘 알려진 매우 잘 알려진 문제입니다.각 호출로 URL의 끝에 정크를 추가하기 만하면됩니다.예 :
myUrlLoader.load(new URLRequest("http://sameOldSite.com/sameOldfile.mp3?" + new Date().toString() ));
.
코드가 테스트되지 않으므로 정확하지 않지만 아이디어를 얻을 수 있습니다.새 날짜를 추가하면 새 날짜 ()를 만들거나 단일 날짜 개체를 재활용하고 toString () 또는 GetTime () 또는 keart를 유지할 때마다 고유 한 문자열 문자열이 나타납니다.글로벌 타이머 객체와 동일한 작업을 수행 할 수 있습니다.extra junk 의이 문자열은 Get 변수로 보이고 사용되지 않기 때문에 삭제됩니다.
I am curious, this is for the smart card, right? and you're storing the pin no to the smart card, maybe the attachment/driver is not loaded for the credwrite to work? Perhaps, with a standard defined smartcard hardware/software used by windows will activate the CredWrite function, my guess is that CredWrite is attempting to communicate with something (perhaps a generic API call to a standard function within the smartcard hardware?)...just my thoughts...
Hope this helps, Best regards, Tom.