>>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