2011-10-31 138 views
0

我是C新手。我如何檢索當前使用C登錄Windows的用戶?如何檢索使用C的當前Windows用戶登錄?

我知道你可以在C通過環境::用戶名爲此++,但不知道怎麼做,在C.

謝謝:)

+0

你只需要用戶的名字或其他細節? –

+0

你是指正在運行你的代碼的用戶?一次可以有多個用戶登錄。 –

回答

3

您可以使用GetUserName

#include <windows.h> 
#include <Lmcons.h> 

TCHAR username[UNLEN+1]; 
DWORD len = UNLEN+1; 
if (GetUserName(username, &len)) 
{ 
    //do something with username 
} 
相關問題