Ottenere lo UserID sotto Win9x e NT

La funzione WNetGetUser recupera il nome dell'utente corrente o il nome usato per stabilire una connessione di rete:

Inserire la seguente dichiarazione in un modulo Bas

Public Declare Function WNetGetUserA Lib "mpr" (ByVal lpName As String , _
ByVal lpUserName As String, lpnLenght As Long) As Long

'Creare una funzione pubblica da richiamare
'cosė: MiaStringa = NomeUtente

Function NomeUtente() As String
    Dim sUserNameBuff as String * 255

    sUserNameBuff = Space(255)
    Call WNetGetUserA( vbNullString , sUserNameBuff , 255&)
    NomeUtente = Left$( sUserNameBuff , _
InStr( sUserNameBuff , vbNullChar ) - 1)
End Function

Testato su: Windows 98, Windows Me, Windows 2000 Professional