07. august 2001 - 11:20Der er
2 kommentarer og 1 løsning
funktion til at kontrollerer hvilken netværksgrupe der er logget på
Jeg bruger denne funtion til at kontrollerer hvilken bruger der er logget på:
Option Compare Database Option Explicit \' Access the GetUserNameA function in advapi32.dll and \' call the function GetUserName. Declare Function GetUserName Lib \"advapi32.dll\" Alias \"GetUserNameA\" _ (ByVal lpBuffer As String, nSize As Long) As Long \' Main routine to Dimension variables, retrieve user name \' and display answer. Function Get_User_Name() \' Dimension variables Dim lpBuff As String * 25 Dim ret As Long, username As String \' Get the user name minus any trailing spaces found in the name. ret = GetUserName(lpBuff, 25) username = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1) Forms!hovedmenu!Tekst47 = username
Jeg har brug for en tisvarende funktion til at fastslå hvilken netværksgruppe der er logget på, Hvem kan hjælpe mig ??
Mener du hvilket domæne? I så fald kan nedenstående klare det. Brug fUserNTDomain til at udtrække domænenavnet
Private Type WKSTA_USER_INFO_1 wkui1_username As Long \'name of the user _ currently logged on _ to the workstation. wkui1_logon_domain As Long \'the domain name of _ the user account of the _ user currently logged on wkui1_oth_domains As Long \'list of other LAN _ Manager domains browsed _ by the workstation. wkui1_logon_server As Long \'name of the computer _ that authenticated the _ server End Type
Private Declare Function apiWkStationUser Lib \"Netapi32\" _ Alias \"NetWkstaUserGetInfo\" _ (ByVal reserved As Long, _ ByVal Level As Long, _ 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 ONLY] (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
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.