Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Finding out who the user is...
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00178748
Message ID:
00180621
Views:
27
>>LOCAL ;
>> lcNull, ;
>> lcUserId, ;
>> lnLen
>>
>>lcNull=""
>>lcUserId=SPACE(255)
>>lnLen=255
>>
>>* Use the WNetGetUser function in the Win32API to get the user id
>>DECLARE INTEGER WNetGetUser IN WIN32API String @, String @, Integer @
>>IF WNetGetUser(@lcNull,@lcUserId,@lnLen)=0
>> lcUserId=UPPER(LEFT(lcUserId,AT(CHR(0),lcUserId)-1))
>>ELSE
>> lcUserId = ""
>>ENDIF
>>
>>RETURN ALLTRIM(lcUserId)
>
>Mike,
>
>Does that work with all OSs, NOSs, and Network clients? If so, thanks for another very useful hint!

WNetGetUser() works identically on all Win32 platforms (Win9x, WinNT for all VFP-supported versions, and WinCE since verison 2.0); the example given retrieves the userid used to log into Windows locally, so it doesn't care about OS in any case. It should work to identify the userid used to attach a remote resource that's accurate to Windows, but may need to be parsed (for example, you'll get the login ID back when attaching a resource on a remote NT box, but that ID might be qualified with a domain or machine context; eg my local login ID is Administrator, but the id used to attach my G: drive is my domain login, EDHOME\Administrator.)

If you want to get the userid used to attach a network resource, substitute the name of the resource for lcNull. Using the example above:

WNetGetUser("Z:" + CHR(0),@lcUserId,@lnLen)

would attempt to get the userid used to attach the remote resource mapped as Z: locally; this works with printers as well. The device must be mapped to a local resource; you can't check the connection to a UNC this way.

Ed
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform