Login - Tough One

Vassago

Former Staff Turned AWF Retiree
Local time
Today, 13:08
Joined
Dec 26, 2002
Messages
4,748
Complicated one here....

At my company we run Windows NT 4.0 (yeah, I know, pathetic)

We also have a database that was created by employees that are no longer here. This database is able to use your NT login to verify whether or not you should have access. If you are not allowed to have access it flags you and closes. It is an mde file so I am not able to get the code.

What I would like to know is where Windows stores your network login information and how to use this in access to grant users access to a database without having to have a separate login. Does anyone know how to accomplish this?

Thanks,
 
Hi vassago,

OnLoad:

UserName = fOSUserName()
ComputerName = fOSMachineName()


In Modules:

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


Enjoy,
Wayne
 
Thanks for a quick response, I did find another code that does what I need it to do, unfortunately I don't know how to have it tkae the NT username and compare it to a table.

This is the code I am using.

Option Compare Database
Option Explicit

Private Declare Function GetUserName Lib "AdvAPI32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nsize As Long) As Long

Public Function GetNTUser() As String
On Error GoTo Err_strUserName

Dim strUserName As String
strUserName = String(100, Chr$(0))
GetUserName strUserName, 100
strUserName = Left$(strUserName, InStr(strUserName, Chr$(0)) - 1)
GetNTUser = StrConv(strUserName, vbProperCase)
'MsgBox "Network ID = " & GetNTUser 'use this for testing

Exit_strUserName:
Exit Function

Err_strUserName:
MsgBox Err.number & " " & Err.Description
Resume Exit_strUserName

End Function


What I want it to do is take the "getntuser" and look for it in a table in a field called "Lan ID". Then, when it finds a match assumes all the information from that record. Please help if you can.

Thanks,
 
vassago,

Dim UserName As String
Dim UserGroup As String

Dim dbs As Database
Dim rst As Recordset
Dim sql As String

UserName = fOSUserName()
Set dbs = CurrentDb
sql = "Select * " & _
"From LoginTable " & _
"Where UserName = '" & UserName & "'"

Set rst = dbs.OpenRecordset(sql)

If rst.EOF and rst.BOF Then
MsgBox("Invalid User")
DoCmd.Quit
Else
UserGroup = rst!UserGroup
End If

hth,
Wayne
 
One Last Question

Great! It's working great only...

How do I get the database to feed the record it finds to certain fields of another table. This would be the last step and I just can't seem to get it.

You've been a great help so far.

Thanks,
 
vassago,

Dim UserName As String
Dim UserGroup As String

Dim dbs As Database
Dim rst As Recordset
Dim sql As String

UserName = fOSUserName()
Set dbs = CurrentDb
sql = "Select * " & _
"From LoginTable " & _
"Where UserName = '" & UserName & "'"

Set rst = dbs.OpenRecordset(sql)

If rst.EOF and rst.BOF Then
MsgBox("Invalid User")
DoCmd.Quit
Else
UserGroup = rst!UserGroup
'
' New Code ... Move group name to another table
'
sql = "select * from DbLoginActivity"
set rst = dbs.OpenRecordset(sql)
rst.Addnew
rst!LoginGroup = UserGroup
rst!LoginTime = Now()
rst.Update
End If
'
' End New Code
'
hth,
Wayne
 

Users who are viewing this thread

Back
Top Bottom