Make your own free website on Tripod.com

Home
Home

--- Soumis par Dev Ashish---

Retrouver le domaine NT de l'usager.

    Pour retrouver l'heure du serveur NT, utiliser la fonction API NetWkStaUserGetInfo.

Note: NetWkStaUserGetInfo, de même que quelques autres fonction de l'API, n'existe que sous l'environnement Windows NT. Ce code ne fonctionnera PAS sous Windows 95 or 98.

'************ Code Start *************
Private Type WKSTA_USER_INFO_1
   wkui1_username As Long     'nom de l'usager _
                              couramment "loggé" _
                              sur cette station.
   wkui1_logon_domain As Long 'le nom du domaine _
                              gérant le compte de l'usager _
                              actuellement "loggé" 
   wkui1_oth_domains As Long  'liste des autres mangers de _
                              domaines locaux (LAN) accessibles _
                              par la station.
   wkui1_logon_server As Long 'nom de la station  _
                              qui a authentifié le serveur
End Type

Private Declare Function apiWkStationUser Lib "Netapi32" _
  Alias "NetWkstaUserGetInfo" _
  (ByVal reserved As Long, _
  ByVal Level As Long, _
  ByVal bufptr As Long) _
  As Long
  
Private Declare Function apiStrLenFromPtr Lib "kernel32" _
  Alias "lstrlenW" _
  (ByVal lpString As Long) _
  As Long

Private Declare Sub sapiCopyMemory Lib "kernel32" _
  Alias "RtlMoveMemory" _
  (hpvDest As Any, _
  hpvSource As Any, _
  ByVal cbCopy As Long)


Public Function fUserNTDomain() As String
'*******************************************
'Name:          fUserNTDomain  [NT SEULEMENT] (Function)
'Purpose:       Find NT Domain name of current user
'Author:        Dev Ashish
'Date:          Thursday, January 14, 1999
'Called by:     Any
'Calls:         NetWkstaUserGetInfo, RTLMoveMemory
'Inputs:        None
'Returns:       NT Domain Name of Current User
'*******************************************
On Error GoTo ErrHandler
  Dim lngRet As Long
  Dim lngPtr As Long
  Dim tNTInfo As WKSTA_USER_INFO_1
  
  lngRet = apiWkStationUser(0&, 1&, lngPtr)
  If lngRet = 0 Then
    Call sapiCopyMemory(tNTInfo, ByVal lngPtr, LenB(tNTInfo))
    If Not lngPtr = 0 Then
      With tNTInfo
        fUserNTDomain = fStringFromPtr(.wkui1_logon_domain)
      End With
    End If
  End If

ExitHere:
  Exit Function
ErrHandler:
  fUserNTDomain = vbNullString
  Resume ExitHere
End Function

Private Function fStringFromPtr(lngPtr As Long) As String
Dim lngLen As Long
Dim abytStr() As Byte
  lngLen = apiStrLenFromPtr(lngPtr) * 2
  If lngLen > 0 Then
    ReDim abytStr(0 To lngLen - 1)
    Call sapiCopyMemory(abytStr(0), ByVal lngPtr, lngLen)
    fStringFromPtr = abytStr()
  End If
End Function
'************ Code End *************