-#if defined(__WIN32__) && !defined(__win32s__) && 0
- // Gets the current user's full name according to the MS article PSS ID
- // Number: Q119670
- // Seems to be the same as the login name for me?
- char *UserName = new char[256];
- char *Domain = new char[256];
- DWORD maxCharacters = 255;
- GetUserName( UserName, &maxCharacters );
- GetComputerName( Domain, &maxCharacters );
-
- WCHAR wszUserName[256]; // Unicode user name
- WCHAR wszDomain[256];
- LPBYTE ComputerName;
-
- struct _SERVER_INFO_100 *si100; // Server structure
- struct _USER_INFO_2 *ui; // User structure
-
- // Convert ASCII user name and domain to Unicode.
-
- MultiByteToWideChar( CP_ACP, 0, UserName,
- strlen(UserName)+1, wszUserName, sizeof(wszUserName) );
- MultiByteToWideChar( CP_ACP, 0, Domain,
- strlen(Domain)+1, wszDomain, sizeof(wszDomain) );
-
- // Get the computer name of a DC for the specified domain.
- // >If you get a link error on this, include netapi32.lib<
-
- NetGetDCName( NULL, wszDomain, &ComputerName );
-
- // Look up the user on the DC.
-
- if(NetUserGetInfo( (LPWSTR) ComputerName,
- (LPWSTR) &wszUserName, 2, (LPBYTE *) &ui))
- {
- printf( "Error getting user information.\n" );
- return( FALSE );
- }
-
- // Convert the Unicode full name to ASCII.
-
- WideCharToMultiByte( CP_ACP, 0, ui->usri2_full_name,
- -1, buf, 256, NULL, NULL );
- }
- return( TRUE );
-/*
- DWORD nSize = maxSize;
- return ::GetUserName(buf, &nSize);
-*/
-#else
- char *user;
- const char *default_id = "anonymous";
-
- // Can't assume we have NIS (PC-NFS) or some other ID daemon
- // So we ...
- if ( (user = getenv("USER")) == NULL &&
- (user = getenv("LOGNAME")) == NULL ) {
- // Use wxWindows configuration data (comming soon)
- GetProfileString(WX_SECTION, eUSERID, default_id, buf, maxSize - 1);
- } else
- strncpy(buf, user, maxSize - 1);
- return *buf ? TRUE : FALSE;
+#if defined(__WXWINCE__)
+ return FALSE;
+#elif defined(__WIN32__) && !defined(__win32s__) && !defined(__WXMICROWIN__)
+ DWORD nSize = maxSize;
+ if ( ::GetUserName(buf, &nSize) == 0 )
+ {
+ // actually, it does happen on Win9x if the user didn't log on
+ DWORD res = ::GetEnvironmentVariable(wxT("username"), buf, maxSize);
+ if ( res == 0 )
+ {
+ // not found
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+#else // Win16 or Win32s
+ wxChar *user;
+ const wxChar *default_id = wxT("anonymous");
+
+ // Can't assume we have NIS (PC-NFS) or some other ID daemon
+ // So we ...
+ if ( (user = wxGetenv(wxT("USER"))) == NULL &&
+ (user = wxGetenv(wxT("LOGNAME"))) == NULL )
+ {
+ // Use wxWindows configuration data (comming soon)
+ GetProfileString(WX_SECTION, eUSERID, default_id, buf, maxSize - 1);
+ }
+ else
+ {
+ wxStrncpy(buf, user, maxSize - 1);
+ }
+
+ return *buf ? TRUE : FALSE;