msi: Set the USERNAME and COMPANYNAME properties when initializing a package [RESEND]

James Hawkins truiken at gmail.com
Wed Oct 18 13:26:49 CDT 2006


Hi,

Is there anything wrong with this patch?  It fixes bug 6042.
http://bugs.winehq.org/show_bug.cgi?id=6042

Changelog:
* Set the USERNAME and COMPANYNAME properties when initializing a package.

 dlls/msi/package.c       |   41 +++++++++++++++++++++++++++++++++++++++++
 dlls/msi/tests/package.c |   26 +++++++++++++++++++++++++-
 2 files changed, 66 insertions(+), 1 deletions(-)

-- 
James Hawkins
-------------- next part --------------
diff --git a/dlls/msi/package.c b/dlls/msi/package.c
index aae868c..3aaad69 100644
--- a/dlls/msi/package.c
+++ b/dlls/msi/package.c
@@ -141,6 +141,9 @@ static VOID set_installer_properties(MSI
     DWORD verval;
     WCHAR verstr[10], bufstr[20];
     HDC dc;
+    LPWSTR check;
+    HKEY hkey;
+    LONG res;
 
     static const WCHAR cszbs[]={'\\',0};
     static const WCHAR CFF[] = 
@@ -210,6 +213,18 @@ static VOID set_installer_properties(MSI
     static const WCHAR szScreenFormat[] = {'%','d',0};
     static const WCHAR szIntel[] = { 'I','n','t','e','l',0 };
     static const WCHAR szAllUsers[] = { 'A','L','L','U','S','E','R','S',0 };
+    static const WCHAR szCurrentVersion[] = {
+        'S','O','F','T','W','A','R','E','\\',
+        'M','i','c','r','o','s','o','f','t','\\',
+        'W','i','n','d','o','w','s',' ','N','T','\\',
+        'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0
+    };
+    static const WCHAR szRegisteredUser[] = {'R','e','g','i','s','t','e','r','e','d','O','w','n','e','r',0};
+    static const WCHAR szRegisteredOrg[] = {
+        'R','e','g','i','s','t','e','r','e','d','O','r','g','a','n','i','z','a','t','i','o','n',0
+    };
+    static const WCHAR szUSERNAME[] = {'U','S','E','R','N','A','M','E',0};
+    static const WCHAR szCOMPANYNAME[] = {'C','O','M','P','A','N','Y','N','A','M','E',0};
     SYSTEM_INFO sys_info;
 
     /*
@@ -353,6 +368,32 @@ static VOID set_installer_properties(MSI
     sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, BITSPIXEL ));
     MSI_SetPropertyW( package, szColorBits, bufstr );
     ReleaseDC(0, dc);
+
+    /* USERNAME and COMPANYNAME */
+    res = RegOpenKeyW( HKEY_LOCAL_MACHINE, szCurrentVersion, &hkey );
+    if (res != ERROR_SUCCESS)
+        return;
+
+    check = msi_dup_property( package, szUSERNAME );
+    if (!check)
+    {
+        LPWSTR user = msi_reg_get_val_str( hkey, szRegisteredUser );
+        MSI_SetPropertyW( package, szUSERNAME, user );
+        msi_free( user );
+    }
+
+    msi_free( check );
+
+    check = msi_dup_property( package, szCOMPANYNAME );
+    if (!check)
+    {
+        LPWSTR company = msi_reg_get_val_str( hkey, szRegisteredOrg );
+        MSI_SetPropertyW( package, szCOMPANYNAME, company );
+        msi_free( company );
+    }
+
+    msi_free( check );
+    CloseHandle( hkey );
 }
 
 static UINT msi_get_word_count( MSIPACKAGE *package )
diff --git a/dlls/msi/tests/package.c b/dlls/msi/tests/package.c
index cdb71f6..f507451 100644
--- a/dlls/msi/tests/package.c
+++ b/dlls/msi/tests/package.c
@@ -2706,7 +2706,8 @@ static void test_installprops(void)
     MSIHANDLE hpkg, hdb;
     CHAR path[MAX_PATH];
     CHAR buf[MAX_PATH];
-    DWORD size;
+    DWORD size, type;
+    HKEY hkey;
     UINT r;
 
     GetCurrentDirectory(MAX_PATH, path);
@@ -2725,7 +2726,30 @@ static void test_installprops(void)
     r = MsiGetProperty(hpkg, "DATABASE", buf, &size);
     ok( r == ERROR_SUCCESS, "failed to get property: %d\n", r);
     ok( !lstrcmp(buf, path), "Expected %s, got %s\n", path, buf);
+
+    RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", &hkey);
+
+    size = MAX_PATH;
+    type = REG_SZ;
+    RegQueryValueEx(hkey, "RegisteredOwner", NULL, &type, (LPBYTE)path, &size);
+
+    size = MAX_PATH;
+    r = MsiGetProperty(hpkg, "USERNAME", buf, &size);
+    ok( r == ERROR_SUCCESS, "failed to get property: %d\n", r);
+    ok( !lstrcmp(buf, path), "Expected %s, got %s\n", path, buf);
+
+    size = MAX_PATH;
+    type = REG_SZ;
+    RegQueryValueEx(hkey, "RegisteredOrganization", NULL, &type, (LPBYTE)path, &size);
+
+    size = MAX_PATH;
+    r = MsiGetProperty(hpkg, "COMPANYNAME", buf, &size);
+    ok( r == ERROR_SUCCESS, "failed to get property: %d\n", r);
+    ok( !lstrcmp(buf, path), "Expected %s, got %s\n", path, buf);
+
+    CloseHandle(hkey);
     MsiCloseHandle(hpkg);
+    DeleteFile(msifile);
 }
 
 static void test_sourcedirprop(void)
-- 
1.4.2.1


More information about the wine-patches mailing list