VC里如何得到Windows当前登陆的用户名? 用什么函数?
是GetCurrentUser(m_accountname);吗?

解决方案 »

  1.   

    GetUserName
    得到运行当前进程的用户名.
      

  2.   

    GetUserNameThe GetUserName function retrieves the user name of the current thread. This is the name of the user currently logged onto the system.Use the GetUserNameEx function to retrieve the user name in a specified format. Additional information is provided by the IADsADSystemInfo interface.
    BOOL GetUserName(
      LPTSTR lpBuffer,
      LPDWORD nSize
    );
      

  3.   

    GetUserName()
    怎么使用?有例子吗?如果得到用户列表呢?用什么?
      

  4.   

    The GetUserName function retrieves the user name of the current thread. This is the name of the user currently logged onto the system. Windows 2000: Use the GetUserNameEx function to retrieve the user name in a specified format.Windows 2000: Additional information is provided by the IADsADSystemInfo interface. BOOL GetUserName(
      LPTSTR lpBuffer,  // name buffer
      LPDWORD nSize     // size of name buffer
    );
    Parameters
    lpBuffer 
    [out] Pointer to the buffer to receive the null-terminated string containing the user's logon name. If this buffer is not large enough to contain the entire user name, the function fails. A buffer size of (UNLEN + 1) characters will hold the maximum length user name including the terminating null character. UNLEN is defined in Lmcons.h. 
    nSize 
    [in/out] On input, specifies the maximum size, in TCHARs, of the buffer specified by the lpBuffer parameter. On output, receives the number of characters copied to the buffer. 
    If the buffer is not large enough, the function fails and nSize receives the required buffer size, in TCHARs, including the terminating null character. Return Values
    If the function succeeds, the return value is a nonzero value, and the variable pointed to by nSize contains the number of TCHARs copied to the buffer specified by lpBuffer, including the terminating null character. If the function fails, the return value is zero. To get extended error information, call GetLastError. char szUser[80]; 
    DWORD cbUser = 80; 
    if (GetUserName (szUser, &cbUser))
    {
         printf("The impersonated user name is %s",szUser);
    }
    else
    {
         HandleError("GetUserName failed.\n");
    }
      

  5.   

    调用 GetUserName 获取用户名,这个函数支持 Windows 9x、Windows NT 以及 Windows 2000。
        在 Windows NT 和 Windows 2000 系统中,此函数首先检查调用线程是否具备专门的存取令牌,如果得到令牌,则返回与调用线程关联的用户名,否则,返回与调用进程关联的用户名。
      

  6.   

    BOOL GetUserName(
      LPTSTR lpBuffer,
      LPDWORD nSize
    );
      

  7.   

    char szUser[80]; 
    DWORD cbUser = 80; 
    if (GetUserName (szUser, &cbUser))
    {
         printf("The impersonated user name is %s",szUser);
    }
    else
    {
         HandleError("GetUserName failed.\n");
    }
      

  8.   

    读注册表 HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer 下
    有个"Logon User Name"的键值, 把它读出来即可