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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

695 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