Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GetUserName() function ain't working 1

Status
Not open for further replies.

IRABYY

Programmer
Apr 18, 2002
221
US
Colleagues,

quick question:
Code:
DECLARE integer GetUserName IN AdvAPI32 string @lpBuffer, integer @lpSize

LOCAL lcBuffer, lnSize, lnRes, I

lcBuffer = SPACE(255)
lnSize = 255

lnRes = GetUserName(@lcBuffer, @lnSize)

IF lnRes = 0
   WAIT WINDOW [ Failure! ]
ELSE
   FOR I = 0 TO 31
      lcBuffer = STRTRAN(lcBuffer, CHR(I), "")
   NEXT I
   WAIT WINDOW [ User Name = "] + ALLTRIM(lcBuffer) + [" ]
ENDIF
RETURN
This code always returns "Failure". The same result when it's GetUserName(lcBuffer, lnSize) (no ampersands).

Where I might have erred?

TIA

Regards,

Ilya
 
Ilya,
I just ran your code under VFP 8.0 on XP Pro SP1, and it worked just fine. What's your environment?

Rick
 
I just tested under VFP 6.0 SP5 on Win2k, and it worked perfectly.
 
wgcs (Programmer) May 7, 2003
I just tested under VFP 6.0 SP5 on Win2k, and it worked perfectly.
*********************************************************
I just ran your code under VFP 8.0 on XP Pro SP1, and it worked just fine. What's your environment?

Rick
*********************************************************

Windows ME, VFP 7.0 SP1. It's said in MSDN Help on this function:
"Requirements
Windows NT/2000 or later: Requires Windows NT 3.1 or later.
Windows 95/98/Me: Requires Windows 95 or later."

So, it should work - but it ain't! [sad]

(Side note: MS have already released SP1 on WinXP? What took them so long? [wink])

Thank you, guys! I'll reboot my box and see if it starts working then.

Regards,

Ilya
 
IRABYY

I will not work on a stand-alone station you have to be logged onto a network.

You can also try:

? GETENV('USERNAME')

Or

?SYS(0)

Or

WshNetwork = CreateObject("WScript.Network")
? wshNetwork.Username





Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
You were right, Mike!

I wasn't logged on into the network. I usually don't because it slows down my machine drastically! But once I did log on - it returned my login name.

Thank you all, colleagues!

Issue is resoved, case is closed.

Regards,

Ilya
 
IRABYY,

I wasn't logged on into the network
You don't have to logged into the network, just logged into window is enough to retrieve the info. GetUserName only return the user that currently logged onto the system not the network. To retrieve username from network is WNetGetUser

More info for GetUserName:


-- AirCon --
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top