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

Get User name or Computer name

Status
Not open for further replies.

Sherak

Programmer
Sep 1, 2003
83
GB
Is there a funtion in Builder whic will return the user name of the user logged on to windows and also the computer name?.

thanks in advance :)
 
ASAIK, Borland doesn't encapsulate these functions into a VCL but you can still use the Windows API's GetUserName() and GetComputerName().

The following snippet came from October 1999 issue of C++Builder Developer's Journal. You can read the entire article online at
Code:
char buf[300];
DWORD bufSize = sizeof(buf);

bool success = ::GetUserName(buf, &bufSize);
if (success)
    lines->Add("Network user name = " + String(buf));
else
    lines->Add("Unable to get network user name.");

bufSize = sizeof(buf);
success = ::GetComputerName(buf, &bufSize);
if (success)
    lines->Add("Network computer name = " + String(buf));
else
    lines->Add("Unable to get network computer name.");

James P. Cottingham
-----------------------------------------
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
You can just use the getenv function of stdlib.h. This will retrieve environment variables of the local computer.

Environment vars that would work are:
- USERNAME
- COMPUTERNAME
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top