Jump to content

CredEnumerate Function Call


slax
 Share

Recommended Posts

Hello Everybody,

I need to call a API Function called CredEnumerate. It is used to enumerate the credentials of the current user. I have read that this function belongs to advapi32.dll but everythime I try to call it, autoit crashes. I found this page that explains the function's parameters:

http://msdn.microsoft.com/en-us/library/aa374794(VS.85).aspx

If anybody has a idea about how to call this function, please answer.

Thanks in advance

Link to comment
Share on other sites

Func _CredEnumerate($sFilter, $iFlags)
    Local $aResult
    
    $aResult = DllCall('advapi32.dll', 'int', 'CredEnumerateW', 'wstr', $sFilter, 'uint', $iFlags, 'uint*', '', 'int*', '')
    If @error Or ($aResult[0] = 0) Then
        ConsoleWrite('Error: ' & @error & @TAB & 'Extended: ' & @extended & @CRLF)
        ConsoleWrite(_WinAPI_GetLastError() & @CRLF)
        Return SetError(1)
    EndIf
    
    ConsoleWrite($aResult[0] & @TAB & $aResult[3] & @TAB & $aResult[4] & @CRLF)
    If $aResult[3] > 0 Then _
        DllCall('advapi32.dll', 'none', 'CredFree', 'ptr', $aResult[4])
    
EndFunc

It should be something like this, I can't test it because cred enumeration flag is not supported in Windows XP. If you can enumerate successfully, the return pointer should point to an array of CREDENTIAL (still, not sure I wrote it correctly:

Global Const $tagCREDENTIAL_ATTRIBUTE = _
    'ptr Keyword;' & _
    'dword Flags;' & _
    'dword ValueSize;' & _
    'ptr Value;'

Global Const $tagCREDENTIAL = _
    'dword Flags;' & _
    'dword Type;' & _
    'ptr TargetName;' & _
    'ptr Comment;' & _
    $tagFILETIME & ';' & _
    'dword CredentialBlobSize;' & _
    'ptr CredentialBlob;' & _
    'dword Persist;' & _
    'dword AttributeCount;' & _
    'ptr Attributes;' & _
    'ptr TargetAlias;' & _
    'ptr UserName;'

Use can build a string concatenation of $tagCREDENTIAL $aResult[3] times (if greater than zero) and call DllStructCreate(), specifying this string as the first parameter, and $aResult[4], the pointer as the second parameter. Not tested.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...