Automatically Login to a Domain



Hello,

we have a MIPSII device running CE 5.0 that we wish to automaitcally login
to a domain either when it starts up or immediately prior to some kind of
transaction that requires the device to be logged into the domain (e.g.
accessing network drives or print servers).

After some research I believe there are two functions available to me, those
being WNetAddConnection3 and the Credential Manager API (CredWrite).

Originally I tried using WNetAddConnection3 but I repeatedly keep getting
error code 53 (ERROR_BAD_NETPATH). Most examples I have found appear to
refer to network share folders or something like that, whereas I wish to log
on to a domain as I presume this will take care of all necessary logins. The
code is shown at the bottom of the post.

Whilst trying to solve the above problem I then stumbled across the
Credentials Manager API. This seems even better than the method above which
appeared to be confirmed when I did a comparison of the registry before and
after using the standard CE domain login dialog, as it showed an additional
entry with the key 'HKLM\Comm\Security\CredMan\Creds\1'. As such I went
ahead and implemented my own version of this code but yet again it did not
work even though the CredWrite call appeared to return the ERROR_SUCCESS
flag. The credential manager code is also shown at the bottom of this post:

My question is which is the best method and what am I doing wrong?

Any help is greatly appreciated,

Many Thanks

Roger


/// **************************** USING WNetAddConnection3
*********************************

NETRESOURCE tNetworkRes;
memset( &tNetworkRes, 0, sizeof( tNetworkRes) );

tNetworkRes.dwType = RESOURCETYPE_ANY;
tNetworkRes.lpLocalName = NULL;

// only microsft network provider supported
tNetworkRes.lpProvider = NULL;

// setup the remote name which will be my domain name e.g. MYDOMAIN
tNetworkRes.lpRemoteName = ptLanInfo->domain;

tNetworkRes.dwDisplayType = RESOURCEDISPLAYTYPE_DOMAIN;

tNetworkRes.dwUsage = RESOURCEUSAGE_CONTAINER;

tNetworkRes.dwScope = RESOURCE_GLOBALNET;

// connect to the network
const DWORD dwERROR = WNetAddConnection3( AfxGetApp()->m_pMainWnd->m_hWnd,
&tNetworkRes,
ptLanInfo->password,
ptLanInfo->user,
0 );
// check if successful
if( ERROR_SUCCESS != dwERROR )
{
CString strError( L"" );
strError.Format( L"Unsuccessful connection to the network, error %u",
dwERROR );
LOG_DIAGNOSTIC_MESSAGE( MSGLISTSER_DIAGNOSTIC_ERROR, strError );
DebugBreak();
}

/// **************************** USING CREDENTIALS MANAGER
*********************************

CRED tCredentials;
tCredentials.dwVersion = CRED_VER_1;

// this is a domain password we want to store
tCredentials.dwType = CRED_TYPE_DOMAIN_PASSWORD;

// setup the username which is in the format MYDOMAIN\MyUserName
tCredentials.wszUser = ptLanInfo->user;
tCredentials.dwUserLen = wcslen( tCredentials.wszUser ) + 1;

// setup the target which will be my domain name e.g. MYDOMAIN
tCredentials.wszTarget = ptLanInfo->domain;
tCredentials.dwTargetLen = wcslen( tCredentials.wszTarget ) + 1;

// finally setup the password - I am assuming this is supposed to be in
WCHAR format
tCredentials.pBlob = reinterpret_cast< PBYTE >( ptLanInfo->password );
tCredentials.dwBlobSize = wcslen( ptLanInfo->password ) * sizeof( WCHAR );

tCredentials.dwFlags = 0;

// now write the credentials to the registry
const DWORD dwERROR = CredWrite( &tCredentials, 0 );
if( dwERROR != ERROR_SUCCESS )
{
DebugBreak();
}

// flush the registry to persist the credentials
CRegistry kRegKey;
kRegKey.Flush( );
kRegKey.Close( );


.



Relevant Pages

  • Re: Automatically Login to a Domain
    ... accessing network drives or print servers). ... those being WNetAddConnection3 and the Credential Manager API. ... // setup the remote name which will be my domain name e.g. MYDOMAIN ... const DWORD dwERROR = WNetAddConnection3( ...
    (microsoft.public.windowsce.app.development)
  • Re: Single Sign On with 802.1x wireless authentication
    ... You may want to select "do not login with credential manager" and Login using normal credentials. ... How to Setup Windows, Network, VPN & Remote Access on ... I have installed IAS RADIUS for wireless authentication. ...
    (microsoft.public.windows.vista.networking_sharing)
  • Re: Logging into a NETWORK from a Machine behind a NAT Router
    ... > IP Address that is part of the bigger network. ... > What do I have to do, to login to a Windows Network, from one of those NAT ... > Do I have to setup some 'pass through' settings on the NAT Router? ...
    (microsoft.public.windows.server.active_directory)
  • Re: Single Sign On with 802.1x wireless authentication
    ... Networking, Internet, Routing, VPN Troubleshooting on ... How to Setup Windows, Network, VPN & Remote Access on ... login with credential manager" and Login using normal credentials. ...
    (microsoft.public.windows.vista.networking_sharing)
  • Re: Single Sign On with 802.1x wireless authentication
    ... It happen's with Toshiba as well which doesnt have credential manager. ... login with credential manager" and Login using normal credentials. ... How to Setup Windows, Network, VPN & Remote Access on ... I have installed IAS RADIUS for wireless authentication. ...
    (microsoft.public.windows.vista.networking_sharing)