diff --git a/win/tclWin32Dll.c b/win/tclWin32Dll.c
index 14edce5..0d27377 100644
--- a/win/tclWin32Dll.c
+++ b/win/tclWin32Dll.c
@@ -124,7 +124,8 @@ static TclWinProcs asciiProcs = {
     NULL, NULL, NULL, NULL, NULL, NULL,
     /* ReadConsole and WriteConsole */
     (BOOL (WINAPI *)(HANDLE, LPVOID, DWORD, LPDWORD, LPVOID)) ReadConsoleA,
-    (BOOL (WINAPI *)(HANDLE, const void*, DWORD, LPDWORD, LPVOID)) WriteConsoleA
+    (BOOL (WINAPI *)(HANDLE, const void*, DWORD, LPDWORD, LPVOID)) WriteConsoleA,
+    (BOOL (WINAPI *)(LPTSTR, LPDWORD)) GetUserNameA
 };
 
 static TclWinProcs unicodeProcs = {
@@ -182,7 +183,8 @@ static TclWinProcs unicodeProcs = {
     NULL, NULL, NULL, NULL, NULL, NULL,
     /* ReadConsole and WriteConsole */
     (BOOL (WINAPI *)(HANDLE, LPVOID, DWORD, LPDWORD, LPVOID)) ReadConsoleW,
-    (BOOL (WINAPI *)(HANDLE, const void*, DWORD, LPDWORD, LPVOID)) WriteConsoleW
+    (BOOL (WINAPI *)(HANDLE, const void*, DWORD, LPDWORD, LPVOID)) WriteConsoleW,
+    (BOOL (WINAPI *)(LPTSTR, LPDWORD))GetUserNameW
 };
 
 TclWinProcs *tclWinProcs;
diff --git a/win/tclWinInit.c b/win/tclWinInit.c
index 88bd81e..b8bcbec 100644
--- a/win/tclWinInit.c
+++ b/win/tclWinInit.c
@@ -503,8 +503,8 @@ TclpSetVariables(
     OemId *oemId;
     OSVERSIONINFOA osInfo;
     Tcl_DString ds;
-    TCHAR szUserName[UNLEN+1];
-    DWORD dwUserNameLen = sizeof(szUserName);
+    WCHAR szUserName[UNLEN+1];
+    DWORD cchUserNameLen = UNLEN;
 
     Tcl_SetVar2Ex(interp, "tclDefaultLibrary", NULL,
 	    TclGetProcessGlobalValue(&defaultLibraryDir), TCL_GLOBAL_ONLY);
@@ -573,12 +573,15 @@ TclpSetVariables(
     /*
      * Initialize the user name from the environment first, since this is much
      * faster than asking the system.
+     * Note: cchUserNameLen is number of characters including nul terminator.
      */
 
     Tcl_DStringInit(&ds);
     if (TclGetEnv("USERNAME", &ds) == NULL) {
-	if (GetUserName(szUserName, &dwUserNameLen) != 0) {
-	    Tcl_WinTCharToUtf(szUserName, (int) dwUserNameLen, &ds);
+	if (tclWinProcs->getUserName((LPTSTR)szUserName, &cchUserNameLen) != 0) {
+	    int cbUserNameLen = cchUserNameLen - 1;
+	    if (tclWinProcs->useWide) cbUserNameLen *= sizeof(WCHAR);
+	    Tcl_WinTCharToUtf((LPTSTR)szUserName, cbUserNameLen, &ds);
 	}
     }
     Tcl_SetVar2(interp, "tcl_platform", "user", Tcl_DStringValue(&ds),
diff --git a/win/tclWinInt.h b/win/tclWinInt.h
index fa65587..b098c9e 100644
--- a/win/tclWinInt.h
+++ b/win/tclWinInt.h
@@ -144,6 +144,7 @@ typedef struct TclWinProcs {
       LPDWORD lpNumberOfCharsWritten,
       LPVOID lpReserved
     );
+    BOOL (WINAPI *getUserName)(LPTSTR lpBuffer, LPDWORD lpnSize);
 } TclWinProcs;
 
 MODULE_SCOPE TclWinProcs *tclWinProcs;
