Re: Automatically Login to a Domain



I use this function: WNetAddConnection3(...).
I dont know if it work for a domain too.

"ringwood" <ringwood@xxxxxxxxxxxxx> ha scritto nel messaggio
news:e$DX8NJhGHA.4864@xxxxxxxxxxxxxxxxxxxxxxx
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

  • Automatically Login to a Domain
    ... accessing network drives or print servers). ... after using the standard CE domain login dialog, ... The credential manager code is also shown at the bottom of this post: ... // setup the remote name which will be my domain name e.g. MYDOMAIN ...
    (microsoft.public.windowsce.app.development)
  • Re: Automatically Login to a Domain
    ... Credential manager APIs ... That will affect which APIs for CE you use and how far we can support you. ... accessing network drives or print servers). ... const DWORD dwERROR = WNetAddConnection3( ...
    (microsoft.public.windowsce.app.development)
  • RE: Securing a Local Network
    ... Show the Management of your company the insecurity of the Peer to Peer ... setup and discuss what risks are they willing to accept. ... -Cost of getting the web server and the mail server internally versus having ... -Use an older box for Intrusion Detection on the internal network as well. ...
    (Security-Basics)
  • Re: Client computer wont connect to internet ATTN: Joe Crown
    ... for my host/client setup. ... >When I supported Windows 98 & Windows ME the most common cause of ... >> When I try to connect to the internet using Firefox or Internet ... >> 7) In the Manufacturers box, click Microsoft, in the Network Protocols ...
    (microsoft.public.windowsxp.network_web)
  • Re: Network Connections x 2 PCs
    ... The setup is quite ... >>> If you have a broadband router, run XP's Network Setup Wizard on both ... tell it that the computers connect to the ... >>> If you have a hub, the setup depends on how many IP addresses you get ...
    (microsoft.public.windowsxp.general)