If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

NT Authentication within VB app

Can anyone tell me the API call to use to find the domain and username of
the currently logged on user to use to authenticate wen allowing access to
a VB app? The person before me tried to use LookupAccountName but it doesn't
seem to be working, it's returning the machine name instead of the domain.
Any ideas?

Re: NT Authentication within VB app

Amy;
You should be able to do this using NetLocalGroupGetMembers. I currently
have posted a question reg this to the group as I had some problem converting
Pointer to String, otherwise the complete code that I am using is listed.
Ajith

"Amy" <agstephens@hotmail.com> wrote:
>
>Can anyone tell me the API call to use to find the domain and username of
>the currently logged on user to use to authenticate wen allowing access
to
>a VB app? The person before me tried to use LookupAccountName but it doesn't
>seem to be working, it's returning the machine name instead of the domain.
>Any ideas?

Re: NT Authentication within VB app

Amy;
You should be able to do this using NetLocalGroupGetMembers. I currently
have posted a question reg this to the group as I had some problem converting
Pointer to String, otherwise the complete code that I am using is listed.
Ajith

"Amy" <agstephens@hotmail.com> wrote:
>
>Can anyone tell me the API call to use to find the domain and username of
>the currently logged on user to use to authenticate wen allowing access
to
>a VB app? The person before me tried to use LookupAccountName but it doesn't
>seem to be working, it's returning the machine name instead of the domain.
>Any ideas?

Re: NT Authentication within VB app

I don't think this is exactly what I'm looking for. I want to pull the domain
and username of the current user and use that to authenticate whether or
not they have rights to an Oracle database. If they do, the application
opens, if they don't the application errors out.

The way I understand NetLocalGroupGetMembers, it appears to return all group
members within a given domain\local group right?

"Ajith" <siponjava@hotmail.com> wrote:
>
>Amy;
>You should be able to do this using NetLocalGroupGetMembers. I currently
>have posted a question reg this to the group as I had some problem converting
>Pointer to String, otherwise the complete code that I am using is listed.
>Ajith
>
>"Amy" <agstephens@hotmail.com> wrote:
>>
>>Can anyone tell me the API call to use to find the domain and username
of
>>the currently logged on user to use to authenticate wen allowing access
>to
>>a VB app? The person before me tried to use LookupAccountName but it doesn't
>>seem to be working, it's returning the machine name instead of the domain.
>>Any ideas?
>

Re: NT Authentication within VB app

I don't think this is exactly what I'm looking for. I want to pull the domain
and username of the current user and use that to authenticate whether or
not they have rights to an Oracle database. If they do, the application
opens, if they don't the application errors out.

The way I understand NetLocalGroupGetMembers, it appears to return all group
members within a given domain\local group right?

"Ajith" <siponjava@hotmail.com> wrote:
>
>Amy;
>You should be able to do this using NetLocalGroupGetMembers. I currently
>have posted a question reg this to the group as I had some problem converting
>Pointer to String, otherwise the complete code that I am using is listed.
>Ajith
>
>"Amy" <agstephens@hotmail.com> wrote:
>>
>>Can anyone tell me the API call to use to find the domain and username
of
>>the currently logged on user to use to authenticate wen allowing access
>to
>>a VB app? The person before me tried to use LookupAccountName but it doesn't
>>seem to be working, it's returning the machine name instead of the domain.
>>Any ideas?
>

"Amy" <agstephens@hotmail.com> wrote:
>
>I don't think this is exactly what I'm looking for. I want to pull the domain
>and username of the current user and use that to authenticate whether or
>not they have rights to an Oracle database. If they do, the application
>opens, if they don't the application errors out.
>
>The way I understand NetLocalGroupGetMembers, it appears to return all group
>members within a given domain\local group right?
>
>"Ajith" <siponjava@hotmail.com> wrote:
>>
>>Amy;
>>You should be able to do this using NetLocalGroupGetMembers. I currently
>>have posted a question reg this to the group as I had some problem converting
>>Pointer to String, otherwise the complete code that I am using is listed.
>>Ajith
>>
>>"Amy" <agstephens@hotmail.com> wrote:
>>>
>>>Can anyone tell me the API call to use to find the domain and username
>of
>>>the currently logged on user to use to authenticate wen allowing access
>>to
>>>a VB app? The person before me tried to use LookupAccountName but it doesn't
>>>seem to be working, it's returning the machine name instead of the domain.
>>>Any ideas?
>>
>

