NowelWinNet




Private Declare Function GetUserName Lib "advapi32.dll" Alias "_
GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Private Declare Function RegCloseKey Lib "advapi32.dll" _
(ByVal hKey As Long) As Long

Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "_
RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) _
As Long

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

Private Const KEY_ALL_CLASSES As Long = &HF00e'
Private Const REG_SZ As Long = 1
Private Const ERROR_SUCCESS = 0&

Private Function LooseSpace(invoer$) As String
Dim p%

p% = InStr(invoer$, Chr(0))
If p% <> 0 Then
LooseSpace$ = Left$(invoer$, p% - 1)
Exit Function
End If
LooseSpace$ = invoer$

End Function

Public Function GetNovellName() As String
Dim res&, lpBuffer$, nSize&

nSize = 8
lpBuffer = String(8, 0)
res& = GetUserName(lpBuffer, nSize)
GetNovellName$ = LooseSpace(Left$(lpBuffer, nSize))

'user is not logged on to a windows-network

'the username is kept in the HKEY_LOCAL_MACHINE\NETWORK\LOGON\username

If GetNovellName$ = "" Then _
GetNovellName = RegGetString$(&H80000002, "NETWORK\LOGON", "username")

End Function

Private Function RegGetString$(hInKey As Long, ByVal subkey$, ByVal valname$)
Dim RetVal$, hSubKey As Long, dwType As Long, SZ As Long, v$, r As Long

RetVal$ = ""

r = RegOpenKeyEx(hInKey, subkey$, 0, KEY_ALL_CLASSES, hSubKey)
If r <> ERROR_SUCCESS Then GoTo Quit_Now
SZ = 256: v$ = String$(SZ, 0)
r = RegQueryValueEx(hSubKey, valname$, 0, dwType, ByVal v$, SZ)
If r = ERROR_SUCCESS And dwType = REG_SZ Then
RetVal$ = Left(v$, SZ - 1)
Else
RetVal$ = ""
End If
If hInKey = 0 Then r = RegCloseKey(hSubKey)

Quit_Now:
RegGetString$ = RetVal$

End Function










( nowelwinnet.html )- by Paolo Puglisi - Modifica del 17/12/2023