Ao tornar as aplicações MS Access mais profissionais, e também ao passo que vamos desenvolvendo soluções sistêmicas, que se incorporam a outras soluções, a relevância e utilização destas requer alguns cuidados mais sofisticados.
Em alguns casos pode ser necessário que registremos os nomes dos usuários que estão acessando as nossas aplicações, ou talvez desejemos desenvolver um modo de Login que utilize esses nomes de usuários na rede.
Function NetUName() As String
On Error GoTo Err_HandlerDim lngLen As LongDim strUserName As StringConst lngcMaxFieldSize As Long = 64&' Inicia.Let strUserName = String$ (254, vbNullChar)Let lngLen = 255&' Em caso de sucesso a API retornará um valor diferente de zero.If apiGetUserName (strUserName, lngLen) <> 0 Then
Let lngLen = lngLen - 1&If lngLen > lngcMaxFieldSize Then 'Tamanho Máximo do campo.Let lngLen = lngcMaxFieldSizeEnd IfLet NetworkUserName = Left$ (strUserName, lngLen)
End IfExit_Handler:
Exit FunctionErr_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".NetworkUserName", , False)Resume Exit_Handler
End Function
Vamos aproveitar e disponibilizar tambéma função que retorna o nome do computador utilizado no momento do log.Option Compare Database' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
' Code Courtesy of Dev Ashish
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As LongFunction fOSUserName() As String' Returns the network login name
Dim lngLen As Long, lngX As LongDim strUserName As StringLet strUserName = String$(254, 0)Let lngLen = 255Let lngX = apiGetUserName(strUserName, lngLen)If lngX <> 0 ThenLet fOSUserName = Left$(strUserName, lngLen - 1)ElseLet fOSUserName = ""End IfEnd Function
Option Compare Database' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of Dev Ashish
Private Declare Function apiGetComputerName Lib "kernel32" Alias _"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As LongFunction fOSMachineName() As String'Returns the computername
Dim lngLen As Long, lngX As LongDim strCompName As StringlngLen = 16strCompName = String$(lngLen, 0)lngX = apiGetComputerName(strCompName, lngLen)If lngX <> 0 ThenfOSMachineName = Left$(strCompName, lngLen)ElsefOSMachineName = ""End IfEnd Function
Tags: Access, log, API, DLL, user name, apiGetUserName, apiGetComputerName
Nenhum comentário:
Postar um comentário