Unix to Windows Porting Dictionary for HPC

Links

Function List

getlogin


Unix

header file: unistd.h

char *getlogin(void);

Windows

header file: Windows.h

BOOL WINAPI GetUserName(__out LPTSTR lpBuffer, __inout LPDWORD lpnSize);

Purpose

This function retrieves the name of the current user.

Discussion

The GetUserName function will provide the same information as the Unix getlogin() function, but with a slightly different format. Instead of returning the unsername, GetUserName stores it in the parameter lpBuffer. It also requires a second parameter, lpnSize, that specifies the size of lpBuffer. For complete details, see the MSDN article.

Example of Use in Windows

#include <Winsock2.h>

char* buffer[256];

if (GetUserName(buffer, 256) == 0)
  printf("The local username is %s.", buffer);
else
  printf("GetUserName error.");
  
blog comments powered by Disqus