APIs for getting username


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: APIs for getting username

  1. #1
    Join Date
    May 2006
    Posts
    48

    APIs for getting username

    hi,

    I'm trying to get the name of the user currently logged into windows inside a service using visual studio C++ 2005. I need to use API to get the username. Does anyone know which API to use and how to use it?

    thanks!

  2. #2
    Join Date
    Jan 2005
    Location
    UK
    Posts
    604
    Hi,

    try

    Code:
    GetUserName
    The GetUserName function retrieves the user name of the current thread. This is the name of the user currently logged onto the system. 
    
    BOOL GetUserName(
      LPTSTR lpBuffer,  // address of name buffer
      LPDWORD nSize     // address of size of name buffer
    );
    It's SDK stuff, look on the MSDN for GetUserName

    use it like this:
    Code:
    char buffer[100] = {0 };
    int sz = 99;
    BOOL result = GetUserName(buffer,&sz);
    // error check
    if(result = FALSE)
    {
      // do some error handling here
    }
    else
    {
       // here the user name is in buffer
       cout << buffer << endl
    
    }
    Cheers,

    D
    DKyb
    -------------------------------
    Life is a short warm moment -
    Death is the long cold rest.
    Pink Floyd
    -------------------------------

Similar Threads

  1. Replies: 0
    Last Post: 09-15-2005, 10:01 AM
  2. Login (Java Servlet/Database)
    By cappo in forum Java
    Replies: 1
    Last Post: 04-26-2005, 06:16 PM
  3. Replies: 8
    Last Post: 01-19-2001, 05:50 PM
  4. Replies: 0
    Last Post: 01-19-2001, 12:54 PM
  5. ODBC API's
    By Val in forum VB Classic
    Replies: 6
    Last Post: 06-01-2000, 01:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center