"Amy" <agstephens@hotmail.com> wrote:
>
>I don't think this is exactly what I'm looking for. I want to pull the domain
>and username of the current user and use that to authenticate whether or
>not they have rights to an Oracle database. If they do, the application
>opens, if they don't the application errors out.
>
>The way I understand NetLocalGroupGetMembers, it appears to return all group
>members within a given domain\local group right?
>
>"Ajith" <siponjava@hotmail.com> wrote:
>>
>>Amy;
>>You should be able to do this using NetLocalGroupGetMembers. I currently
>>have posted a question reg this to the group as I had some problem converting
>>Pointer to String, otherwise the complete code that I am using is listed.
>>Ajith
>>
>>"Amy" <agstephens@hotmail.com> wrote:
>>>
>>>Can anyone tell me the API call to use to find the domain and username
>of
>>>the currently logged on user to use to authenticate wen allowing access
>>to
>>>a VB app? The person before me tried to use LookupAccountName but it doesn't
>>>seem to be working, it's returning the machine name instead of the domain.
>>>Any ideas?
>>
>

Re: NT Authentication within VB app

hai amy
i am pasting the code here as a class module named ..... to use in ur VB
project.
copy all the data in between the 2 starred lines into a notepad and save
it as CNTUserWKstn.cls file to be used in ur VB project. go thru this class
file in a object browser. u will find properties like domain, loggedOnuser
etc

Private Type WKSTA_INFO_102
wki102_platform_id As Long
wki102_computername As Long
wki102_langroup As Long
wki102_ver_major As Long
wki102_ver_minor As Long
wki102_lanroot As Long
wki102_logged_on_users As Long
End Type

Private Type WkstaInfo102
PlatformId As Long
ComputerName As String
LanGroup As String
VerMajor As Long
VerMinor As Long
LanRoot As String
LoggedOnUsers As Long
End Type

Private Type WKSTA_USER_INFO_1
wkui1_username As Long
wkui1_logon_domain As Long
wkui1_oth_domains As Long
wkui1_logon_server As Long
End Type

If lpStringW Then
nLen = lstrlenW(lpStringW) * 2
If nLen Then
ReDim buffer(0 To (nLen - 1)) As Byte
CopyMem buffer(0), ByVal lpStringW, nLen
PointerToStringW = buffer
End If
End If
End Function

'Ritorna un elenco dei membri di un gruppo locale
'Uses the win api functions to retrieve list of local groups a user belongs
Private Function LocalGroupsGetMember(Server As String, Group As String)
As ListOfMemberGroup
Dim yServer() As Byte
Dim yGroup() As Byte
Dim lRetCode As Long
Dim nRead As Long, nTotal As Long
Dim nRet As Long, nResume As Long
Dim PrefMaxLen As Long
Dim i As Long, x As Long
Dim tGroupInfo As LOCALGROUP_MEMBERS_INFO_API
Dim lGroupInfo As Long
Dim lGroupInfoPtr As Long
Dim GroupInfo As GroupMemberInfo
Dim GrpList As ListOfMemberGroup

If ServerName <> "" Then
If InStr(1, ServerName, "\\") = 0 Then
ServerName = "\\" & ServerName
End If
End If

yServer = ServerName & vbNullChar
MakeServerName = yServer

End Function

' *********************************************************
' Public Methods
' Pass the name of group as input string
' returns True if current user is in the group specified as in parameter
' else returns False
' *********************************************************

Public Function CheckCurrentUserInGroup(GrpItem As String) As Boolean

Dim GrpList As ListOfMemberGroup
Dim i As Integer

'Local Group
GrpList = LocalGroupsGetMember(ComputerName, GrpItem)

'if the grplist is not initilised ie., no corresponding entries then exit
If GrpList.Init = False Then

CheckCurrentUserInGroup = False

Else

For i = 1 To UBound(GrpList.List)
'if user and group match then return true and exit
If UserName = GrpList.List(i).UserName Then
CheckCurrentUserInGroup = True
Exit Function
Else
CheckCurrentUserInGroup = False
End If
Next

End If

End Function

' *********************************************************
' Public Methods
' returns a string array of groups to which the user belongs
' *********************************************************

Public Function UsersInGroup(ByVal GrpName As String) As String()
Dim GrpList As ListOfMemberGroup
Dim i As Integer, aUser() As String

