Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / May 2005

Tip: Looking for answers? Try searching our database.

PInvoke CredRead in Advapi32.dll

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
hsd31 - 11 May 2005 22:05 GMT
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.Seque­ntial, 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.CredR­ead(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.InteropService­s.FILETIME}
persist = 0
targetAlias = null
targetName = null
type =  0
userName = null
Willy Denoyette [MVP] - 12 May 2005 09:56 GMT
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.Seque­ntial, 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.CredR­ead(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.InteropService­s.FILETIME}
persist = 0
targetAlias = null
targetName = null
type =  0
userName = null

Seems correct, the flags field must be masked with 0x0000000F, only the
least significant 4 bits count, in your case flags = 8 (check the header for
the meaning of Credential flags field).

Willy.
hsd31 - 12 May 2005 15:12 GMT
Fixed the problem. Check the following post:

http://groups-beta.google.com/group/microsoft.public.dotnet.framework.interop/br
owse_frm/thread/487ead44a96a5bd6/d42c68d64abac300?hl=en#d42c68d64abac300


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.