Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Who is logged in?
Message
De
10/11/1998 21:42:40
 
 
À
10/11/1998 16:50:04
Tyson Bonn
Myers and Stauffer Consulting
Harrisburg, Pennsylvanie, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00156400
Message ID:
00156446
Vues:
35
>Here's a routine I run that tries to get the info from the Windows API. If it fails, it then tries the FoxPro information.
>
>
>* Declare the API function.
>DECLARE INTEGER GetUserName IN Win32API STRING @S, INTEGER @I
>
>* Define the buffer size and destination variable.
>lnDWord = 20
>lcBuffer = SPACE(m.lnDWord + 1) && One for the trailing NULL
>
>* Try the API function.
>IF (GetUserName(@m.lcBuffer, m.lnDWord) = 1)
> * Use the API call results.
> lcUserID = STRTRAN(ALLTRIM(m.lcBuffer), CHR(0), [])
>ELSE
> * Use the FoxPro function.
> lcUserID = ID()
>ENDIF
>
>

A better, or at least more flexible choice is to use WNetGetUser, which can either return the local userid, or the userid used to log into a particular remote resource:
DECLARE WNetGetUser IN WIN32API ;
   STRING lpLocalDeviceName, ;
   STRING lpUserName, ;
   INTEGER @SizeOfUserNameBuffer
*  Get the local userid (Windows Login)
cBuf = REPL(CHR(0),256)
nBufSize = 256
IF WNetGetUser(0, @cBuf, @nBufSize) = 0
   ? LEFT(cBuf,nBufSize-1)
ENDIF
*  Get the userid used to attach to the mapped drive Z:
cBuf = REPL(CHR(0),256)
nBufSize = 256
IF WNetGetUser('Z:'+CHR(0), @cBuf, @nBufSize) = 0
   ? LEFT(cBuf,nBufSize-1)
ENDIF
The problem with SYS(0)/ID() and GetUserName() is that it isn't necessarily clear which of several user identities is being returned. I'm usually more interested in the userid that connected to the shared resource, which is the basis of rights granted to the shared resource, rather than the local user identity.
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
Répondre
Fil
Voir

Click here to load this message in the networking platform