'Local Group
GrpList = LocalGroupsGetMember(ComputerName, GrpName)

'if the grplist is not initilised ie., no corresponding entries.
If GrpList.Init = False Then
UsersInGroup = aUser()
Else
ReDim aUser(1 To UBound(GrpList.List))
For i = 1 To UBound(GrpList.List)
aUser(i) = GrpList.List(i).UserName
Next
UsersInGroup = aUser()
End If

End Function

*****************************************************************

"Amy" <agstephens@hotmail.com> wrote:
>
>Can anyone tell me the API call to use to find the domain and username of
>the currently logged on user to use to authenticate wen allowing access
to
>a VB app? The person before me tried to use LookupAccountName but it doesn't
>seem to be working, it's returning the machine name instead of the domain.
>Any ideas?

Re: NT Authentication within VB app

hai amy
i am pasting the code here as a class module named ..... to use in ur VB
project.
copy all the data in between the 2 starred lines into a notepad and save
it as CNTUserWKstn.cls file to be used in ur VB project. go thru this class
file in a object browser. u will find properties like domain, loggedOnuser
etc

Private Type WKSTA_INFO_102
wki102_platform_id As Long
wki102_computername As Long
wki102_langroup As Long
wki102_ver_major As Long
wki102_ver_minor As Long
wki102_lanroot As Long
wki102_logged_on_users As Long
End Type

Private Type WkstaInfo102
PlatformId As Long
ComputerName As String
LanGroup As String
VerMajor As Long
VerMinor As Long
LanRoot As String
LoggedOnUsers As Long
End Type

Private Type WKSTA_USER_INFO_1
wkui1_username As Long
wkui1_logon_domain As Long
wkui1_oth_domains As Long
wkui1_logon_server As Long
End Type

If lpStringW Then
nLen = lstrlenW(lpStringW) * 2
If nLen Then
ReDim buffer(0 To (nLen - 1)) As Byte
CopyMem buffer(0), ByVal lpStringW, nLen
PointerToStringW = buffer
End If
End If
End Function

'Ritorna un elenco dei membri di un gruppo locale
'Uses the win api functions to retrieve list of local groups a user belongs
Private Function LocalGroupsGetMember(Server As String, Group As String)
As ListOfMemberGroup
Dim yServer() As Byte
Dim yGroup() As Byte
Dim lRetCode As Long
Dim nRead As Long, nTotal As Long
Dim nRet As Long, nResume As Long
Dim PrefMaxLen As Long
Dim i As Long, x As Long
Dim tGroupInfo As LOCALGROUP_MEMBERS_INFO_API
Dim lGroupInfo As Long
Dim lGroupInfoPtr As Long
Dim GroupInfo As GroupMemberInfo
Dim GrpList As ListOfMemberGroup

If ServerName <> "" Then
If InStr(1, ServerName, "\\") = 0 Then
ServerName = "\\" & ServerName
End If
End If

yServer = ServerName & vbNullChar
MakeServerName = yServer

End Function

' *********************************************************
' Public Methods
' Pass the name of group as input string
' returns True if current user is in the group specified as in parameter
' else returns False
' *********************************************************

Public Function CheckCurrentUserInGroup(GrpItem As String) As Boolean

Dim GrpList As ListOfMemberGroup
Dim i As Integer

'Local Group
GrpList = LocalGroupsGetMember(ComputerName, GrpItem)

'if the grplist is not initilised ie., no corresponding entries then exit
If GrpList.Init = False Then

CheckCurrentUserInGroup = False

Else

For i = 1 To UBound(GrpList.List)
'if user and group match then return true and exit
If UserName = GrpList.List(i).UserName Then
CheckCurrentUserInGroup = True
Exit Function
Else
CheckCurrentUserInGroup = False
End If
Next

End If

End Function

' *********************************************************
' Public Methods
' returns a string array of groups to which the user belongs
' *********************************************************

Public Function UsersInGroup(ByVal GrpName As String) As String()
Dim GrpList As ListOfMemberGroup
Dim i As Integer, aUser() As String

'Local Group
GrpList = LocalGroupsGetMember(ComputerName, GrpName)

