COMO SABER O TIPO DE USUARIO?

JALEXM 24/09/2012 17:27:56
#410378
Como saber se o usuario local é Administrador ou de outro tipo?
Após o programa abrir, preciso permitir/impedir que o usuário continue a usá-lo conforme seu tipo.
O programa não usa banco de dados, portanto não posso criar tabela de usuários, etc.
Dá prá saber isso usando VB6? Alguma função da API?
Precisava saber isso para WinXP e Win7.
Obrigado.
ROBSON220BASS 24/09/2012 17:44:17
#410387
tenta ai, por que to sem vb6 aqui

http://www.vbmania.com.br/pages/index.php?varModulo=Forum&varMethod=abrir&varID=87759
JALEXM 24/09/2012 17:56:33
#410389
Citação:

:
tenta ai, por que to sem vb6 aqui

http://www.vbmania.com.br/pages/index.php?varModulo=Forum&varMethod=abrir&varID=87759



Na verdade eu precisava saber o tipo de usuário e essa função retorna o nome.
Teria alguma outra dica para o problema?
MARCELO.TREZE 24/09/2012 18:50:00
#410395
Resposta escolhida
bom é o seguinte existem apenas dois tipos (administrador, limitado) eu tenho aqui este código que diz se o usuário é administrador, então se não for.... veja

em um módulo cole

Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type
[ô] dwPlatformId values
Public Const VER_PLATFORM_WIN32s = 0
Public Const VER_PLATFORM_WIN32_WINDOWS = 1
Public Const VER_PLATFORM_WIN32_NT = 2
Public Declare Function GetVersionEx Lib [Ô]kernel32[Ô] Alias [Ô]GetVersionExA” (ByRef lpVersionInformation As OSVERSIONINFO) As Long[Ô] ()

[ô] These functions are for getting the process token information, which IsUserAnAdministrator uses to
[ô] handle detecting an administrator that’s running in a non-elevated process under UAC.
Private Const TOKEN_READ As Long = &H20008
Private Const TOKEN_ELEVATION_TYPE As Long = 18
Private Declare Function IsUserAnAdmin Lib [Ô]Shell32[Ô] Alias [Ô]#680[Ô] () As Integer
Private Declare Function CloseHandle Lib [Ô]kernel32[Ô] (ByVal hObject As Long) As Long
Private Declare Function OpenProcessToken Lib [Ô]advapi32.dll” (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long[Ô] ()
Private Declare Function GetTokenInformation Lib [Ô]advapi32.dll” (ByVal TokenHandle As Long, ByVal TokenInformationClass As Long, TokenInformation As Any,_ ByVal TokenInformationLength As Long, ReturnLength As Long) As Long[Ô] ()

Public Function IsUserAnAdministrator() As Boolean
On Error GoTo IsUserAnAdministratorError
IsUserAnAdministrator = False
If IsUserAnAdmin() Then
IsUserAnAdministrator = True
Exit Function
End If
[ô] If we’re on Vista onwards, check for UAC elevation token
[ô] as we may be an admin but we’re not elevated yet, so the
[ô] IsUserAnAdmin() function will return false
Dim osVersion As OSVERSIONINFO
osVersion.dwOSVersionInfoSize = Len(osVersion)
If GetVersionEx(osVersion) = 0 Then
Exit Function
End If
If osVersion.dwPlatformId <> VER_PLATFORM_WIN32_NT Or osVersion.dwMajorVersion < 6 Then
[ô] If the user is not on Vista or greater, then there’s no UAC, so don’t bother checking.
Exit Function
End If
Dim result As Long
Dim hProcessID As Long
Dim hToken As Long
Dim lReturnLength As Long
Dim tokenElevationType As Long
[ô] We need to get the token for the current process
hProcessID = GetCurrentProcess
If hProcessID <> 0 Then
If OpenProcessToken(hProcessID, TOKEN_READ, hToken) = 1 Then
result = GetTokenInformation(hToken, TOKEN_ELEVATION_TYPE, tokenElevationType, 4, lReturnLength)
If result = 0 Then
[ô] Couldn’t get token information
Exit Function
End If
If tokenElevationType <> 1 Then
IsUserAnAdministrator = True
End If
CloseHandle hToken
End If
CloseHandle hProcessID
End If
Exit Function
IsUserAnAdministratorError:
[ô] Handle errors
End Function


para usar


coloque onde desejar

If IsUserAnAdministrator = True Then
Msgbox [Ô] O usuário é administrador![Ô]
Else
Msgbox [Ô] O usuário é limitado![Ô]
End if


veja se funciona


Tópico encerrado , respostas não são mais permitidas