CrAzY hOuSe
Locos por la programación
Conocer el nombre del usuario (leyendo el registro de Windows).
.net

Syndication

Windows almacena el nombre del usuario grabado en el registro del sistema.

Un ejemplo para obtener dicho nombre:

'nivel al cual se quiere acceder en el registro
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const REG_SZ = 1
'función api para obtener el valor de una llave
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, _
                         ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, _
                         lpcbData As Long) As Long
'abrir una llave para su uso
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, _
                         ByVal lpSubKey As String, phkResult As Long) As Long
'cerrar una llave
Private Declare Function RegCloseKey Lib "advapi32.dll" Alias "RegCloseKeyA" (ByVal hKey As Long) As Long

Public Function UsuarioRegistrado() As String
    Dim hLlave As Long
    Dim strLlave As String
    Dim lngSize As Long
    Dim lngType As Long
    Dim x As Long
    
    If RegOpenKey(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion", hLlave) Then Exit Function
    strLlave = Space$(255)
    lngSize = Len(strLlave)
    x = RegQueryValueEx(hLlave, "RegisteredOwner", 0, lngType, ByVal strLlave, lngSize)
    If x = 0 Then
    If lngType = REG_SZ And lngSize <= Len(strLlave) Then
        UsuarioRegistrado = Left$(strLlave, lngSize)
    End If
    End If
    RegCloseKey hLlave
End Function

Posted mar, jul 18 2000 23:36 by Maverick
Filed under: ,

Add a Comment

(optional)  
(optional)
(required)  
Remember Me?
MavericK
Powered by Community Server (Non-Commercial Edition), by Telligent Systems