General information
Category:
Windows API functions
I just want the user's login name.
I have a declaration for WNetGetUser as follows:
private declare function WNetGetUser lib "mpr.dll" alias "WNetGetUserA" (byval lpName as string, byval lpUserName as string, lpnLength as long) as long
then in a button click method:
dim lLen, result as long
dim sName, sBuffer as string
lLen = 255
sBuffer = space$(lLen) 'I have tried string(lLen, vbNullChar) also, same results
result = WNetGetUser(sName, sBuffer, lLen)
here the result is 0, but string is unchanged
I tried assigning "" or vbNullChar to sName and got result of 234
When I do the following in FoxPro, I get the user name I expect:
declare integer WNetGetUser in WIN32API string lpDeviceName, string lpUserNameBuffer, integer @BufferLength
lcBuffer = rep(chr(0), 256)
lnBufSize = 256
if WNetGetUser(0, @lcBuffer, @lnBufSize) = 0
return alltrim(strtran(left(lcBuffer, lnBufSize -1), chr(0))
endif
Can anyone help me?
PS I've not had success with GetComputerName or GetUserName, either.
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only