Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
WHO AM I in Novell
Message
De
05/11/1998 23:08:59
 
 
À
05/11/1998 22:56:37
Sergio Ortiz
Tek Services Group, Llc
Hollywood, Floride, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00155101
Message ID:
00155110
Vues:
21
>Does anybody know what function to use to retrieve the User Name from the machine that the user is logged in?

There are several ways to do this; the easy one is to use the Windows Scripting Host's Wscript.Network Automation object if Windows Scripting Host is installed on your system:

oWSHNet = CREATEOBJ('Wscript.Network')
? oWshNet.UserName

If the Windows Scripting Host is not installed, you can use any of several Win32API calls; the simplest is WNetGetUser()
DECLARE INTEGER WNetGetUser IN WIN32API ;
   STRING lpDeviceName, ;
   STRING lpUserNameBuffer, ;
   INTEGER @BufferLength
cBuffer = REPL(CHR(0),256)
nBufSize = 256
IF WNetGetUser(0, @cBuffer, @nBufSize) = 0
   *  Got it
   ? LEFT(cBuffer,nBufSize - 1)
ELSE
   *  Something went wrong
ENDIF
This will retrieve the login name for the local machine. If you wanted to see how the user was logged in to access a particular device, such as a mapped network drive Z:, you would use 'Z:'+CHR(0) in place of the first argument, ie

IF WNetGetUser('Z:'+CHR(0), @cBuffer, @nBufSize)
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