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 );
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: 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"); }
调用 GetUserName 获取用户名,这个函数支持 Windows 9x、Windows NT 以及 Windows 2000。 在 Windows NT 和 Windows 2000 系统中,此函数首先检查调用线程是否具备专门的存取令牌,如果得到令牌,则返回与调用线程关联的用户名,否则,返回与调用进程关联的用户名。
得到运行当前进程的用户名.
BOOL GetUserName(
LPTSTR lpBuffer,
LPDWORD nSize
);
怎么使用?有例子吗?如果得到用户列表呢?用什么?
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");
}
在 Windows NT 和 Windows 2000 系统中,此函数首先检查调用线程是否具备专门的存取令牌,如果得到令牌,则返回与调用线程关联的用户名,否则,返回与调用进程关联的用户名。
LPTSTR lpBuffer,
LPDWORD nSize
);
DWORD cbUser = 80;
if (GetUserName (szUser, &cbUser))
{
printf("The impersonated user name is %s",szUser);
}
else
{
HandleError("GetUserName failed.\n");
}
有个"Logon User Name"的键值, 把它读出来即可