NT Authentication

B

Br1an_g

heres how to get the current NT sign on (from knowledge
base):
function goes in a module
the rest in the module of the form (prob switchboard)

then you can do a select statment to retrieve the user
permissions from your table where lpUserName=tblUserName

Code:
' Declare for call to mpr.dll.
Declare Function WNetGetUser Lib "mpr.dll" _
Alias "WNetGetUserA" (ByVal lpName As String, _
ByVal lpUserName As String, lpnLength As Long) As
Long

Const NoError = 0       'The Function call was
successful

Sub GetUserName()

' Buffer size for the return string.
Const lpnLength As Integer = 255

' Get return buffer space.
Dim status As Integer

' For getting user information.
Dim lpName, lpUserName As String

' Assign the buffer size constant to lpUserName.
lpUserName = Space$(lpnLength + 1)

' Get the log-on name of the person using product.
status = WNetGetUser(lpName, lpUserName, lpnLength)

' See whether error occurred.
If status = NoError Then
' This line removes the null character. Strings
in C are null-
' terminated. Strings in Visual Basic are not
null-terminated.
' The null character must be removed from the C
strings to be used
' cleanly in Visual Basic.
lpUserName = Left$(lpUserName, InStr(lpUserName,
Chr(0)) - 1)
Else

' An error occurred.
MsgBox "Unable to get the name."
End
End If

' Display the name of the person logged on to the
machine.
MsgBox "The person logged on this machine is: " &
lpUserName

