Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Retrieving user's loginname
Message
De
15/07/1999 19:40:40
 
 
À
09/07/1999 14:19:22
Information générale
Forum:
Visual Basic
Catégorie:
Autre
Divers
Thread ID:
00239556
Message ID:
00242079
Vues:
28
>In Visual Fox, the function sys(0) will return the user's logon name. Is there a similar function available in Visual Basic? I hope I don't have to go into Win API just to get the user's name.

The code to get the WIndows login name through the API is pretty trivial in VB:

FromDan Appleman's Book Visual Basic Programmer's Guide to the Win32 API

Declare Function GetUserName& Lib "advapi32.dll' Alias "GetUsernameA" _
(ByVal lpBuffer As String, nSize as Long)
DIM S$, cnt&, dl&
cnt& = 199
S$ = STRING$(200,0)
dl& = GetUserName(s$, cnt)
s$ = Left$(s$,cnt)

Not much more than calling SYS(0) and stripping the machine name if it's present conditionally; it's roughly the same code in VFP using the API, and the API code isn't affected by whether or not you're on a network.

If you don't have Appleman's book, get it - it's probably the most intelligible thing on the Win32 API out now unless you're at least passingly familiar with C/C++.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform