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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting the Username through the Registry

Status
Not open for further replies.

LindaRichard

Programmer
Feb 23, 2001
103
CA
In my Visual Fox Pro 6.0 application I use the Windows API to get the users network name though the registry to set access to various parts of the database.

Everything works fine with Windows 98 2 nd edition with the following keys:
HKEY_LOCAL_MACHINE
Network
Logon
Username

I can retrieve an 8 character username

The problem is that with Windows 2000 professional the registry returns encoded characters. Does anyone have any idea how I can get the network logon username into FoxPro without having to add a routine to force the user to logon a second time?

Thanks

Linda
 
look at sys(0), it returns the user and machine name so you will have to parse.
 
Hi Linda,

As fluteplr said, the method with the least overhead is to parse the username out of the value returned by SYS(0):
lnAt=AT(' # ',SYS(0))+3
? SUBSTR(SYS(0),lnAt)

Additionally, you could use the network object of the Windows Script Host:
oNetwork=CreateObject('WScript.Network')
? oNetwork.UserName

FYI, on my 2000 box, the username is stored in the Logon User Name value of the following key:
\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer
Jon Hawkins

The World Is Headed For Mutiny,
When All We Want Is Unity. - Creed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top