API Call for Access 2 , Windows 3.11 Wanted 
Author Message
 API Call for Access 2 , Windows 3.11 Wanted

I am trying to write a function that will return the current user logged
into Windows 3.11 via a API call if one exists .
 Can anyone help

Thanks in advance.

--
     .__________________________________________________________.
      |                                                          |
      |                     Kevin Swain                          |

      |              Database Product Group Leader               |
      |                  Gec Marconi S3i Ltd                     |

    / )        Home Page http://www.*-*-*.com/       ( \
   ( (|__________________________________________________________|) )
 (((\ \)  /,)                                               / )  / //))
 (\\\\ \_/ /                                                \ \_/ /////
  \       /                                                  \       /
   \    _/                                                    \_    /



Sat, 18 Sep 1999 03:00:00 GMT  
 API Call for Access 2 , Windows 3.11 Wanted

Quote:

>I am trying to write a function that will return the current user logged
>into Windows 3.11 via a API call if one exists .
> Can anyone help

>Thanks in advance.

Kevin,

Here is some info from my MSDN CD.

Cheers,

Jim

SUMMARY
The information from this article is taken from the following Microsoft
Knowledge Base article:

ARTICLE-ID: Q96772
TITLE     : INF: How to Use WNetGetUser() in Windows for Workgroups

The information is duplicated here to include sample code that is
converted for use in Visual Basic.
WNetGetUser() is documented on page 194 in the Microsoft Windows Device
Driver Kit (DDK) "Device Driver Adaptation Guide" for version 3.1. This
function can be used to retrieve the current user name of the user logged
on to the network underlying Windows. However, when using this function in
Microsoft Windows for Workgroups, WNetGetUser() returns WN_SUCCESS but the
user name string is empty. Because WFWNET.DRV is a multinet driver, the
network that supports WNetGetUser() must be activated before using this
function.

MORE INFORMATION
Until the release of the Windows for Workgroups Software Development Kit
(SDK), the WNetGetUser() function was used internally by Windows. It is
documented in the Windows version 3.1 "Device Driver Adaptation Guide" for
network device driver developers.
Now the Windows for Workgroups SDK allows you to call WNetGetUser() from
an application. However, when using this function on a system with a
multinet driver, you must activate the supporting network by first using
MNetSetNextTarget(). If the target network has not been set, the function
returns WN_SUCCESS but the returned string for the user name is empty.
This is documented in the description of MNetSetNextTarget() in the
Windows for Workgroups SDK.
It is not sufficient to just call MNetSetNextTarget() before
WNetGetUser(). The current target network may not support WNetGetUser().
To set the target network to use WNetGetUser() correctly, you must number
the networks and call WNetGetUser() for each network. If WNetGetUser()
does not return WN_SUCCESS, then increment the network number for the next
target network and iterate the loop. If the loop iterates through all of
the networks but WNetGetUser() never returns WN_SUCCESS, then none of the
target networks support WNetGetUser(). The following sample code
demonstrates how to do this.

Step-by-Step Example

1. Start a new project in Visual Basic. Form1 is created by default.

2. Add the following code to the General Declarations section of Form1:

   ' Enter each of the following Declare statements on one, single line:
   Declare Function WNetGetUser Lib "wfwnet.drv" (ByVal szUser As String,
      nBufferSize As Integer) As Integer
   Declare Function MNetNetworkEnum Lib "wfwnet.drv"
     (lphNetwork As Integer) As Integer
   Declare Function MNetSetNextTarget Lib "wfwnet.drv"
      (ByVal hNetwork As Integer) As Integer

   ' The following function determines the logged-in user in Windows for
   ' Workgroups:
   Function MultiNetGetUser (UserName$) As Integer

      Dim hNetDrv As Integer
      Dim wRetEnum As Integer, ret As Integer
      Dim wRetGetUser As Integer
      Dim cb As Integer
      Dim Found As Integer

      Found = False
      ' Grab the 1st network:
      hNetDrv = 0
      wRetEnum = MNetNetworkEnum(hNetDrv)

      ' Loop while there are installed networks:
      While (wRetEnum = 0) And Not Found
         user$ = Space$(255)
         cb = Len(user$)

         ' Make sure correct network is accessed in next WNetGetUser call:
         ret = MNetSetNextTarget(hNetDrv)

         ' Get the user:
         wRetGetUser = WNetGetUser(user$, cb)

         ' Check for success:
         If wRetGetUser = 0 Then
            ' Just grab the relevant characters:
            UserName$ = Left$(user$, cb - 1)
            MsgBox UserName$, , "WNetGetUser"
            Found = True
         End If

         ' Get the next network:
         wRetEnum = MNetNetworkEnum(hNetDrv)
      Wend
      If Not Found Then
         MsgBox "WNetGetUser not supported on any of the Multinet subnets"
      End If

      MultiNetGetUser = Found

   End Function

3. Put a command button (Command1) on the form.

4. Add the following code to the Command1 Click event:

   Sub Command1_Click()
      r = MultiNetGetUser(UserName$)
   End Sub

5. Save the project.

6. Run the program.  A message box should pop up displaying the user name.

NOTE: To determine whether a system supports multinet operations,
MNetGetCaps() can be used with WNNC_NET_TYPE. The return value has the
WNNC_NET_MultiNet (0x8000) set if the system supports multinet operations.

Additional reference words: 2.00 3.00 3.10 3.11 username multi-net

KBCategory: kbnetwork kbprg kbcode
KBSubcategory: APrgNet



Sat, 18 Sep 1999 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. I need Windows 3.11 API / Necesito API de Windows 3.11

2. I need Windows 3.11 API / Necesito API de Windows 3.11

3. Wanted Visual Basic v.4 16 bit for Windows 3.11

4. WFW 3.11 API Call

5. Win 3.1 / 3.11 Findfile api Calls

6. Looking for a API to creating icons in a Windows 3.11 group

7. Controlling a remote access connection in Windows for Workgroups 3.11

8. Major Help needed with VB4 + Windows 3.11 Linked to Access 2.0 on Novell 4

9. Accessing the WFW 3.11 Network API

10. Listbox changes height when moved from Windows 3.11 to Windows 95

11. DDE & VB4 - Windows 3.11 vs Windows 95

12. Problems with 16 bit Crystal Info on Windows 3.11 (Windows for Workgroups)

 

 
Powered by phpBB® Forum Software