NT username storage

lgeer

Capt_Tinker
Local time
Today, 02:29
Joined
Jan 3, 2003
Messages
19
I'm getting alot of samples off the internet that help me with what I'm trying to do (get username from NT's login file) but I have no clue on how to call these functions within my dbase? For the most part I'm calling the info just for "security" reasons from a form but I'd also like to be able to store the data to know who was the last person to edit the content of the dbase.:confused:

Thanks
Tinker
 
lgeer,

Tinker,

In the modules table, on the database window, choose
to create a new module. Call it utility and put
these two functions in:

' ************************************************************
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Private Declare Function apiGetComputerName Lib "kernel32" Alias _
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If lngX <> 0 Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = ""
End If
End Function



Public Function fOSMachineName() As String
'Returns the computername
Dim lngLen As Long, lngX As Long
Dim strCompName As String
lngLen = 16
strCompName = String$(lngLen, 0)
lngX = apiGetComputerName(strCompName, lngLen)
If lngX <> 0 Then
fOSMachineName = Left$(strCompName, lngLen)
Else
fOSMachineName = ""
End If
End Function
' ************************************************************

Then from one of your forms make the calls from something
like the OnOpen event:

Me.ComputerName = fOSMachineName()
Me.UserName = fOSUserName()

hth,
Wayne
 
Ya-hoo!

That's 2 points for you! Thank you for the help - It works now - I was calling it from the wrong location and didn't realize it!:rolleyes:

~Tinker
:D
 

Users who are viewing this thread

Back
Top Bottom