有正确答案马上结贴

解决方案 »

  1.   

    GetUserName
    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 and later: 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,  // name buffer
      LPDWORD nSize     // size of name buffer
    );
      

  2.   

    char Temp[126];
    unsigned long lLength=125;memset( Temp, 0, 126 );
    ::GetUserName( Temp, &lLength );
      

  3.   

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