How to get user log-in name? - for jhance

Posted on 1998-12-22
Last Modified: 2010-08-05
in relation to the previous qn i asked,
can u pls guide me on how to return the user name in a char buffer? I need to pass this data to other functions and
I am facing difficulties converting it to char buffer.

char* GetLogin()
    NET_API_STATUS netStatus;
    WKSTA_USER_INFO_0 *buf;
    netStatus = NetWkstaUserGetInfo(NULL, 0, (LPBYTE *)&buf);
    //wprintf(_T("Username is %s\n"), buf->wkui0_username);
    return buf->wkui0_username;

int main(int argc, TCHAR* argv[])
      char* buf = GetLogin();
        return 0;

Question by:tanmh
  • 3
LVL 11

Accepted Solution

alexo earned 0 total points
ID: 1180820
static char buff[256];
NetWkstaUserGetInfo(NULL, 0, (LPBYTE*)&pBuff);
WideCharToMultiByte(CP_ACP, 0, (LPWSTR)pBuff->wkui0_username, -1, buff, sizeof buff, NULL, NULL);
return buff;
LVL 11

Expert Comment

ID: 1180821
OOps, sorry.  Didn't notice the "for jhance" part.  You can reject it if you want jhance to get the points (although the answer is correct...)

Author Comment

ID: 1180822
hi alexo,
although it was for jhance but he didn't take up this question
and your answer is correct so it is only right that
I give you the marks.

LVL 11

Expert Comment

ID: 1180823
Actually I see no reason in restricting questions to a single expert (unless, of course, if those are "dummy" questions to award points).

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now