'if the grplist is not initilised ie., no corresponding entries.
If GrpList.Init = False Then
UsersInGroup = aUser()
Else
ReDim aUser(1 To UBound(GrpList.List))
For i = 1 To UBound(GrpList.List)
aUser(i) = GrpList.List(i).UserName
Next
UsersInGroup = aUser()
End If

End Function

*****************************************************************

"Amy" <agstephens@hotmail.com> wrote:
>
>Can anyone tell me the API call to use to find the domain and username of
>the currently logged on user to use to authenticate wen allowing access
to
>a VB app? The person before me tried to use LookupAccountName but it doesn't
>seem to be working, it's returning the machine name instead of the domain.
>Any ideas?

Re: NT Authentication within VB app

hai amy <agstephens@hotmail.com>
i am pasting the code here as a class module named ..... to use in ur VB
project.
copy all the data in between the 2 starred lines into a notepad and save
it as CNTUserWKstn.cls file to be used in ur VB project. go thru this class
file in a object browser. u will find properties like domain, loggedOnuser
etc

Private Type WKSTA_INFO_102
wki102_platform_id As Long
wki102_computername As Long
wki102_langroup As Long
wki102_ver_major As Long
wki102_ver_minor As Long
wki102_lanroot As Long
wki102_logged_on_users As Long
End Type

Private Type WkstaInfo102
PlatformId As Long
ComputerName As String
LanGroup As String
VerMajor As Long
VerMinor As Long
LanRoot As String
LoggedOnUsers As Long
End Type

Private Type WKSTA_USER_INFO_1
wkui1_username As Long
wkui1_logon_domain As Long
wkui1_oth_domains As Long
wkui1_logon_server As Long
End Type

If lpStringW Then
nLen = lstrlenW(lpStringW) * 2
If nLen Then
ReDim buffer(0 To (nLen - 1)) As Byte
CopyMem buffer(0), ByVal lpStringW, nLen
PointerToStringW = buffer
End If
End If
End Function

'Ritorna un elenco dei membri di un gruppo locale
'Uses the win api functions to retrieve list of local groups a user belongs
Private Function LocalGroupsGetMember(Server As String, Group As String)
As ListOfMemberGroup
Dim yServer() As Byte
Dim yGroup() As Byte
Dim lRetCode As Long
Dim nRead As Long, nTotal As Long
Dim nRet As Long, nResume As Long
Dim PrefMaxLen As Long
Dim i As Long, x As Long
Dim tGroupInfo As LOCALGROUP_MEMBERS_INFO_API
Dim lGroupInfo As Long
Dim lGroupInfoPtr As Long
Dim GroupInfo As GroupMemberInfo
Dim GrpList As ListOfMemberGroup

If ServerName <> "" Then
If InStr(1, ServerName, "\\") = 0 Then
ServerName = "\\" & ServerName
End If
End If

yServer = ServerName & vbNullChar
MakeServerName = yServer

End Function

' *********************************************************
' Public Methods
' Pass the name of group as input string
' returns True if current user is in the group specified as in parameter
' else returns False
' *********************************************************

Public Function CheckCurrentUserInGroup(GrpItem As String) As Boolean

Dim GrpList As ListOfMemberGroup
Dim i As Integer

'Local Group
GrpList = LocalGroupsGetMember(ComputerName, GrpItem)

'if the grplist is not initilised ie., no corresponding entries then exit
If GrpList.Init = False Then

CheckCurrentUserInGroup = False

Else

For i = 1 To UBound(GrpList.List)
'if user and group match then return true and exit
If UserName = GrpList.List(i).UserName Then
CheckCurrentUserInGroup = True
Exit Function
Else
CheckCurrentUserInGroup = False
End If
Next

End If

End Function

' *********************************************************
' Public Methods
' returns a string array of groups to which the user belongs
' *********************************************************

Public Function UsersInGroup(ByVal GrpName As String) As String()
Dim GrpList As ListOfMemberGroup
Dim i As Integer, aUser() As String

'Local Group
GrpList = LocalGroupsGetMember(ComputerName, GrpName)

'if the grplist is not initilised ie., no corresponding entries.
If GrpList.Init = False Then
UsersInGroup = aUser()
Else
ReDim aUser(1 To UBound(GrpList.List))
For i = 1 To UBound(GrpList.List)
aUser(i) = GrpList.List(i).UserName
Next
UsersInGroup = aUser()
End If

End Function

*****************************************************************

