H
hsd31
I'm trying to PInvoke the 'CredRead' function in Advapi32.dll. It
doesn't seem to work. CredRead returns true, but the CREDENTIALS struct
has flag set to 1538928. Anyone know what it means ? Is my CREDENTIALS
struct incorrect?
PInvoke Signature used:
-----------------------
[DllImport("advapi32.dll", EntryPoint="CredReadW", CharSet =
CharSet.Unicode)]
public static extern bool CredRead(string target,
CRED_TYPE type, int
reservedFlag, ref CREDENTIAL credential);
User Defined Structures:
------------------------
public enum CRED_TYPE : int
{
GENERIC = 1,
DOMAIN_PASSWORD = 2,
DOMAIN_CERTIFICATE = 3,
DOMAIN_VISIBLE_PASSWORD = 4,
MAXIMUM = 5
}
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
public struct CREDENTIAL
{
public UInt32 flags;
public UInt32 type;
public string targetName;
public string comment;
public FILETIME lastWritten;
public UInt32 credentialBlobSize;
public IntPtr credentialBlob;
public UInt32 persist;
public UInt32 attributeCount;
public IntPtr credAttribute;
public string targetAlias;
public string userName;
}
Method Call:
------------
Security.CREDENTIAL credential = new CREDENTIAL();
bool bSuccess = Security.Advapi32Wrapper.CredRead(target,
CRED_TYPE.GENERIC, 0, ref credential));
(NOTE: bSuccess returns TRUE, credentials is not null)
Result:
-------
flags = 1538928
attributeCount = 0
comment = null
credAttribute = 0
credentialBlob = 0
credentialBlobSize = 0
lastWritten = {System.Runtime.InteropServices.FILETIME}
persist = 0
targetAlias = null
targetName = null
type = 0
userName = null
doesn't seem to work. CredRead returns true, but the CREDENTIALS struct
has flag set to 1538928. Anyone know what it means ? Is my CREDENTIALS
struct incorrect?
PInvoke Signature used:
-----------------------
[DllImport("advapi32.dll", EntryPoint="CredReadW", CharSet =
CharSet.Unicode)]
public static extern bool CredRead(string target,
CRED_TYPE type, int
reservedFlag, ref CREDENTIAL credential);
User Defined Structures:
------------------------
public enum CRED_TYPE : int
{
GENERIC = 1,
DOMAIN_PASSWORD = 2,
DOMAIN_CERTIFICATE = 3,
DOMAIN_VISIBLE_PASSWORD = 4,
MAXIMUM = 5
}
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
public struct CREDENTIAL
{
public UInt32 flags;
public UInt32 type;
public string targetName;
public string comment;
public FILETIME lastWritten;
public UInt32 credentialBlobSize;
public IntPtr credentialBlob;
public UInt32 persist;
public UInt32 attributeCount;
public IntPtr credAttribute;
public string targetAlias;
public string userName;
}
Method Call:
------------
Security.CREDENTIAL credential = new CREDENTIAL();
bool bSuccess = Security.Advapi32Wrapper.CredRead(target,
CRED_TYPE.GENERIC, 0, ref credential));
(NOTE: bSuccess returns TRUE, credentials is not null)
Result:
-------
flags = 1538928
attributeCount = 0
comment = null
credAttribute = 0
credentialBlob = 0
credentialBlobSize = 0
lastWritten = {System.Runtime.InteropServices.FILETIME}
persist = 0
targetAlias = null
targetName = null
type = 0
userName = null