|
1 |
| - |
2 | 1 | #define WIN32_LEAN_AND_MEAN
|
3 | 2 |
|
4 | 3 | #include <windows.h>
|
5 | 4 | #include <msiquery.h>
|
6 | 5 | #include <wcautil.h>
|
7 | 6 |
|
| 7 | +#define GUID_BUFFER_SIZE 39 // {8-4-4-4-12}\0 |
| 8 | + |
| 9 | + |
| 10 | +UINT WINAPI SetInstallScope(MSIHANDLE hInstall) { |
| 11 | + HRESULT hr = S_OK; |
| 12 | + UINT er = ERROR_SUCCESS; |
| 13 | + TCHAR upgrade_code[GUID_BUFFER_SIZE]; |
| 14 | + DWORD upgrade_code_len = GUID_BUFFER_SIZE; |
| 15 | + DWORD iProductIndex; |
| 16 | + TCHAR product_code[GUID_BUFFER_SIZE]; |
| 17 | + TCHAR assignment_type[2]; |
| 18 | + DWORD assignment_type_len = 2; |
| 19 | + |
| 20 | + hr = WcaInitialize(hInstall, "SetInstallScope"); |
| 21 | + ExitOnFailure(hr, "Failed to initialize"); |
| 22 | + |
| 23 | + er = MsiGetProperty(hInstall, TEXT("UpgradeCode"), upgrade_code, |
| 24 | + &upgrade_code_len); |
| 25 | + ExitOnWin32Error(er, hr, "Failed to get UpgradeCode property"); |
| 26 | + |
| 27 | + for (iProductIndex = 0;; iProductIndex++) { |
| 28 | + er = MsiEnumRelatedProducts(upgrade_code, 0, iProductIndex, product_code); |
| 29 | + if (er == ERROR_NO_MORE_ITEMS) break; |
| 30 | + ExitOnWin32Error(er, hr, "Failed to get related product code"); |
| 31 | + |
| 32 | + er = MsiGetProductInfo(product_code, INSTALLPROPERTY_ASSIGNMENTTYPE, |
| 33 | + assignment_type, &assignment_type_len); |
| 34 | + ExitOnWin32Error(er, hr, "Failed to get the assignment type property " |
| 35 | + "from related product"); |
| 36 | + |
| 37 | + // '0' = per-user; '1' = per-machine |
| 38 | + if (assignment_type[0] == '0') { |
| 39 | + /* When old versions which were installed as per-user are detected, the |
| 40 | + * installation scope has to be set to per-user to be able to do an |
| 41 | + * upgrade. If not, two versions will be installed side-by-side: one as |
| 42 | + * per-user and the other as per-machine. |
| 43 | + * |
| 44 | + * If we wanted to disable backward compatibility, the installer should |
| 45 | + * abort here, and request the previous version to be manually |
| 46 | + * uninstalled before installing this one. |
| 47 | + */ |
| 48 | + er = MsiSetProperty(hInstall, TEXT("ALLUSERS"), TEXT("")); |
| 49 | + ExitOnWin32Error(er, hr, "Failed to set the install scope to per-user"); |
| 50 | + break; |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | +LExit: |
| 55 | + return WcaFinalize(ERROR_SUCCESS); |
| 56 | +} |
| 57 | + |
8 | 58 |
|
9 | 59 | UINT WINAPI BroadcastEnvironmentUpdate(MSIHANDLE hInstall) {
|
10 | 60 | HRESULT hr = S_OK;
|
|
0 commit comments