diff --git a/dlls/msi/action.c b/dlls/msi/action.c index ef57728..c614e32 100644 --- a/dlls/msi/action.c +++ b/dlls/msi/action.c @@ -4319,7 +4319,11 @@ static UINT ACTION_RegisterUser(MSIPACKAGE *package) if (!productid) return ERROR_SUCCESS; - rc = MSIREG_OpenCurrentUserInstallProps(package->ProductCode, &hkey, TRUE); + if (package->Context == MSIINSTALLCONTEXT_MACHINE) + rc = MSIREG_OpenLocalSystemInstallProps(package->ProductCode, &hkey, TRUE); + else + rc = MSIREG_OpenCurrentUserInstallProps(package->ProductCode, &hkey, TRUE); + if (rc != ERROR_SUCCESS) goto end; diff --git a/dlls/msi/tests/install.c b/dlls/msi/tests/install.c index 3d8296f..5b5b13c 100644 --- a/dlls/msi/tests/install.c +++ b/dlls/msi/tests/install.c @@ -1400,6 +1400,27 @@ static void write_file(const CHAR *filename, const char *data, int data_size) CloseHandle(hf); } +static void get_user_sid(LPSTR *usersid) +{ + HANDLE token; + BYTE buf[1024]; + DWORD size; + PTOKEN_USER user; + HMODULE hadvapi32 = GetModuleHandleA("advapi32.dll"); + static BOOL (WINAPI *pConvertSidToStringSidA)(PSID, LPSTR*); + + *usersid = NULL; + pConvertSidToStringSidA = (void *)GetProcAddress(hadvapi32, "ConvertSidToStringSidA"); + if (!pConvertSidToStringSidA) + return; + + OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token); + size = sizeof(buf); + GetTokenInformation(token, TokenUser, (void *)buf, size, &size); + user = (PTOKEN_USER)buf; + pConvertSidToStringSidA(user->User.Sid, usersid); +} + static void write_msi_summary_info(MSIHANDLE db) { MSIHANDLE summary; @@ -2589,24 +2610,86 @@ static void test_publish_publishfeatures(void) delete_pfmsitest_files(); } +static LPSTR reg_get_val_str(HKEY hkey, LPCSTR name) +{ + DWORD len = 0; + LPSTR val; + LONG r; + + r = RegQueryValueExA(hkey, name, NULL, NULL, NULL, &len); + if (r != ERROR_SUCCESS) + return NULL; + + len += sizeof (WCHAR); + val = HeapAlloc(GetProcessHeap(), 0, len); + if (!val) return NULL; + val[0] = 0; + RegQueryValueExA(hkey, name, NULL, NULL, (LPBYTE)val, &len); + return val; +} + +static void get_owner_company(LPSTR *owner, LPSTR *company) +{ + LONG res; + HKEY hkey; + + *owner = *company = NULL; + + res = RegOpenKeyA(HKEY_CURRENT_USER, + "Software\\Microsoft\\MS Setup (ACME)\\User Info", &hkey); + if (res == ERROR_SUCCESS) + { + *owner = reg_get_val_str(hkey, "DefName"); + *company = reg_get_val_str(hkey, "DefCompany"); + RegCloseKey(hkey); + } + + if (!*owner || !*company) + { + res = RegOpenKeyA(HKEY_LOCAL_MACHINE, + "Software\\Microsoft\\Windows\\CurrentVersion", &hkey); + if (res == ERROR_SUCCESS) + { + *owner = reg_get_val_str(hkey, "RegisteredOwner"); + *company = reg_get_val_str(hkey, "RegisteredOrganization"); + RegCloseKey(hkey); + } + } + + if (!*owner || !*company) + { + res = RegOpenKeyA(HKEY_LOCAL_MACHINE, + "Software\\Microsoft\\Windows NT\\CurrentVersion", &hkey); + if (res == ERROR_SUCCESS) + { + *owner = reg_get_val_str(hkey, "RegisteredOwner"); + *company = reg_get_val_str(hkey, "RegisteredOrganization"); + RegCloseKey(hkey); + } + } +} + static void test_publish_registeruser(void) { UINT r; LONG res; - HKEY uninstall, prodkey; - INSTALLSTATE state; - CHAR prodcode[] = "{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}"; + HKEY props; + LPSTR usersid; + LPSTR owner, company; + CHAR keypath[MAX_PATH]; - static const CHAR subkey[] = "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall"; + static const CHAR keyfmt[] = + "Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\" + "UserData\\%s\\Products\\84A88FD7F6998CE40A22FB59F6B9C2BB\\InstallProperties"; - if (!pMsiQueryComponentStateA) + get_user_sid(&usersid); + if (!usersid) { - skip("MsiQueryComponentStateA is not available\n"); + skip("ConvertSidToStringSidA is not available\n"); return; } - res = RegOpenKeyA(HKEY_LOCAL_MACHINE, subkey, &uninstall); - ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res); + get_owner_company(&owner, &company); CreateDirectoryA("msitest", NULL); create_file("msitest\\maximus", 500); @@ -2615,107 +2698,54 @@ static void test_publish_registeruser(void) MsiSetInternalUI(INSTALLUILEVEL_FULL, NULL); - state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}"); - ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state); - - state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature"); - ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state); - - state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo"); - ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state); - - r = pMsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED, - "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state); - ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r); - ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state); - - res = RegOpenKeyA(uninstall, prodcode, &prodkey); - ok(res == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", res); - - /* RegisterUser */ + /* RegisterUser, per-user */ r = MsiInstallProductA(msifile, "REGISTER_USER=1"); ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r); - ok(pf_exists("msitest\\maximus"), "File not installed\n"); - ok(pf_exists("msitest"), "File not installed\n"); - - state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}"); - todo_wine - { - ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state); - } - - state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature"); - ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state); + ok(delete_pf("msitest\\maximus", TRUE), "File not installed\n"); + ok(delete_pf("msitest", FALSE), "File not installed\n"); - state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo"); - ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state); + sprintf(keypath, keyfmt, usersid); - r = pMsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED, - "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state); - ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r); - ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state); + res = RegOpenKeyA(HKEY_LOCAL_MACHINE, keypath, &props); + ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res); - res = RegOpenKeyA(uninstall, prodcode, &prodkey); - ok(res == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", res); + CHECK_REG_STR(props, "ProductID", "none"); + CHECK_REG_STR(props, "RegCompany", company); + CHECK_REG_STR(props, "RegOwner", owner); - /* try to uninstall after RegisterUser */ - r = MsiInstallProductA(msifile, "REMOVE=ALL"); - todo_wine - { - ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r); - } - ok(pf_exists("msitest\\maximus"), "File deleted\n"); - ok(pf_exists("msitest"), "File deleted\n"); + RegDeleteValueA(props, "ProductID"); + RegDeleteValueA(props, "RegCompany"); + RegDeleteValueA(props, "RegOwner"); + RegDeleteKeyA(props, ""); + RegCloseKey(props); - state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}"); - ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state); + /* RegisterUser, machine */ + r = MsiInstallProductA(msifile, "REGISTER_USER=1 ALLUSERS=1"); + ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r); + ok(delete_pf("msitest\\maximus", TRUE), "File not installed\n"); + ok(delete_pf("msitest", FALSE), "File not installed\n"); - state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature"); - ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state); + sprintf(keypath, keyfmt, "S-1-5-18"); - state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo"); - ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state); + res = RegOpenKeyA(HKEY_LOCAL_MACHINE, keypath, &props); + ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res); - r = pMsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED, - "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state); - ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r); - ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state); + CHECK_REG_STR(props, "ProductID", "none"); + CHECK_REG_STR(props, "RegCompany", company); + CHECK_REG_STR(props, "RegOwner", owner); - res = RegOpenKeyA(uninstall, prodcode, &prodkey); - ok(res == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", res); + RegDeleteValueA(props, "ProductID"); + RegDeleteValueA(props, "RegCompany"); + RegDeleteValueA(props, "RegOwner"); + RegDeleteKeyA(props, ""); + RegCloseKey(props); - /* full install to remove */ - r = MsiInstallProductA(msifile, "FULL=1"); - ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r); - r = MsiInstallProductA(msifile, "FULL=1 REMOVE=ALL"); - ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r); + HeapFree(GetProcessHeap(), 0, company); + HeapFree(GetProcessHeap(), 0, owner); - RegCloseKey(uninstall); DeleteFile(msifile); DeleteFile("msitest\\maximus"); RemoveDirectory("msitest"); - delete_pfmsitest_files(); -} - -static void get_user_sid(LPSTR *usersid) -{ - HANDLE token; - BYTE buf[1024]; - DWORD size; - PTOKEN_USER user; - HMODULE hadvapi32 = GetModuleHandleA("advapi32.dll"); - static BOOL (WINAPI *pConvertSidToStringSidA)(PSID, LPSTR*); - - *usersid = NULL; - pConvertSidToStringSidA = (void *)GetProcAddress(hadvapi32, "ConvertSidToStringSidA"); - if (!pConvertSidToStringSidA) - return; - - OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token); - size = sizeof(buf); - GetTokenInformation(token, TokenUser, (void *)buf, size, &size); - user = (PTOKEN_USER)buf; - pConvertSidToStringSidA(user->User.Sid, usersid); } static void test_publish_processcomponents(void) -- 1.5.4.3