End Sub
-----Original Message-----
Good morning,
Rather than requiring users to logon to a new database
(no longer the Labor Standards Request - I'm doing a
Budget/Expense tracking and PO preparation deal now), I'd
like to compare the NT userID from the "client PC" with a
table of users who are allowed to use the application.
I'm not so much (at the moment) concerned about user
levels (of course, I'll be administrator), but I will need
to compare to a table of users...
If I can set userlevel by a usertable (with the list of
NT IDs), then I can allow or not allow certain menus to be
seen, etc.
I've checked the ng archives and found nothing. I'm
posting here, then I will go to the AccessWeb site as well.
 
G

Guest

This is fantastic. Thank you very much

And I assume that the "Unable to get the name" portion can be used to deny access to the database

Thanks
Dere

----- Br1an_g wrote: ----

heres how to get the current NT sign on (from knowledge
base)
function goes in a modul
the rest in the module of the form (prob switchboard

then you can do a select statment to retrieve the user
permissions from your table where lpUserName=tblUserNam

[code
' Declare for call to mpr.dll
Declare Function WNetGetUser Lib "mpr.dll"
Alias "WNetGetUserA" (ByVal lpName As String,
ByVal lpUserName As String, lpnLength As Long) As
Lon

Const NoError = 0 'The Function call was
successfu

Sub GetUserName(

' Buffer size for the return string
Const lpnLength As Integer = 25

' Get return buffer space
Dim status As Intege

' For getting user information
Dim lpName, lpUserName As Strin

' Assign the buffer size constant to lpUserName
lpUserName = Space$(lpnLength + 1

' Get the log-on name of the person using product
status = WNetGetUser(lpName, lpUserName, lpnLength

' See whether error occurred
If status = NoError The
' This line removes the null character. Strings
in C are null
' terminated. Strings in Visual Basic are not
null-terminated
' The null character must be removed from the C
strings to be use
' cleanly in Visual Basic
lpUserName = Left$(lpUserName, InStr(lpUserName,
Chr(0)) - 1
Els

' An error occurred
MsgBox "Unable to get the name.
En
End I

' Display the name of the person logged on to the
machine
MsgBox "The person logged on this machine is: " &
lpUserNam

End Su
[/code
-----Original Message----
Good morning
Rather than requiring users to logon to a new database
(no longer the Labor Standards Request - I'm doing a
Budget/Expense tracking and PO preparation deal now), I'd
like to compare the NT userID from the "client PC" with a
table of users who are allowed to use the application.
I'm not so much (at the moment) concerned about user
levels (of course, I'll be administrator), but I will need
to compare to a table of users..NT IDs), then I can allow or not allow certain menus to be
seen, etc
 
B

Br1an_g

HI derek,

the unable to get name section is if an error occurs and
the code cannot get the NT sign on of the user.

you would need to add another level of check before
the 'Else'

e.g.
Dim dbs as Database
Dim rst as recordset

set dbs = CurrentDb

dbs.Execute "SELECT UserNamePermissions " _
& "INTO SQLTemp " _
& "FROM tblSecurity " _
& "WHERE UserNamePermissions = '" & lpUserName & "';"

'open the new SQLTemp table
Set rst = dbs.OpenRecordset("SQLTemp")

'check if there are records in the temp table
If rst.RecordCount > 0 Then
'username exists apply permissions
else
'username does not exist deny permission
end if

'Tidy up - Delete the temp table
dbs.Execute "DROP TABLE SQLTemp;"

Hope that makes sense

Brian
-----Original Message-----
This is fantastic. Thank you very much.

And I assume that the "Unable to get the name" portion
can be used to deny access to the database?
Thanks!
Derek

----- Br1an_g wrote: -----

heres how to get the current NT sign on (from knowledge
base):
function goes in a module
the rest in the module of the form (prob switchboard)

then you can do a select statment to retrieve the user
permissions from your table where lpUserName=tblUserName

Code:
' Declare for call to mpr.dll.
Declare Function WNetGetUser Lib "mpr.dll" _
Alias "WNetGetUserA" (ByVal lpName As String, _
ByVal lpUserName As String, lpnLength As Long) As
Long

Const NoError = 0       'The Function call was
successful

Sub GetUserName()

' Buffer size for the return string.
Const lpnLength As Integer = 255

' Get return buffer space.
Dim status As Integer

' For getting user information.
Dim lpName, lpUserName As String

' Assign the buffer size constant to lpUserName.
lpUserName = Space$(lpnLength + 1)

' Get the log-on name of the person using product.
status = WNetGetUser(lpName, lpUserName, lpnLength)

' See whether error occurred.
If status = NoError Then
' This line removes the null character. Strings
in C are null-
' terminated. Strings in Visual Basic are not
null-terminated.
' The null character must be removed from the C
strings to be used
' cleanly in Visual Basic.
lpUserName = Left$(lpUserName, InStr (lpUserName,
Chr(0)) - 1)
Else

' An error occurred.
MsgBox "Unable to get the name."
End
End If

' Display the name of the person logged on to the
machine.
MsgBox "The person logged on this machine is: " &
lpUserName

End Sub
-----Original Message-----
Good morning,
Rather than requiring users to logon to a new
database
(no longer the Labor Standards Request - I'm doing a
Budget/Expense tracking and PO preparation deal now), I'd
like to compare the NT userID from the "client PC" with a
table of users who are allowed to use the application.
I'm not so much (at the moment) concerned about user
levels (of course, I'll be administrator), but I will need
to compare to a table of users... list of
NT IDs), then I can allow or not allow certain menus to be
seen, etc. I'm
posting here, then I will go to the AccessWeb site as well.
.
 
B

Br1an_g

derek,

is this a different issue from the authentication?

or is it the code that i originally posted that is giving
this error?

-----Original Message-----
I don't anticipate any errors. (famous last words, I'm sure).

However, each time I'm INSERTing or UPDATEing into
tables, I have a timestamp that gets updated and I want to
update or insert (respectively) the lpUserName as well.
Unfortunately, I'm getting an error message that my
function lpUserName is undefined. I've made my
switchboard module Public, but I need to define my
function. I normally don't have things running outside of
the sub/function which call them, so I'm at a loss. Can
you suggest something that would work?
Thank you!
Derek

----- Br1an_g wrote: -----

HI derek,

the unable to get name section is if an error occurs and
the code cannot get the NT sign on of the user.

you would need to add another level of check before
the 'Else'

e.g.
Dim dbs as Database
Dim rst as recordset

set dbs = CurrentDb

dbs.Execute "SELECT UserNamePermissions " _
& "INTO SQLTemp " _
& "FROM tblSecurity " _
& "WHERE UserNamePermissions = '" & lpUserName & "';"

'open the new SQLTemp table
Set rst = dbs.OpenRecordset("SQLTemp")

'check if there are records in the temp table
If rst.RecordCount > 0 Then
'username exists apply permissions
else
'username does not exist deny permission
end if

'Tidy up - Delete the temp table
dbs.Execute "DROP TABLE SQLTemp;"

Hope that makes sense

Brian
-----Original Message-----
This is fantastic. Thank you very much.
portion
can be used to deny access to the database?
knowledge
base):
function goes in a module
the rest in the module of the form (prob switchboard)
the
user
permissions from your table where lpUserName=tblUserName
Code:
[/QUOTE]
' Declare for call to mpr.dll.
Declare Function WNetGetUser Lib "mpr.dll" _
Alias "WNetGetUserA" (ByVal lpName As String, _
ByVal lpUserName As String, lpnLength As[/QUOTE] Long)[QUOTE]
As was
successful
Const lpnLength As Integer = 255
Dim lpName, lpUserName As String lpUserName.
lpUserName = Space$(lpnLength + 1)[/QUOTE] using[QUOTE]
product.
status = WNetGetUser(lpName, lpUserName, lpnLength)
If status = NoError Then
' This line removes the null[/QUOTE] character.[QUOTE]
Strings
in C are null-
' terminated. Strings in Visual Basic[/QUOTE] are[QUOTE]
not
null-terminated.
' The null character must be removed[/QUOTE] from
the C[QUOTE]
strings to be used
' cleanly in Visual Basic.
lpUserName = Left$(lpUserName, InStr (lpUserName,
Chr(0)) - 1)
Else
MsgBox "Unable to get the name."
End
End If[/QUOTE] on to
the[QUOTE]
machine.
MsgBox "The person logged on this[/QUOTE] machine
is: " &>     lpUserName[QUOTE][QUOTE]
End Sub
-----Original Message-----
Good morning,
Rather than requiring users to logon to a new
database
(no longer the Labor Standards Request - I'm doing a
Budget/Expense tracking and PO preparation
deal
now), I'd
like to compare the NT userID from the "client
PC"
with a
table of users who are allowed to use the application.
I'm not so much (at the moment) concerned about user
levels (of course, I'll be administrator), but
I
will need
to compare to a table of users... list of
NT IDs), then I can allow or not allow certain
menus
to be
seen, etc. I'm
posting here, then I will go to the AccessWeb
site
as well..
 
G

Guest

I figured it out. I had some typos in the code. (modified by myself
Thanks
Dere

----- Br1an_g wrote: ----

derek

is this a different issue from the authentication

or is it the code that i originally posted that is giving
this error

-----Original Message----
I don't anticipate any errors. (famous last words, I'm sure)
tables, I have a timestamp that gets updated and I want to
update or insert (respectively) the lpUserName as well.
Unfortunately, I'm getting an error message that my
function lpUserName is undefined. I've made my
switchboard module Public, but I need to define my
function. I normally don't have things running outside of
the sub/function which call them, so I'm at a loss. Can
you suggest something that would work
Thank you Dere
----- Br1an_g wrote: ----
HI derek
the unable to get name section is if an error occurs
and
the code cannot get the NT sign on of the user
you would need to add another level of check before the 'Else
e.g
Dim dbs as Databas
Dim rst as recordse
set dbs = CurrentD
dbs.Execute "SELECT UserNamePermissions "
& "INTO SQLTemp "
& "FROM tblSecurity "
& "WHERE UserNamePermissions = '" & lpUserName & "';
'open the new SQLTemp tabl
Set rst = dbs.OpenRecordset("SQLTemp"
'check if there are records in the temp tabl
If rst.RecordCount > 0 The
'username exists apply permission
els
'username does not exist deny permissio
end i
'Tidy up - Delete the temp tabl
dbs.Execute "DROP TABLE SQLTemp;
Hope that makes sens
Bria
This is fantastic. Thank you very much
portion
can be used to deny access to the database
knowledge
base)
function goes in a modul
the rest in the module of the form (prob switchboard
the
user
permissions from your table where lpUserName=tblUserNam
' Declare for call to mpr.dll
Declare Function WNetGetUser Lib "mpr.dll"
Alias "WNetGetUserA" (ByVal lpName As String,
ByVal lpUserName As String, lpnLength As
Long)
As was
successfu
Const lpnLength As Integer = 25
Dim lpName, lpUserName As Strin lpUserName
lpUserName = Space$(lpnLength + 1
using
product
status = WNetGetUser(lpName, lpUserName, lpnLength
If status = NoError The
' This line removes the null
character.
Strings
in C are null
' terminated. Strings in Visual Basic
are
not
null-terminated
' The null character must be removed
from
the C
strings to be used
' cleanly in Visual Basic.
lpUserName = Left$(lpUserName, InStr (lpUserName,
Chr(0)) - 1)
Else
MsgBox "Unable to get the name."
End
End If
on to
the
machine.
MsgBox "The person logged on this
machine
is: " &> lpUserName
End Sub [/code]
-----Original Message-----
Good morning,
Rather than requiring users to logon to a new
database
(no longer the Labor Standards Request - I'm doing a
Budget/Expense tracking and PO preparation
deal
now), I'd
like to compare the NT userID from the "client
PC"
with a
table of users who are allowed to use the application.
I'm not so much (at the moment) concerned about user
levels (of course, I'll be administrator), but
I
will need
to compare to a table of users... list of
NT IDs), then I can allow or not allow certain
menus
to be
seen, etc. I'm
posting here, then I will go to the AccessWeb
site
as well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top