shithub: choc

Download patch

ref: 9fc871cdc51ddc335db803abae91eda42efdb2ed
parent: c80600ef2c0ded9c51ebd0f169972149956d939b
author: Simon Howard <fraggle@gmail.com>
date: Fri Jun 12 13:35:39 EDT 2009

Set the USER environment variable based on the owner information from
the registry.

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 1598

--- a/wince/env.c
+++ b/wince/env.c
@@ -40,17 +40,48 @@
     putenv(value);
 }
 
+static int ReadOwnerName(wchar_t *value, DWORD len)
+{
+    HKEY key;
+    DWORD valtype;
+
+    if (RegOpenKeyExW(HKEY_CURRENT_USER,
+                      L"\\ControlPanel\\Owner", 0,
+                      KEY_READ, &key) != ERROR_SUCCESS)
+    {
+        MessageBoxW(NULL, L"Can't open owner", L"Error", MB_OK);
+        return 0;
+    }
+
+    valtype = REG_SZ;
+
+    if (RegQueryValueExW(key, L"Name", NULL, &valtype,
+                         (LPBYTE) value, &len) != ERROR_SUCCESS)
+    {
+        MessageBoxW(NULL, L"Can't read owner", L"Error", MB_OK);
+        return 0;
+    }
+
+    MessageBoxW(NULL, value, L"Error", MB_OK);
+
+    // Close the key
+
+    RegCloseKey(key);
+
+    return 1;
+}
+
 void PopulateEnvironment(void)
 {
     wchar_t temp[MAX_PATH];
-    DWORD buf_len;
 
     // Username:
 
-    buf_len = UNLEN;
-    GetUserNameExW(NameDisplay, temp, &buf_len);
-    SetEnvironment("USER=", temp);
-    SetEnvironment("USERNAME=", temp);
+    if (ReadOwnerName(temp, MAX_PATH))
+    {
+        SetEnvironment("USER=", temp);
+        SetEnvironment("USERNAME=", temp);
+    }
 
     // Temp dir: