Skip to main content

Problem:

This example demonstrates the use of the two Win32 API functions WNetGetUser to retrieve the name of the user who is currently logged on, and WNetAddConnection2 to verify a specified password against a network servers password file for the current user.

Resolution:

INTRODUCTION

==========

This example demonstrates the use of the two Win32 API functions WNetGetUser in order to retrieve the name of the user who is currently logged on, and WNetAddConnection2 in order to verify a specified password against a network servers password file for the current user.

These routines allow you to use the Networks password authentication routines so that you can use the same network user names and passwords as security to your own application.

You pass a network machine name, a username and a password to the WNetAddConnection2 function and it will attempt to log the specified user on to the network machine name provided. A return code is returned which indicates whether or not the call was successful.

SOURCE FILES:

==========

Program Files            Description

---------------------     -----------------------------------------------------------

CHECKLOGIN.CBL    Program that calls the WIN32 API functions.

MINIWIN.CPY          These are the Win32 API header files, converted for use with Net Express.

WINTYPES.CPY       

WINNETWK.CPY

ERROR.CPY

WINERROR.CPY

REQUIREMENTS:

==========

This sample should run on all systems running Windows 95 SE or higher. This program does a dynamic load of the Windows system file MPR.DLL. MPR.DLL must be made available within the PATH environment variable.

OPERATION:

========

Rebuild this project to create the file checklogin.exe. This is a character mode program that will display the results of the API function calls. It will obtain the name of the user currently logged on and will then prompt for a password. This password will then be used to attempt to login the user on the specified network server. The username and password must be valid for the system specified or the error ERROR-SESSION-CREDENTIAL-CONFLICT will be returned. This indicates a bad password or username.

NOTE:

====

If you do not want to dynamically load MPR.DLL then you can change the call-convention used from dynamicWINAPI to WINAPI and add the Windows SDK import library MPR.LIB to the Project/Build Settings/Link/Advanced/ Link with these Libraries field.

==========================================================

Keywords: demonstration, sample, example, demo, win32 api, checklogin.zip

demo.ex

demo.me

demo.ne

Attachments:

checklogin.zip

Old KB# 4160