"Amy" <agstephens@hotmail.com> wrote:
>
>Can anyone tell me the API call to use to find the domain and username of
>the currently logged on user to use to authenticate wen allowing access
to
>a VB app? The person before me tried to use LookupAccountName but it doesn't
>seem to be working, it's returning the machine name instead of the domain.
>Any ideas?

Re: NT Authentication within VB app

hai amy <agstephens@hotmail.com>
i am pasting the code here as a class module named ..... to use in ur VB
project.
copy all the data in between the 2 starred lines into a notepad and save
it as CNTUserWKstn.cls file to be used in ur VB project. go thru this class
file in a object browser. u will find properties like domain, loggedOnuser
etc

Private Type WKSTA_INFO_102
wki102_platform_id As Long
wki102_computername As Long
wki102_langroup As Long
wki102_ver_major As Long
wki102_ver_minor As Long
wki102_lanroot As Long
wki102_logged_on_users As Long
End Type

Private Type WkstaInfo102
PlatformId As Long
ComputerName As String
LanGroup As String
VerMajor As Long
VerMinor As Long
LanRoot As String
LoggedOnUsers As Long
End Type

Private Type WKSTA_USER_INFO_1
wkui1_username As Long
wkui1_logon_domain As Long
wkui1_oth_domains As Long
wkui1_logon_server As Long
End Type

If lpStringW Then
nLen = lstrlenW(lpStringW) * 2
If nLen Then
ReDim buffer(0 To (nLen - 1)) As Byte
CopyMem buffer(0), ByVal lpStringW, nLen
PointerToStringW = buffer
End If
End If
End Function

'Ritorna un elenco dei membri di un gruppo locale
'Uses the win api functions to retrieve list of local groups a user belongs
Private Function LocalGroupsGetMember(Server As String, Group As String)
As ListOfMemberGroup
Dim yServer() As Byte
Dim yGroup() As Byte
Dim lRetCode As Long
Dim nRead As Long, nTotal As Long
Dim nRet As Long, nResume As Long
Dim PrefMaxLen As Long
Dim i As Long, x As Long
Dim tGroupInfo As LOCALGROUP_MEMBERS_INFO_API
Dim lGroupInfo As Long
Dim lGroupInfoPtr As Long
Dim GroupInfo As GroupMemberInfo
Dim GrpList As ListOfMemberGroup

If ServerName <> "" Then
If InStr(1, ServerName, "\\") = 0 Then
ServerName = "\\" & ServerName
End If
End If

yServer = ServerName & vbNullChar
MakeServerName = yServer

End Function

' *********************************************************
' Public Methods
' Pass the name of group as input string
' returns True if current user is in the group specified as in parameter
' else returns False
' *********************************************************

Public Function CheckCurrentUserInGroup(GrpItem As String) As Boolean

Dim GrpList As ListOfMemberGroup
Dim i As Integer

'Local Group
GrpList = LocalGroupsGetMember(ComputerName, GrpItem)

'if the grplist is not initilised ie., no corresponding entries then exit
If GrpList.Init = False Then

CheckCurrentUserInGroup = False

Else

For i = 1 To UBound(GrpList.List)
'if user and group match then return true and exit
If UserName = GrpList.List(i).UserName Then
CheckCurrentUserInGroup = True
Exit Function
Else
CheckCurrentUserInGroup = False
End If
Next

End If

End Function

' *********************************************************
' Public Methods
' returns a string array of groups to which the user belongs
' *********************************************************

Public Function UsersInGroup(ByVal GrpName As String) As String()
Dim GrpList As ListOfMemberGroup
Dim i As Integer, aUser() As String

'Local Group
GrpList = LocalGroupsGetMember(ComputerName, GrpName)

'if the grplist is not initilised ie., no corresponding entries.
If GrpList.Init = False Then
UsersInGroup = aUser()
Else
ReDim aUser(1 To UBound(GrpList.List))
For i = 1 To UBound(GrpList.List)
aUser(i) = GrpList.List(i).UserName
Next
UsersInGroup = aUser()
End If

End Function

*****************************************************************

"Amy" <agstephens@hotmail.com> wrote:
>
>Can anyone tell me the API call to use to find the domain and username of
>the currently logged on user to use to authenticate wen allowing access
to
>a VB app? The person before me tried to use LookupAccountName but it doesn't
>seem to be working, it's returning the machine name instead of the domain.
>Any ideas?