I have a module in VB6 that retreives the Windows NT/2000 logon name and holds it. I use the GetWindowsLoginUserID() in my RDC Crystal Control to check the users login name. Then, the program checks a database to see what reports the user can access.
I now have a request to limit the reports searching ability to only THEIR login name. As it is now, once they have access to the report, they can access information on anyone if they have the other users ID. I want my reports to look at the GetWindowsLoginUserID() and run reports based on that. Do I need to create a UFL?
'Modeule to get the users Logon Name
Option Explicit
Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" _
(ByVal lpBuffer As String, _
nSize As Long) As Long
Public Function GetWindowsLoginUserID() As String
Dim rtn As Long
Dim sBuffer As String
Dim lSize As Long
sBuffer = String$(260, Chr$(0))
lSize = Len(sBuffer)
rtn = GetUserName(sBuffer, lSize)
If rtn Then
sBuffer = Left$(sBuffer, lSize)
'Reformat string
If InStr(sBuffer, Chr$(0)) Then
sBuffer = Left$(sBuffer, InStr(sBuffer, Chr$(0)) - 1)
End If
GetWindowsLoginUserID = sBuffer
Else
'Error!
GetWindowsLoginUserID = ""
End If
frmMain.Show
End Function
I now have a request to limit the reports searching ability to only THEIR login name. As it is now, once they have access to the report, they can access information on anyone if they have the other users ID. I want my reports to look at the GetWindowsLoginUserID() and run reports based on that. Do I need to create a UFL?
'Modeule to get the users Logon Name
Option Explicit
Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" _
(ByVal lpBuffer As String, _
nSize As Long) As Long
Public Function GetWindowsLoginUserID() As String
Dim rtn As Long
Dim sBuffer As String
Dim lSize As Long
sBuffer = String$(260, Chr$(0))
lSize = Len(sBuffer)
rtn = GetUserName(sBuffer, lSize)
If rtn Then
sBuffer = Left$(sBuffer, lSize)
'Reformat string
If InStr(sBuffer, Chr$(0)) Then
sBuffer = Left$(sBuffer, InStr(sBuffer, Chr$(0)) - 1)
End If
GetWindowsLoginUserID = sBuffer
Else
'Error!
GetWindowsLoginUserID = ""
End If
frmMain.Show
End Function