2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2005 Mike McCormack for CodeWeavers
5 * Copyright 2005 Aric Stewart for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #define NONAMELESSUNION
32 #include "wine/debug.h"
36 #include "wine/unicode.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
44 * This module will be all the helper functions for registry access by the
48 static const WCHAR szUserDataFeatures_fmt
[] = {
49 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
50 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
51 'I','n','s','t','a','l','l','e','r','\\','U','s','e','r','D','a','t','a','\\',
52 '%','s','\\','P','r','o','d','u','c','t','s','\\','%','s','\\','F','e','a','t','u','r','e','s',0};
54 static const WCHAR szUserDataComp_fmt
[] = {
55 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
56 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
57 'I','n','s','t','a','l','l','e','r','\\','U','s','e','r','D','a','t','a','\\',
58 '%','s','\\','C','o','m','p','o','n','e','n','t','s','\\','%','s',0};
60 static const WCHAR szUserDataComponents_fmt
[] = {
61 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
62 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
63 'I','n','s','t','a','l','l','e','r','\\','U','s','e','r','D','a','t','a','\\',
64 '%','s','\\','C','o','m','p','o','n','e','n','t','s',0};
66 static const WCHAR szUserDataProd_fmt
[] = {
67 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
68 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
69 'I','n','s','t','a','l','l','e','r','\\','U','s','e','r','D','a','t','a','\\',
70 '%','s','\\','P','r','o','d','u','c','t','s','\\','%','s',0};
72 static const WCHAR szUserDataProducts_fmt
[] = {
73 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
74 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
75 'I','n','s','t','a','l','l','e','r','\\','U','s','e','r','D','a','t','a','\\',
76 '%','s','\\','P','r','o','d','u','c','t','s',0};
78 static const WCHAR szUserDataPatch_fmt
[] = {
79 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
80 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
81 'I','n','s','t','a','l','l','e','r','\\','U','s','e','r','D','a','t','a','\\',
82 '%','s','\\','P','a','t','c','h','e','s','\\','%','s',0};
84 static const WCHAR szUserDataPatches_fmt
[] = {
85 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
86 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
87 'I','n','s','t','a','l','l','e','r','\\','U','s','e','r','D','a','t','a','\\',
88 '%','s','\\','P','a','t','c','h','e','s',0};
90 static const WCHAR szUserDataProductPatches_fmt
[] = {
91 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
92 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
93 'I','n','s','t','a','l','l','e','r','\\','U','s','e','r','D','a','t','a','\\',
94 '%','s','\\','P','r','o','d','u','c','t','s','\\','%','s','\\','P','a','t','c','h','e','s',0};
96 static const WCHAR szInstallProperties_fmt
[] = {
97 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
98 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
99 'I','n','s','t','a','l','l','e','r','\\','U','s','e','r','D','a','t','a','\\',
100 '%','s','\\','P','r','o','d','u','c','t','s','\\','%','s','\\',
101 'I','n','s','t','a','l','l','P','r','o','p','e','r','t','i','e','s',0};
103 static const WCHAR szInstaller_LocalManagedProd_fmt
[] = {
104 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
105 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
106 'I','n','s','t','a','l','l','e','r','\\','M','a','n','a','g','e','d','\\','%','s','\\',
107 'I','n','s','t','a','l','l','e','r','\\','P','r','o','d','u','c','t','s','\\','%','s',0};
109 static const WCHAR szInstaller_LocalManagedFeat_fmt
[] = {
110 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
111 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
112 'I','n','s','t','a','l','l','e','r','\\','M','a','n','a','g','e','d','\\','%','s','\\',
113 'I','n','s','t','a','l','l','e','r','\\','F','e','a','t','u','r','e','s','\\','%','s',0};
115 static const WCHAR szInstaller_Products
[] = {
116 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
117 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
118 'I','n','s','t','a','l','l','e','r','\\','P','r','o','d','u','c','t','s',0};
120 static const WCHAR szInstaller_Patches
[] = {
121 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
122 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
123 'I','n','s','t','a','l','l','e','r','\\','P','a','t','c','h','e','s',0};
125 static const WCHAR szInstaller_LocalClassesProducts
[] = {
126 'S','o','f','t','w','a','r','e','\\','C','l','a','s','s','e','s','\\',
127 'I','n','s','t','a','l','l','e','r','\\','P','r','o','d','u','c','t','s',0};
129 static const WCHAR szInstaller_LocalClassesFeatures
[] = {
130 'S','o','f','t','w','a','r','e','\\','C','l','a','s','s','e','s','\\',
131 'I','n','s','t','a','l','l','e','r','\\','F','e','a','t','u','r','e','s',0};
133 static const WCHAR szInstaller_LocalClassesProd
[] = {
134 'S','o','f','t','w','a','r','e','\\','C','l','a','s','s','e','s','\\',
135 'I','n','s','t','a','l','l','e','r','\\','P','r','o','d','u','c','t','s','\\',0};
137 static const WCHAR szInstaller_LocalClassesFeat
[] = {
138 'S','o','f','t','w','a','r','e','\\','C','l','a','s','s','e','s','\\',
139 'I','n','s','t','a','l','l','e','r','\\','F','e','a','t','u','r','e','s','\\',0};
141 static const WCHAR szInstaller_ClassesUpgradeCode
[] = {
142 'S','o','f','t','w','a','r','e','\\','C','l','a','s','s','e','s','\\',
143 'I','n','s','t','a','l','l','e','r','\\','U','p','g','r','a','d','e','C','o','d','e','s','\\',0};
145 static const WCHAR szInstaller_ClassesUpgradeCodes
[] = {
146 'S','o','f','t','w','a','r','e','\\','C','l','a','s','s','e','s','\\',
147 'I','n','s','t','a','l','l','e','r','\\','U','p','g','r','a','d','e','C','o','d','e','s',0};
149 static const WCHAR szInstaller_Features
[] = {
150 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
151 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
152 'I','n','s','t','a','l','l','e','r','\\','F','e','a','t','u','r','e','s','\\',0};
154 static const WCHAR szInstaller_UpgradeCodes
[] = {
155 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
156 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
157 'I','n','s','t','a','l','l','e','r','\\','U','p','g','r','a','d','e','C','o','d','e','s','\\',0};
159 static const WCHAR szInstaller_UserUpgradeCodes
[] = {
160 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
161 'I','n','s','t','a','l','l','e','r','\\','U','p','g','r','a','d','e','C','o','d','e','s','\\',0};
163 static const WCHAR szUninstall
[] = {
164 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
165 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
166 'U','n','i','n','s','t','a','l','l','\\',0};
168 static const WCHAR szUninstall_32node
[] = {
169 'S','o','f','t','w','a','r','e','\\','W','o','w','6','4','3','2','N','o','d','e','\\',
170 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
171 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','U','n','i','n','s','t','a','l','l','\\',0};
173 static const WCHAR szUserComponents
[] = {
174 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
175 'I','n','s','t','a','l','l','e','r','\\','C','o','m','p','o','n','e','n','t','s','\\',0};
177 static const WCHAR szUserFeatures
[] = {
178 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
179 'I','n','s','t','a','l','l','e','r','\\','F','e','a','t','u','r','e','s','\\',0};
181 static const WCHAR szUserProducts
[] = {
182 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
183 'I','n','s','t','a','l','l','e','r','\\','P','r','o','d','u','c','t','s','\\',0};
185 static const WCHAR szUserPatches
[] = {
186 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
187 'I','n','s','t','a','l','l','e','r','\\','P','a','t','c','h','e','s','\\',0};
189 BOOL
unsquash_guid(LPCWSTR in
, LPWSTR out
)
193 if (lstrlenW(in
) != 32)
208 out
[n
++] = in
[17+i
*2];
209 out
[n
++] = in
[16+i
*2];
214 out
[n
++] = in
[17+i
*2];
215 out
[n
++] = in
[16+i
*2];
222 BOOL
squash_guid(LPCWSTR in
, LPWSTR out
)
229 if (FAILED(CLSIDFromString((LPCOLESTR
)in
, &guid
)))
243 out
[17+i
*2] = in
[n
++];
244 out
[16+i
*2] = in
[n
++];
249 out
[17+i
*2] = in
[n
++];
250 out
[16+i
*2] = in
[n
++];
257 /* tables for encoding and decoding base85 */
258 static const unsigned char table_dec85
[0x80] = {
259 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
260 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
261 0xff,0x00,0xff,0xff,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0xff,
262 0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0xff,0xff,0xff,0x16,0xff,0x17,
263 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,
264 0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0xff,0x34,0x35,0x36,
265 0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44,0x45,0x46,
266 0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0xff,0x53,0x54,0xff,
269 static const char table_enc85
[] =
270 "!$%&'()*+,-.0123456789=?@ABCDEFGHIJKLMNO"
271 "PQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwx"
275 * Converts a base85 encoded guid into a GUID pointer
276 * Base85 encoded GUIDs should be 20 characters long.
278 * returns TRUE if successful, FALSE if not
280 BOOL
decode_base85_guid( LPCWSTR str
, GUID
*guid
)
282 DWORD i
, val
= 0, base
= 1, *p
;
288 for( i
=0; i
<20; i
++ )
295 val
+= table_dec85
[str
[i
]] * base
;
298 if( table_dec85
[str
[i
]] == 0xff )
308 * Encodes a base85 guid given a GUID pointer
309 * Caller should provide a 21 character buffer for the encoded string.
311 * returns TRUE if successful, FALSE if not
313 BOOL
encode_base85_guid( GUID
*guid
, LPWSTR str
)
315 unsigned int x
, *p
, i
;
317 p
= (unsigned int*) guid
;
321 *str
++ = table_enc85
[x
%85];
323 *str
++ = table_enc85
[x
%85];
325 *str
++ = table_enc85
[x
%85];
327 *str
++ = table_enc85
[x
%85];
329 *str
++ = table_enc85
[x
%85];
336 DWORD
msi_version_str_to_dword(LPCWSTR p
)
338 DWORD major
, minor
= 0, build
= 0, version
= 0;
349 p
= strchrW(p
+1, '.');
354 return MAKELONG(build
, MAKEWORD(minor
, major
));
357 LONG
msi_reg_set_val_str( HKEY hkey
, LPCWSTR name
, LPCWSTR value
)
360 if (!value
) value
= szEmpty
;
361 len
= (lstrlenW(value
) + 1) * sizeof (WCHAR
);
362 return RegSetValueExW( hkey
, name
, 0, REG_SZ
, (const BYTE
*)value
, len
);
365 LONG
msi_reg_set_val_multi_str( HKEY hkey
, LPCWSTR name
, LPCWSTR value
)
368 while (*p
) p
+= lstrlenW(p
) + 1;
369 return RegSetValueExW( hkey
, name
, 0, REG_MULTI_SZ
,
370 (const BYTE
*)value
, (p
+ 1 - value
) * sizeof(WCHAR
) );
373 LONG
msi_reg_set_val_dword( HKEY hkey
, LPCWSTR name
, DWORD val
)
375 return RegSetValueExW( hkey
, name
, 0, REG_DWORD
, (LPBYTE
)&val
, sizeof (DWORD
) );
378 LONG
msi_reg_set_subkey_val( HKEY hkey
, LPCWSTR path
, LPCWSTR name
, LPCWSTR val
)
383 r
= RegCreateKeyW( hkey
, path
, &hsubkey
);
384 if (r
!= ERROR_SUCCESS
)
386 r
= msi_reg_set_val_str( hsubkey
, name
, val
);
387 RegCloseKey( hsubkey
);
391 LPWSTR
msi_reg_get_val_str( HKEY hkey
, LPCWSTR name
)
397 r
= RegQueryValueExW(hkey
, name
, NULL
, NULL
, NULL
, &len
);
398 if (r
!= ERROR_SUCCESS
)
401 len
+= sizeof (WCHAR
);
402 val
= msi_alloc( len
);
406 RegQueryValueExW(hkey
, name
, NULL
, NULL
, (LPBYTE
) val
, &len
);
410 BOOL
msi_reg_get_val_dword( HKEY hkey
, LPCWSTR name
, DWORD
*val
)
412 DWORD type
, len
= sizeof (DWORD
);
413 LONG r
= RegQueryValueExW(hkey
, name
, NULL
, &type
, (LPBYTE
) val
, &len
);
414 return r
== ERROR_SUCCESS
&& type
== REG_DWORD
;
417 static WCHAR
*get_user_sid(void)
424 if (!OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY
, &token
)) return NULL
;
425 if (!(user
= msi_alloc( size
)))
427 CloseHandle( token
);
430 if (!GetTokenInformation( token
, TokenUser
, user
, size
, &size
))
433 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
|| !(user
= msi_alloc( size
)))
435 CloseHandle( token
);
438 GetTokenInformation( token
, TokenUser
, user
, size
, &size
);
440 CloseHandle( token
);
441 if (!ConvertSidToStringSidW( user
->User
.Sid
, &ret
))
450 UINT
MSIREG_OpenUninstallKey(const WCHAR
*product
, enum platform platform
, HKEY
*key
, BOOL create
)
452 WCHAR keypath
[0x200];
454 TRACE("%s\n", debugstr_w(product
));
456 if (is_64bit
&& platform
== PLATFORM_INTEL
)
458 strcpyW(keypath
, szUninstall_32node
);
459 strcatW(keypath
, product
);
463 strcpyW(keypath
, szUninstall
);
464 strcatW(keypath
, product
);
466 if (create
) return RegCreateKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, key
, NULL
);
467 return RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, KEY_ALL_ACCESS
, key
);
470 UINT
MSIREG_DeleteUninstallKey(const WCHAR
*product
, enum platform platform
)
472 WCHAR keypath
[0x200];
474 TRACE("%s\n", debugstr_w(product
));
476 if (is_64bit
&& platform
== PLATFORM_INTEL
)
478 strcpyW(keypath
, szUninstall_32node
);
479 strcatW(keypath
, product
);
483 strcpyW(keypath
, szUninstall
);
484 strcatW(keypath
, product
);
486 return RegDeleteTreeW(HKEY_LOCAL_MACHINE
, keypath
);
489 UINT
MSIREG_OpenProductKey(LPCWSTR szProduct
, LPCWSTR szUserSid
, MSIINSTALLCONTEXT context
, HKEY
*key
, BOOL create
)
491 LPWSTR usersid
= NULL
;
492 HKEY root
= HKEY_LOCAL_MACHINE
;
493 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
494 WCHAR squished_pc
[GUID_SIZE
], keypath
[MAX_PATH
];
496 if (!squash_guid(szProduct
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
497 TRACE("%s squished %s\n", debugstr_w(szProduct
), debugstr_w(squished_pc
));
499 if (context
== MSIINSTALLCONTEXT_MACHINE
)
501 strcpyW(keypath
, szInstaller_LocalClassesProd
);
502 strcatW(keypath
, squished_pc
);
504 else if (context
== MSIINSTALLCONTEXT_USERUNMANAGED
)
506 root
= HKEY_CURRENT_USER
;
507 strcpyW(keypath
, szUserProducts
);
508 strcatW(keypath
, squished_pc
);
514 if (!(usersid
= get_user_sid()))
516 ERR("Failed to retrieve user SID\n");
517 return ERROR_FUNCTION_FAILED
;
521 sprintfW(keypath
, szInstaller_LocalManagedProd_fmt
, szUserSid
, squished_pc
);
524 if (create
) return RegCreateKeyExW(root
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
525 return RegOpenKeyExW(root
, keypath
, 0, access
, key
);
528 UINT
MSIREG_DeleteUserProductKey(LPCWSTR szProduct
)
530 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
532 if (!squash_guid(szProduct
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
533 TRACE("%s squished %s\n", debugstr_w(szProduct
), debugstr_w(squished_pc
));
535 strcpyW(keypath
, szUserProducts
);
536 strcatW(keypath
, squished_pc
);
537 return RegDeleteTreeW(HKEY_CURRENT_USER
, keypath
);
540 UINT
MSIREG_OpenUserPatchesKey(LPCWSTR szPatch
, HKEY
*key
, BOOL create
)
542 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
544 if (!squash_guid(szPatch
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
545 TRACE("%s squished %s\n", debugstr_w(szPatch
), debugstr_w(squished_pc
));
547 strcpyW(keypath
, szUserPatches
);
548 strcatW(keypath
, squished_pc
);
550 if (create
) return RegCreateKeyW(HKEY_CURRENT_USER
, keypath
, key
);
551 return RegOpenKeyW(HKEY_CURRENT_USER
, keypath
, key
);
554 UINT
MSIREG_OpenFeaturesKey(LPCWSTR szProduct
, LPCWSTR szUserSid
, MSIINSTALLCONTEXT context
,
555 HKEY
*key
, BOOL create
)
557 HKEY root
= HKEY_LOCAL_MACHINE
;
558 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
559 WCHAR squished_pc
[GUID_SIZE
], keypath
[MAX_PATH
], *usersid
= NULL
;
561 if (!squash_guid(szProduct
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
562 TRACE("%s squished %s\n", debugstr_w(szProduct
), debugstr_w(squished_pc
));
564 if (context
== MSIINSTALLCONTEXT_MACHINE
)
566 strcpyW(keypath
, szInstaller_LocalClassesFeat
);
567 strcatW(keypath
, squished_pc
);
569 else if (context
== MSIINSTALLCONTEXT_USERUNMANAGED
)
571 root
= HKEY_CURRENT_USER
;
572 strcpyW(keypath
, szUserFeatures
);
573 strcatW(keypath
, squished_pc
);
579 if (!(usersid
= get_user_sid()))
581 ERR("Failed to retrieve user SID\n");
582 return ERROR_FUNCTION_FAILED
;
586 sprintfW(keypath
, szInstaller_LocalManagedFeat_fmt
, szUserSid
, squished_pc
);
589 if (create
) return RegCreateKeyExW(root
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
590 return RegOpenKeyExW(root
, keypath
, 0, access
, key
);
593 UINT
MSIREG_DeleteUserFeaturesKey(LPCWSTR szProduct
)
595 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
597 if (!squash_guid(szProduct
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
598 TRACE("%s squished %s\n", debugstr_w(szProduct
), debugstr_w(squished_pc
));
600 strcpyW(keypath
, szUserFeatures
);
601 strcatW(keypath
, squished_pc
);
602 return RegDeleteTreeW(HKEY_CURRENT_USER
, keypath
);
605 static UINT
MSIREG_OpenInstallerFeaturesKey(LPCWSTR szProduct
, HKEY
*key
, BOOL create
)
607 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
608 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
610 if (!squash_guid(szProduct
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
611 TRACE("%s squished %s\n", debugstr_w(szProduct
), debugstr_w(squished_pc
));
613 strcpyW(keypath
, szInstaller_Features
);
614 strcatW(keypath
, squished_pc
);
616 if (create
) return RegCreateKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
617 return RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, key
);
620 UINT
MSIREG_OpenUserDataFeaturesKey(LPCWSTR szProduct
, LPCWSTR szUserSid
, MSIINSTALLCONTEXT context
,
621 HKEY
*key
, BOOL create
)
623 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
624 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200], *usersid
= NULL
;
626 if (!squash_guid(szProduct
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
627 TRACE("%s squished %s\n", debugstr_w(szProduct
), debugstr_w(squished_pc
));
629 if (context
== MSIINSTALLCONTEXT_MACHINE
)
631 sprintfW(keypath
, szUserDataFeatures_fmt
, szLocalSid
, squished_pc
);
637 if (!(usersid
= get_user_sid()))
639 ERR("Failed to retrieve user SID\n");
640 return ERROR_FUNCTION_FAILED
;
644 sprintfW(keypath
, szUserDataFeatures_fmt
, szUserSid
, squished_pc
);
647 if (create
) return RegCreateKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
648 return RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, key
);
651 UINT
MSIREG_OpenUserComponentsKey(LPCWSTR szComponent
, HKEY
*key
, BOOL create
)
653 WCHAR squished_cc
[GUID_SIZE
], keypath
[0x200];
655 if (!squash_guid(szComponent
, squished_cc
)) return ERROR_FUNCTION_FAILED
;
656 TRACE("%s squished %s\n", debugstr_w(szComponent
), debugstr_w(squished_cc
));
658 strcpyW(keypath
, szUserComponents
);
659 strcatW(keypath
, squished_cc
);
661 if (create
) return RegCreateKeyW(HKEY_CURRENT_USER
, keypath
, key
);
662 return RegOpenKeyW(HKEY_CURRENT_USER
, keypath
, key
);
665 UINT
MSIREG_OpenUserDataComponentKey(LPCWSTR szComponent
, LPCWSTR szUserSid
, HKEY
*key
, BOOL create
)
667 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
668 WCHAR comp
[GUID_SIZE
], keypath
[0x200];
671 if (!squash_guid(szComponent
, comp
)) return ERROR_FUNCTION_FAILED
;
672 TRACE("%s squished %s\n", debugstr_w(szComponent
), debugstr_w(comp
));
676 if (!(usersid
= get_user_sid()))
678 ERR("Failed to retrieve user SID\n");
679 return ERROR_FUNCTION_FAILED
;
681 sprintfW(keypath
, szUserDataComp_fmt
, usersid
, comp
);
685 sprintfW(keypath
, szUserDataComp_fmt
, szUserSid
, comp
);
687 if (create
) return RegCreateKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
688 return RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, key
);
691 UINT
MSIREG_DeleteUserDataComponentKey(LPCWSTR szComponent
, LPCWSTR szUserSid
)
693 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
694 WCHAR comp
[GUID_SIZE
], keypath
[0x200];
699 if (!squash_guid(szComponent
, comp
)) return ERROR_FUNCTION_FAILED
;
700 TRACE("%s squished %s\n", debugstr_w(szComponent
), debugstr_w(comp
));
704 if (!(usersid
= get_user_sid()))
706 ERR("Failed to retrieve user SID\n");
707 return ERROR_FUNCTION_FAILED
;
709 sprintfW(keypath
, szUserDataComponents_fmt
, usersid
);
713 sprintfW(keypath
, szUserDataComponents_fmt
, szUserSid
);
715 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, &hkey
)) return ERROR_SUCCESS
;
716 r
= RegDeleteTreeW(hkey
, comp
);
721 UINT
MSIREG_OpenUserDataProductKey(LPCWSTR szProduct
, MSIINSTALLCONTEXT dwContext
, LPCWSTR szUserSid
, HKEY
*key
, BOOL create
)
723 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
724 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
727 if (!squash_guid(szProduct
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
728 TRACE("%s squished %s\n", debugstr_w(szProduct
), debugstr_w(squished_pc
));
730 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
731 sprintfW(keypath
, szUserDataProd_fmt
, szLocalSid
, squished_pc
);
733 sprintfW(keypath
, szUserDataProd_fmt
, szUserSid
, squished_pc
);
736 if (!(usersid
= get_user_sid()))
738 ERR("Failed to retrieve user SID\n");
739 return ERROR_FUNCTION_FAILED
;
741 sprintfW(keypath
, szUserDataProd_fmt
, usersid
, squished_pc
);
744 if (create
) return RegCreateKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
745 return RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, key
);
748 UINT
MSIREG_OpenUserDataPatchKey(LPCWSTR szPatch
, MSIINSTALLCONTEXT dwContext
, HKEY
*key
, BOOL create
)
750 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
751 WCHAR squished_patch
[GUID_SIZE
], keypath
[0x200];
754 if (!squash_guid(szPatch
, squished_patch
)) return ERROR_FUNCTION_FAILED
;
755 TRACE("%s squished %s\n", debugstr_w(szPatch
), debugstr_w(squished_patch
));
757 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
758 sprintfW(keypath
, szUserDataPatch_fmt
, szLocalSid
, squished_patch
);
761 if (!(usersid
= get_user_sid()))
763 ERR("Failed to retrieve user SID\n");
764 return ERROR_FUNCTION_FAILED
;
766 sprintfW(keypath
, szUserDataPatch_fmt
, usersid
, squished_patch
);
769 if (create
) return RegCreateKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
770 return RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, key
);
773 UINT
MSIREG_DeleteUserDataPatchKey(LPCWSTR patch
, MSIINSTALLCONTEXT context
)
775 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
776 WCHAR squished_patch
[GUID_SIZE
], keypath
[0x200];
781 if (!squash_guid(patch
, squished_patch
)) return ERROR_FUNCTION_FAILED
;
782 TRACE("%s squished %s\n", debugstr_w(patch
), debugstr_w(squished_patch
));
784 if (context
== MSIINSTALLCONTEXT_MACHINE
)
785 sprintfW(keypath
, szUserDataPatches_fmt
, szLocalSid
);
788 if (!(usersid
= get_user_sid()))
790 ERR("Failed to retrieve user SID\n");
791 return ERROR_FUNCTION_FAILED
;
793 sprintfW(keypath
, szUserDataPatches_fmt
, usersid
);
796 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, &hkey
)) return ERROR_SUCCESS
;
797 r
= RegDeleteTreeW(hkey
, squished_patch
);
802 UINT
MSIREG_OpenUserDataProductPatchesKey(LPCWSTR product
, MSIINSTALLCONTEXT context
, HKEY
*key
, BOOL create
)
804 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
805 WCHAR squished_product
[GUID_SIZE
], keypath
[0x200];
808 if (!squash_guid(product
, squished_product
)) return ERROR_FUNCTION_FAILED
;
809 TRACE("%s squished %s\n", debugstr_w(product
), debugstr_w(squished_product
));
811 if (context
== MSIINSTALLCONTEXT_MACHINE
)
812 sprintfW(keypath
, szUserDataProductPatches_fmt
, szLocalSid
, squished_product
);
815 if (!(usersid
= get_user_sid()))
817 ERR("Failed to retrieve user SID\n");
818 return ERROR_FUNCTION_FAILED
;
820 sprintfW(keypath
, szUserDataProductPatches_fmt
, usersid
, squished_product
);
823 if (create
) return RegCreateKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
824 return RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, key
);
827 UINT
MSIREG_OpenInstallProps(LPCWSTR szProduct
, MSIINSTALLCONTEXT dwContext
, LPCWSTR szUserSid
, HKEY
*key
, BOOL create
)
830 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
831 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
833 if (!squash_guid(szProduct
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
834 TRACE("%s squished %s\n", debugstr_w(szProduct
), debugstr_w(squished_pc
));
836 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
837 sprintfW(keypath
, szInstallProperties_fmt
, szLocalSid
, squished_pc
);
839 sprintfW(keypath
, szInstallProperties_fmt
, szUserSid
, squished_pc
);
842 if (!(usersid
= get_user_sid()))
844 ERR("Failed to retrieve user SID\n");
845 return ERROR_FUNCTION_FAILED
;
847 sprintfW(keypath
, szInstallProperties_fmt
, usersid
, squished_pc
);
850 if (create
) return RegCreateKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
851 return RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, key
);
854 UINT
MSIREG_DeleteUserDataProductKey(LPCWSTR szProduct
)
856 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
857 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
862 if (!squash_guid(szProduct
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
863 TRACE("%s squished %s\n", debugstr_w(szProduct
), debugstr_w(squished_pc
));
865 if (!(usersid
= get_user_sid()))
867 ERR("Failed to retrieve user SID\n");
868 return ERROR_FUNCTION_FAILED
;
870 sprintfW(keypath
, szUserDataProducts_fmt
, usersid
);
873 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, &hkey
)) return ERROR_SUCCESS
;
874 r
= RegDeleteTreeW(hkey
, squished_pc
);
879 UINT
MSIREG_DeleteProductKey(LPCWSTR szProduct
)
881 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
882 WCHAR squished_pc
[GUID_SIZE
];
886 if (!squash_guid(szProduct
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
887 TRACE("%s squished %s\n", debugstr_w(szProduct
), debugstr_w(squished_pc
));
889 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, szInstaller_Products
, 0, access
, &hkey
)) return ERROR_SUCCESS
;
890 r
= RegDeleteTreeW(hkey
, squished_pc
);
895 UINT
MSIREG_OpenPatchesKey(LPCWSTR szPatch
, HKEY
*key
, BOOL create
)
897 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
898 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
900 if (!squash_guid(szPatch
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
901 TRACE("%s squished %s\n", debugstr_w(szPatch
), debugstr_w(squished_pc
));
903 sprintfW(keypath
, szInstaller_Patches
, squished_pc
);
905 if (create
) return RegCreateKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
906 return RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, key
);
909 UINT
MSIREG_OpenUpgradeCodesKey(LPCWSTR szUpgradeCode
, HKEY
*key
, BOOL create
)
911 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
912 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
914 if (!squash_guid(szUpgradeCode
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
915 TRACE("%s squished %s\n", debugstr_w(szUpgradeCode
), debugstr_w(squished_pc
));
917 strcpyW(keypath
, szInstaller_UpgradeCodes
);
918 strcatW(keypath
, squished_pc
);
920 if (create
) return RegCreateKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
921 return RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, key
);
924 UINT
MSIREG_OpenUserUpgradeCodesKey(LPCWSTR szUpgradeCode
, HKEY
* key
, BOOL create
)
926 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
928 if (!squash_guid(szUpgradeCode
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
929 TRACE("%s squished %s\n", debugstr_w(szUpgradeCode
), debugstr_w(squished_pc
));
931 strcpyW(keypath
, szInstaller_UserUpgradeCodes
);
932 strcatW(keypath
, squished_pc
);
934 if (create
) return RegCreateKeyW(HKEY_CURRENT_USER
, keypath
, key
);
935 return RegOpenKeyW(HKEY_CURRENT_USER
, keypath
, key
);
938 UINT
MSIREG_DeleteUserUpgradeCodesKey(LPCWSTR szUpgradeCode
)
940 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
942 if (!squash_guid(szUpgradeCode
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
943 TRACE("%s squished %s\n", debugstr_w(szUpgradeCode
), debugstr_w(squished_pc
));
945 strcpyW(keypath
, szInstaller_UserUpgradeCodes
);
946 strcatW(keypath
, squished_pc
);
947 return RegDeleteTreeW(HKEY_CURRENT_USER
, keypath
);
950 UINT
MSIREG_DeleteLocalClassesProductKey(LPCWSTR szProductCode
)
952 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
953 WCHAR squished_pc
[GUID_SIZE
];
957 if (!squash_guid(szProductCode
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
958 TRACE("%s squished %s\n", debugstr_w(szProductCode
), debugstr_w(squished_pc
));
960 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, szInstaller_LocalClassesProducts
, 0, access
, &hkey
)) return ERROR_SUCCESS
;
961 r
= RegDeleteTreeW(hkey
, squished_pc
);
966 UINT
MSIREG_DeleteLocalClassesFeaturesKey(LPCWSTR szProductCode
)
968 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
969 WCHAR squished_pc
[GUID_SIZE
];
973 if (!squash_guid(szProductCode
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
974 TRACE("%s squished %s\n", debugstr_w(szProductCode
), debugstr_w(squished_pc
));
976 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, szInstaller_LocalClassesFeatures
, 0, access
, &hkey
)) return ERROR_SUCCESS
;
977 r
= RegDeleteTreeW(hkey
, squished_pc
);
982 UINT
MSIREG_OpenClassesUpgradeCodesKey(LPCWSTR szUpgradeCode
, HKEY
*key
, BOOL create
)
984 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
985 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
987 if (!squash_guid(szUpgradeCode
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
988 TRACE("%s squished %s\n", debugstr_w(szUpgradeCode
), debugstr_w(squished_pc
));
990 strcpyW(keypath
, szInstaller_ClassesUpgradeCode
);
991 strcatW(keypath
, squished_pc
);
993 if (create
) return RegCreateKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
994 return RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, key
);
997 UINT
MSIREG_DeleteClassesUpgradeCodesKey(LPCWSTR szUpgradeCode
)
999 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
1000 WCHAR squished_pc
[GUID_SIZE
];
1004 if (!squash_guid(szUpgradeCode
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
1005 TRACE("%s squished %s\n", debugstr_w(szUpgradeCode
), debugstr_w(squished_pc
));
1007 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, szInstaller_ClassesUpgradeCodes
, 0, access
, &hkey
)) return ERROR_SUCCESS
;
1008 r
= RegDeleteTreeW(hkey
, squished_pc
);
1013 /*************************************************************************
1014 * MsiDecomposeDescriptorW [MSI.@]
1016 * Decomposes an MSI descriptor into product, feature and component parts.
1017 * An MSI descriptor is a string of the form:
1018 * [base 85 guid] [feature code] '>' [base 85 guid]
1021 * szDescriptor [I] the descriptor to decompose
1022 * szProduct [O] buffer of MAX_FEATURE_CHARS+1 for the product guid
1023 * szFeature [O] buffer of MAX_FEATURE_CHARS+1 for the feature code
1024 * szComponent [O] buffer of MAX_FEATURE_CHARS+1 for the component guid
1025 * pUsed [O] the length of the descriptor
1028 * ERROR_SUCCESS if everything worked correctly
1029 * ERROR_INVALID_PARAMETER if the descriptor was invalid
1032 UINT WINAPI
MsiDecomposeDescriptorW( LPCWSTR szDescriptor
, LPWSTR szProduct
,
1033 LPWSTR szFeature
, LPWSTR szComponent
, LPDWORD pUsed
)
1037 GUID product
, component
;
1039 TRACE("%s %p %p %p %p\n", debugstr_w(szDescriptor
), szProduct
,
1040 szFeature
, szComponent
, pUsed
);
1042 r
= decode_base85_guid( szDescriptor
, &product
);
1044 return ERROR_INVALID_PARAMETER
;
1046 TRACE("product %s\n", debugstr_guid( &product
));
1048 p
= strchrW(&szDescriptor
[20],'>');
1050 return ERROR_INVALID_PARAMETER
;
1052 len
= (p
- &szDescriptor
[20]);
1053 if( len
> MAX_FEATURE_CHARS
)
1054 return ERROR_INVALID_PARAMETER
;
1056 TRACE("feature %s\n", debugstr_wn( &szDescriptor
[20], len
));
1058 r
= decode_base85_guid( p
+1, &component
);
1060 return ERROR_INVALID_PARAMETER
;
1062 TRACE("component %s\n", debugstr_guid( &component
));
1065 StringFromGUID2( &product
, szProduct
, MAX_FEATURE_CHARS
+1 );
1067 StringFromGUID2( &component
, szComponent
, MAX_FEATURE_CHARS
+1 );
1070 memcpy( szFeature
, &szDescriptor
[20], len
*sizeof(WCHAR
) );
1073 len
= ( &p
[21] - szDescriptor
);
1075 TRACE("length = %d\n", len
);
1076 if (pUsed
) *pUsed
= len
;
1078 return ERROR_SUCCESS
;
1081 UINT WINAPI
MsiDecomposeDescriptorA( LPCSTR szDescriptor
, LPSTR szProduct
,
1082 LPSTR szFeature
, LPSTR szComponent
, LPDWORD pUsed
)
1084 WCHAR product
[MAX_FEATURE_CHARS
+1];
1085 WCHAR feature
[MAX_FEATURE_CHARS
+1];
1086 WCHAR component
[MAX_FEATURE_CHARS
+1];
1087 LPWSTR str
= NULL
, p
= NULL
, f
= NULL
, c
= NULL
;
1090 TRACE("%s %p %p %p %p\n", debugstr_a(szDescriptor
), szProduct
,
1091 szFeature
, szComponent
, pUsed
);
1093 str
= strdupAtoW( szDescriptor
);
1094 if( szDescriptor
&& !str
)
1095 return ERROR_OUTOFMEMORY
;
1104 r
= MsiDecomposeDescriptorW( str
, p
, f
, c
, pUsed
);
1106 if (r
== ERROR_SUCCESS
)
1108 WideCharToMultiByte( CP_ACP
, 0, p
, -1,
1109 szProduct
, MAX_FEATURE_CHARS
+1, NULL
, NULL
);
1110 WideCharToMultiByte( CP_ACP
, 0, f
, -1,
1111 szFeature
, MAX_FEATURE_CHARS
+1, NULL
, NULL
);
1112 WideCharToMultiByte( CP_ACP
, 0, c
, -1,
1113 szComponent
, MAX_FEATURE_CHARS
+1, NULL
, NULL
);
1121 UINT WINAPI
MsiEnumProductsA(DWORD index
, LPSTR lpguid
)
1124 WCHAR szwGuid
[GUID_SIZE
];
1126 TRACE("%d %p\n", index
, lpguid
);
1129 return ERROR_INVALID_PARAMETER
;
1130 r
= MsiEnumProductsW(index
, szwGuid
);
1131 if( r
== ERROR_SUCCESS
)
1132 WideCharToMultiByte(CP_ACP
, 0, szwGuid
, -1, lpguid
, GUID_SIZE
, NULL
, NULL
);
1137 UINT WINAPI
MsiEnumProductsW(DWORD index
, LPWSTR lpguid
)
1139 TRACE("%d %p\n", index
, lpguid
);
1142 return ERROR_INVALID_PARAMETER
;
1144 return MsiEnumProductsExW( NULL
, szAllSid
, MSIINSTALLCONTEXT_ALL
, index
, lpguid
,
1148 UINT WINAPI
MsiEnumFeaturesA(LPCSTR szProduct
, DWORD index
,
1149 LPSTR szFeature
, LPSTR szParent
)
1152 WCHAR szwFeature
[GUID_SIZE
], szwParent
[GUID_SIZE
];
1153 LPWSTR szwProduct
= NULL
;
1155 TRACE("%s %d %p %p\n", debugstr_a(szProduct
), index
, szFeature
, szParent
);
1159 szwProduct
= strdupAtoW( szProduct
);
1161 return ERROR_OUTOFMEMORY
;
1164 r
= MsiEnumFeaturesW(szwProduct
, index
, szwFeature
, szwParent
);
1165 if( r
== ERROR_SUCCESS
)
1167 WideCharToMultiByte(CP_ACP
, 0, szwFeature
, -1,
1168 szFeature
, GUID_SIZE
, NULL
, NULL
);
1169 WideCharToMultiByte(CP_ACP
, 0, szwParent
, -1,
1170 szParent
, GUID_SIZE
, NULL
, NULL
);
1173 msi_free( szwProduct
);
1178 UINT WINAPI
MsiEnumFeaturesW(LPCWSTR szProduct
, DWORD index
,
1179 LPWSTR szFeature
, LPWSTR szParent
)
1181 HKEY hkeyProduct
= 0;
1184 TRACE("%s %d %p %p\n", debugstr_w(szProduct
), index
, szFeature
, szParent
);
1187 return ERROR_INVALID_PARAMETER
;
1189 r
= MSIREG_OpenInstallerFeaturesKey(szProduct
,&hkeyProduct
,FALSE
);
1190 if( r
!= ERROR_SUCCESS
)
1191 return ERROR_NO_MORE_ITEMS
;
1194 r
= RegEnumValueW(hkeyProduct
, index
, szFeature
, &sz
, NULL
, NULL
, NULL
, NULL
);
1195 RegCloseKey(hkeyProduct
);
1200 UINT WINAPI
MsiEnumComponentsA(DWORD index
, LPSTR lpguid
)
1203 WCHAR szwGuid
[GUID_SIZE
];
1205 TRACE("%u, %p\n", index
, lpguid
);
1207 if (!lpguid
) return ERROR_INVALID_PARAMETER
;
1209 r
= MsiEnumComponentsW(index
, szwGuid
);
1210 if( r
== ERROR_SUCCESS
)
1211 WideCharToMultiByte(CP_ACP
, 0, szwGuid
, -1, lpguid
, GUID_SIZE
, NULL
, NULL
);
1216 UINT WINAPI
MsiEnumComponentsW(DWORD index
, LPWSTR lpguid
)
1218 TRACE("%u, %p\n", index
, lpguid
);
1220 if (!lpguid
) return ERROR_INVALID_PARAMETER
;
1222 return MsiEnumComponentsExW( szAllSid
, MSIINSTALLCONTEXT_ALL
, index
, lpguid
, NULL
, NULL
, NULL
);
1225 UINT WINAPI
MsiEnumComponentsExA( LPCSTR user_sid
, DWORD ctx
, DWORD index
, CHAR guid
[39],
1226 MSIINSTALLCONTEXT
*installed_ctx
, LPSTR sid
, LPDWORD sid_len
)
1229 WCHAR
*user_sidW
= NULL
, *sidW
= NULL
, guidW
[GUID_SIZE
];
1231 TRACE("%s, %u, %u, %p, %p, %p, %p\n", debugstr_a(user_sid
), ctx
, index
, guid
, installed_ctx
,
1234 if (sid
&& !sid_len
) return ERROR_INVALID_PARAMETER
;
1235 if (user_sid
&& !(user_sidW
= strdupAtoW( user_sid
))) return ERROR_OUTOFMEMORY
;
1236 if (sid
&& !(sidW
= msi_alloc( *sid_len
* sizeof(WCHAR
) )))
1238 msi_free( user_sidW
);
1239 return ERROR_OUTOFMEMORY
;
1241 r
= MsiEnumComponentsExW( user_sidW
, ctx
, index
, guidW
, installed_ctx
, sidW
, sid_len
);
1242 if (r
== ERROR_SUCCESS
)
1244 if (guid
) WideCharToMultiByte( CP_ACP
, 0, guidW
, GUID_SIZE
, guid
, GUID_SIZE
, NULL
, NULL
);
1245 if (sid
) WideCharToMultiByte( CP_ACP
, 0, sidW
, *sid_len
+ 1, sid
, *sid_len
+ 1, NULL
, NULL
);
1247 msi_free( user_sidW
);
1252 static UINT
fetch_machine_component( DWORD ctx
, DWORD index
, DWORD
*idx
, WCHAR guid
[39],
1253 MSIINSTALLCONTEXT
*installed_ctx
, LPWSTR sid
, LPDWORD sid_len
)
1255 static const WCHAR componentsW
[] =
1256 {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
1257 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1258 'I','n','s','t','a','l','l','e','r','\\','U','s','e','r','D','a','t','a','\\',
1259 'S','-','1','-','5','-','1','8','\\','C','o','m','p','o','n','e','n','t','s',0};
1260 UINT r
= ERROR_SUCCESS
;
1261 WCHAR component
[GUID_SIZE
];
1262 DWORD i
= 0, len_component
;
1263 REGSAM access
= KEY_ENUMERATE_SUB_KEYS
| KEY_WOW64_64KEY
;
1264 HKEY key_components
;
1266 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, componentsW
, 0, access
, &key_components
))
1267 return ERROR_NO_MORE_ITEMS
;
1269 len_component
= sizeof(component
)/sizeof(component
[0]);
1270 while (!RegEnumKeyExW( key_components
, i
, component
, &len_component
, NULL
, NULL
, NULL
, NULL
))
1272 if (*idx
== index
) goto found
;
1274 len_component
= sizeof(component
)/sizeof(component
[0]);
1277 RegCloseKey( key_components
);
1278 return ERROR_NO_MORE_ITEMS
;
1286 r
= ERROR_MORE_DATA
;
1294 if (guid
) unsquash_guid( component
, guid
);
1295 if (installed_ctx
) *installed_ctx
= MSIINSTALLCONTEXT_MACHINE
;
1296 RegCloseKey( key_components
);
1300 static UINT
fetch_user_component( const WCHAR
*usersid
, DWORD ctx
, DWORD index
, DWORD
*idx
,
1301 WCHAR guid
[39], MSIINSTALLCONTEXT
*installed_ctx
, LPWSTR sid
,
1304 static const WCHAR userdataW
[] =
1305 {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
1306 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1307 'I','n','s','t','a','l','l','e','r','\\','U','s','e','r','D','a','t','a',0};
1308 static const WCHAR componentsW
[] = {'\\','C','o','m','p','o','n','e','n','t','s',0};
1309 UINT r
= ERROR_SUCCESS
;
1310 WCHAR path
[MAX_PATH
], component
[GUID_SIZE
], user
[128];
1311 DWORD i
= 0, j
= 0, len_component
, len_user
;
1312 REGSAM access
= KEY_ENUMERATE_SUB_KEYS
| KEY_WOW64_64KEY
;
1313 HKEY key_users
, key_components
;
1315 if (ctx
== MSIINSTALLCONTEXT_USERMANAGED
) /* FIXME: were to find these? */
1316 return ERROR_NO_MORE_ITEMS
;
1318 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, userdataW
, 0, access
, &key_users
))
1319 return ERROR_NO_MORE_ITEMS
;
1321 len_user
= sizeof(user
)/sizeof(user
[0]);
1322 while (!RegEnumKeyExW( key_users
, i
, user
, &len_user
, NULL
, NULL
, NULL
, NULL
))
1324 if ((strcmpW( usersid
, szAllSid
) && strcmpW( usersid
, user
)) ||
1325 !strcmpW( szLocalSid
, user
))
1328 len_user
= sizeof(user
)/sizeof(user
[0]);
1331 strcpyW( path
, user
);
1332 strcatW( path
, componentsW
);
1333 if (RegOpenKeyExW( key_users
, path
, 0, access
, &key_components
))
1336 len_user
= sizeof(user
)/sizeof(user
[0]);
1339 len_component
= sizeof(component
)/sizeof(component
[0]);
1340 while (!RegEnumKeyExW( key_components
, j
, component
, &len_component
, NULL
, NULL
, NULL
, NULL
))
1342 if (*idx
== index
) goto found
;
1344 len_component
= sizeof(component
)/sizeof(component
[0]);
1347 RegCloseKey( key_components
);
1348 len_user
= sizeof(user
)/sizeof(user
[0]);
1351 RegCloseKey( key_users
);
1352 return ERROR_NO_MORE_ITEMS
;
1357 if (*sid_len
< len_user
+ 1)
1359 *sid_len
= len_user
+ 1;
1360 r
= ERROR_MORE_DATA
;
1364 *sid_len
= len_user
;
1365 strcpyW( sid
, user
);
1368 if (guid
) unsquash_guid( component
, guid
);
1369 if (installed_ctx
) *installed_ctx
= ctx
;
1370 RegCloseKey( key_components
);
1371 RegCloseKey( key_users
);
1375 static UINT
enum_components( const WCHAR
*usersid
, DWORD ctx
, DWORD index
, DWORD
*idx
, WCHAR guid
[39],
1376 MSIINSTALLCONTEXT
*installed_ctx
, LPWSTR sid
, LPDWORD sid_len
)
1378 UINT r
= ERROR_NO_MORE_ITEMS
;
1383 usersid
= user
= get_user_sid();
1384 if (!user
) return ERROR_FUNCTION_FAILED
;
1386 if (ctx
& MSIINSTALLCONTEXT_USERMANAGED
)
1388 r
= fetch_user_component( usersid
, MSIINSTALLCONTEXT_USERMANAGED
, index
, idx
, guid
,
1389 installed_ctx
, sid
, sid_len
);
1390 if (r
!= ERROR_NO_MORE_ITEMS
) goto done
;
1392 if (ctx
& MSIINSTALLCONTEXT_USERUNMANAGED
)
1394 r
= fetch_user_component( usersid
, MSIINSTALLCONTEXT_USERUNMANAGED
, index
, idx
, guid
,
1395 installed_ctx
, sid
, sid_len
);
1396 if (r
!= ERROR_NO_MORE_ITEMS
) goto done
;
1398 if (ctx
& MSIINSTALLCONTEXT_MACHINE
)
1400 r
= fetch_machine_component( MSIINSTALLCONTEXT_MACHINE
, index
, idx
, guid
, installed_ctx
,
1402 if (r
!= ERROR_NO_MORE_ITEMS
) goto done
;
1410 UINT WINAPI
MsiEnumComponentsExW( LPCWSTR user_sid
, DWORD ctx
, DWORD index
, WCHAR guid
[39],
1411 MSIINSTALLCONTEXT
*installed_ctx
, LPWSTR sid
, LPDWORD sid_len
)
1415 static DWORD last_index
;
1417 TRACE("%s, %u, %u, %p, %p, %p, %p\n", debugstr_w(user_sid
), ctx
, index
, guid
, installed_ctx
,
1420 if ((sid
&& !sid_len
) || !ctx
|| (user_sid
&& ctx
== MSIINSTALLCONTEXT_MACHINE
))
1421 return ERROR_INVALID_PARAMETER
;
1423 if (index
&& index
- last_index
!= 1)
1424 return ERROR_INVALID_PARAMETER
;
1426 if (!index
) last_index
= 0;
1428 r
= enum_components( user_sid
, ctx
, index
, &idx
, guid
, installed_ctx
, sid
, sid_len
);
1429 if (r
== ERROR_SUCCESS
)
1437 UINT WINAPI
MsiEnumClientsA(LPCSTR szComponent
, DWORD index
, LPSTR szProduct
)
1440 WCHAR szwProduct
[GUID_SIZE
];
1441 LPWSTR szwComponent
= NULL
;
1443 TRACE("%s %d %p\n", debugstr_a(szComponent
), index
, szProduct
);
1446 return ERROR_INVALID_PARAMETER
;
1450 szwComponent
= strdupAtoW( szComponent
);
1452 return ERROR_OUTOFMEMORY
;
1455 r
= MsiEnumClientsW(szComponent
?szwComponent
:NULL
, index
, szwProduct
);
1456 if( r
== ERROR_SUCCESS
)
1458 WideCharToMultiByte(CP_ACP
, 0, szwProduct
, -1,
1459 szProduct
, GUID_SIZE
, NULL
, NULL
);
1462 msi_free( szwComponent
);
1467 UINT WINAPI
MsiEnumClientsW(LPCWSTR szComponent
, DWORD index
, LPWSTR szProduct
)
1471 WCHAR szValName
[SQUISH_GUID_SIZE
];
1473 TRACE("%s %d %p\n", debugstr_w(szComponent
), index
, szProduct
);
1475 if (!szComponent
|| !*szComponent
|| !szProduct
)
1476 return ERROR_INVALID_PARAMETER
;
1478 if (MSIREG_OpenUserDataComponentKey(szComponent
, NULL
, &hkeyComp
, FALSE
) != ERROR_SUCCESS
&&
1479 MSIREG_OpenUserDataComponentKey(szComponent
, szLocalSid
, &hkeyComp
, FALSE
) != ERROR_SUCCESS
)
1480 return ERROR_UNKNOWN_COMPONENT
;
1482 /* see if there are any products at all */
1483 sz
= SQUISH_GUID_SIZE
;
1484 r
= RegEnumValueW(hkeyComp
, 0, szValName
, &sz
, NULL
, NULL
, NULL
, NULL
);
1485 if (r
!= ERROR_SUCCESS
)
1487 RegCloseKey(hkeyComp
);
1490 return ERROR_INVALID_PARAMETER
;
1492 return ERROR_UNKNOWN_COMPONENT
;
1495 sz
= SQUISH_GUID_SIZE
;
1496 r
= RegEnumValueW(hkeyComp
, index
, szValName
, &sz
, NULL
, NULL
, NULL
, NULL
);
1497 if( r
== ERROR_SUCCESS
)
1499 unsquash_guid(szValName
, szProduct
);
1500 TRACE("-> %s\n", debugstr_w(szProduct
));
1502 RegCloseKey(hkeyComp
);
1506 static UINT
MSI_EnumComponentQualifiers( LPCWSTR szComponent
, DWORD iIndex
,
1507 awstring
*lpQualBuf
, LPDWORD pcchQual
,
1508 awstring
*lpAppBuf
, LPDWORD pcchAppBuf
)
1510 DWORD name_sz
, val_sz
, name_max
, val_max
, type
, ofs
;
1511 LPWSTR name
= NULL
, val
= NULL
;
1515 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent
), iIndex
,
1516 lpQualBuf
, pcchQual
, lpAppBuf
, pcchAppBuf
);
1519 return ERROR_INVALID_PARAMETER
;
1521 r
= MSIREG_OpenUserComponentsKey( szComponent
, &key
, FALSE
);
1522 if (r
!= ERROR_SUCCESS
)
1523 return ERROR_UNKNOWN_COMPONENT
;
1525 /* figure out how big the name is we want to return */
1527 r
= ERROR_OUTOFMEMORY
;
1528 name
= msi_alloc( name_max
* sizeof(WCHAR
) );
1533 r
= ERROR_OUTOFMEMORY
;
1534 val
= msi_alloc( val_max
);
1538 /* loop until we allocate enough memory */
1543 r
= RegEnumValueW( key
, iIndex
, name
, &name_sz
,
1544 NULL
, &type
, (LPBYTE
)val
, &val_sz
);
1545 if (r
== ERROR_SUCCESS
)
1547 if (r
!= ERROR_MORE_DATA
)
1550 if (type
!= REG_MULTI_SZ
)
1552 ERR("component data has wrong type (%d)\n", type
);
1556 r
= ERROR_OUTOFMEMORY
;
1557 if (name_sz
+ 1 >= name_max
)
1561 name
= msi_alloc( name_max
* sizeof (WCHAR
) );
1566 if (val_sz
> val_max
)
1568 val_max
= val_sz
+ sizeof (WCHAR
);
1570 val
= msi_alloc( val_max
* sizeof (WCHAR
) );
1575 ERR("should be enough data, but isn't %d %d\n", name_sz
, val_sz
);
1580 r
= MsiDecomposeDescriptorW( val
, NULL
, NULL
, NULL
, &ofs
);
1581 if (r
!= ERROR_SUCCESS
)
1584 TRACE("Providing %s and %s\n", debugstr_w(name
), debugstr_w(val
+ofs
));
1586 r
= msi_strcpy_to_awstring( name
, -1, lpQualBuf
, pcchQual
);
1587 r2
= msi_strcpy_to_awstring( val
+ofs
, -1, lpAppBuf
, pcchAppBuf
);
1589 if (r2
!= ERROR_SUCCESS
)
1599 /*************************************************************************
1600 * MsiEnumComponentQualifiersA [MSI.@]
1602 UINT WINAPI
MsiEnumComponentQualifiersA( LPCSTR szComponent
, DWORD iIndex
,
1603 LPSTR lpQualifierBuf
, LPDWORD pcchQualifierBuf
,
1604 LPSTR lpApplicationDataBuf
, LPDWORD pcchApplicationDataBuf
)
1606 awstring qual
, appdata
;
1610 TRACE("%s %08x %p %p %p %p\n", debugstr_a(szComponent
), iIndex
,
1611 lpQualifierBuf
, pcchQualifierBuf
, lpApplicationDataBuf
,
1612 pcchApplicationDataBuf
);
1614 comp
= strdupAtoW( szComponent
);
1615 if (szComponent
&& !comp
)
1616 return ERROR_OUTOFMEMORY
;
1618 qual
.unicode
= FALSE
;
1619 qual
.str
.a
= lpQualifierBuf
;
1621 appdata
.unicode
= FALSE
;
1622 appdata
.str
.a
= lpApplicationDataBuf
;
1624 r
= MSI_EnumComponentQualifiers( comp
, iIndex
,
1625 &qual
, pcchQualifierBuf
, &appdata
, pcchApplicationDataBuf
);
1630 /*************************************************************************
1631 * MsiEnumComponentQualifiersW [MSI.@]
1633 UINT WINAPI
MsiEnumComponentQualifiersW( LPCWSTR szComponent
, DWORD iIndex
,
1634 LPWSTR lpQualifierBuf
, LPDWORD pcchQualifierBuf
,
1635 LPWSTR lpApplicationDataBuf
, LPDWORD pcchApplicationDataBuf
)
1637 awstring qual
, appdata
;
1639 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent
), iIndex
,
1640 lpQualifierBuf
, pcchQualifierBuf
, lpApplicationDataBuf
,
1641 pcchApplicationDataBuf
);
1643 qual
.unicode
= TRUE
;
1644 qual
.str
.w
= lpQualifierBuf
;
1646 appdata
.unicode
= TRUE
;
1647 appdata
.str
.w
= lpApplicationDataBuf
;
1649 return MSI_EnumComponentQualifiers( szComponent
, iIndex
,
1650 &qual
, pcchQualifierBuf
, &appdata
, pcchApplicationDataBuf
);
1653 /*************************************************************************
1654 * MsiEnumRelatedProductsW [MSI.@]
1657 UINT WINAPI
MsiEnumRelatedProductsW(LPCWSTR szUpgradeCode
, DWORD dwReserved
,
1658 DWORD iProductIndex
, LPWSTR lpProductBuf
)
1662 DWORD dwSize
= SQUISH_GUID_SIZE
;
1663 WCHAR szKeyName
[SQUISH_GUID_SIZE
];
1665 TRACE("%s %u %u %p\n", debugstr_w(szUpgradeCode
), dwReserved
,
1666 iProductIndex
, lpProductBuf
);
1668 if (NULL
== szUpgradeCode
)
1669 return ERROR_INVALID_PARAMETER
;
1670 if (NULL
== lpProductBuf
)
1671 return ERROR_INVALID_PARAMETER
;
1673 r
= MSIREG_OpenUpgradeCodesKey(szUpgradeCode
, &hkey
, FALSE
);
1674 if (r
!= ERROR_SUCCESS
)
1675 return ERROR_NO_MORE_ITEMS
;
1677 r
= RegEnumValueW(hkey
, iProductIndex
, szKeyName
, &dwSize
, NULL
, NULL
, NULL
, NULL
);
1678 if( r
== ERROR_SUCCESS
)
1679 unsquash_guid(szKeyName
, lpProductBuf
);
1685 /*************************************************************************
1686 * MsiEnumRelatedProductsA [MSI.@]
1689 UINT WINAPI
MsiEnumRelatedProductsA(LPCSTR szUpgradeCode
, DWORD dwReserved
,
1690 DWORD iProductIndex
, LPSTR lpProductBuf
)
1692 LPWSTR szwUpgradeCode
= NULL
;
1693 WCHAR productW
[GUID_SIZE
];
1696 TRACE("%s %u %u %p\n", debugstr_a(szUpgradeCode
), dwReserved
,
1697 iProductIndex
, lpProductBuf
);
1701 szwUpgradeCode
= strdupAtoW( szUpgradeCode
);
1702 if( !szwUpgradeCode
)
1703 return ERROR_OUTOFMEMORY
;
1706 r
= MsiEnumRelatedProductsW( szwUpgradeCode
, dwReserved
,
1707 iProductIndex
, productW
);
1708 if (r
== ERROR_SUCCESS
)
1710 WideCharToMultiByte( CP_ACP
, 0, productW
, GUID_SIZE
,
1711 lpProductBuf
, GUID_SIZE
, NULL
, NULL
);
1713 msi_free( szwUpgradeCode
);
1717 /***********************************************************************
1718 * MsiEnumPatchesExA [MSI.@]
1720 UINT WINAPI
MsiEnumPatchesExA(LPCSTR szProductCode
, LPCSTR szUserSid
,
1721 DWORD dwContext
, DWORD dwFilter
, DWORD dwIndex
, LPSTR szPatchCode
,
1722 LPSTR szTargetProductCode
, MSIINSTALLCONTEXT
*pdwTargetProductContext
,
1723 LPSTR szTargetUserSid
, LPDWORD pcchTargetUserSid
)
1725 LPWSTR prodcode
= NULL
;
1726 LPWSTR usersid
= NULL
;
1727 LPWSTR targsid
= NULL
;
1728 WCHAR patch
[GUID_SIZE
];
1729 WCHAR targprod
[GUID_SIZE
];
1733 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p, %p)\n",
1734 debugstr_a(szProductCode
), debugstr_a(szUserSid
), dwContext
, dwFilter
,
1735 dwIndex
, szPatchCode
, szTargetProductCode
, pdwTargetProductContext
,
1736 szTargetUserSid
, pcchTargetUserSid
);
1738 if (szTargetUserSid
&& !pcchTargetUserSid
)
1739 return ERROR_INVALID_PARAMETER
;
1741 if (szProductCode
) prodcode
= strdupAtoW(szProductCode
);
1742 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1744 r
= MsiEnumPatchesExW(prodcode
, usersid
, dwContext
, dwFilter
, dwIndex
,
1745 patch
, targprod
, pdwTargetProductContext
,
1747 if (r
!= ERROR_SUCCESS
)
1750 WideCharToMultiByte(CP_ACP
, 0, patch
, -1, szPatchCode
,
1751 GUID_SIZE
, NULL
, NULL
);
1752 WideCharToMultiByte(CP_ACP
, 0, targprod
, -1, szTargetProductCode
,
1753 GUID_SIZE
, NULL
, NULL
);
1755 if (!szTargetUserSid
)
1757 if (pcchTargetUserSid
)
1758 *pcchTargetUserSid
= len
;
1763 targsid
= msi_alloc(++len
* sizeof(WCHAR
));
1766 r
= ERROR_OUTOFMEMORY
;
1770 r
= MsiEnumPatchesExW(prodcode
, usersid
, dwContext
, dwFilter
, dwIndex
,
1771 patch
, targprod
, pdwTargetProductContext
,
1773 if (r
!= ERROR_SUCCESS
|| !szTargetUserSid
)
1776 WideCharToMultiByte(CP_ACP
, 0, targsid
, -1, szTargetUserSid
,
1777 *pcchTargetUserSid
, NULL
, NULL
);
1779 len
= lstrlenW(targsid
);
1780 if (*pcchTargetUserSid
< len
+ 1)
1782 r
= ERROR_MORE_DATA
;
1783 *pcchTargetUserSid
= len
* sizeof(WCHAR
);
1786 *pcchTargetUserSid
= len
;
1796 static UINT
msi_get_patch_state(LPCWSTR prodcode
, LPCWSTR usersid
,
1797 MSIINSTALLCONTEXT context
,
1798 LPWSTR patch
, MSIPATCHSTATE
*state
)
1800 DWORD type
, val
, size
;
1801 HKEY prod
, hkey
= 0;
1804 UINT r
= ERROR_NO_MORE_ITEMS
;
1806 *state
= MSIPATCHSTATE_INVALID
;
1808 r
= MSIREG_OpenUserDataProductKey(prodcode
, context
,
1809 usersid
, &prod
, FALSE
);
1810 if (r
!= ERROR_SUCCESS
)
1811 return ERROR_NO_MORE_ITEMS
;
1813 res
= RegOpenKeyExW(prod
, szPatches
, 0, KEY_READ
, &hkey
);
1814 if (res
!= ERROR_SUCCESS
)
1817 res
= RegOpenKeyExW(hkey
, patch
, 0, KEY_READ
, &udpatch
);
1818 if (res
!= ERROR_SUCCESS
)
1821 size
= sizeof(DWORD
);
1822 res
= RegGetValueW(udpatch
, NULL
, szState
, RRF_RT_DWORD
, &type
, &val
, &size
);
1823 if (res
!= ERROR_SUCCESS
||
1824 val
< MSIPATCHSTATE_APPLIED
|| val
> MSIPATCHSTATE_REGISTERED
)
1826 r
= ERROR_BAD_CONFIGURATION
;
1834 RegCloseKey(udpatch
);
1841 static UINT
msi_check_product_patches(LPCWSTR prodcode
, LPCWSTR usersid
,
1842 MSIINSTALLCONTEXT context
, DWORD filter
, DWORD index
, DWORD
*idx
,
1843 LPWSTR patch
, LPWSTR targetprod
, MSIINSTALLCONTEXT
*targetctx
,
1844 LPWSTR targetsid
, DWORD
*sidsize
, LPWSTR
*transforms
)
1846 MSIPATCHSTATE state
= MSIPATCHSTATE_INVALID
;
1847 LPWSTR ptr
, patches
= NULL
;
1848 HKEY prod
, patchkey
= 0;
1849 HKEY localprod
= 0, localpatch
= 0;
1852 UINT temp
, r
= ERROR_NO_MORE_ITEMS
;
1854 if (MSIREG_OpenProductKey(prodcode
, usersid
, context
,
1855 &prod
, FALSE
) != ERROR_SUCCESS
)
1856 return ERROR_NO_MORE_ITEMS
;
1859 res
= RegGetValueW(prod
, szPatches
, szPatches
, RRF_RT_ANY
, &type
, NULL
,
1861 if (res
!= ERROR_SUCCESS
)
1864 if (type
!= REG_MULTI_SZ
)
1866 r
= ERROR_BAD_CONFIGURATION
;
1870 patches
= msi_alloc(size
);
1873 r
= ERROR_OUTOFMEMORY
;
1877 res
= RegGetValueW(prod
, szPatches
, szPatches
, RRF_RT_ANY
, &type
,
1879 if (res
!= ERROR_SUCCESS
)
1882 for (ptr
= patches
; *ptr
&& r
== ERROR_NO_MORE_ITEMS
; ptr
+= lstrlenW(ptr
) + 1)
1884 if (!unsquash_guid(ptr
, patch
))
1886 r
= ERROR_BAD_CONFIGURATION
;
1891 res
= RegGetValueW(prod
, szPatches
, ptr
, RRF_RT_REG_SZ
,
1892 &type
, NULL
, &size
);
1893 if (res
!= ERROR_SUCCESS
)
1898 *transforms
= msi_alloc(size
);
1901 r
= ERROR_OUTOFMEMORY
;
1905 res
= RegGetValueW(prod
, szPatches
, ptr
, RRF_RT_REG_SZ
,
1906 &type
, *transforms
, &size
);
1907 if (res
!= ERROR_SUCCESS
)
1911 if (context
== MSIINSTALLCONTEXT_USERMANAGED
)
1913 if (!(filter
& MSIPATCHSTATE_APPLIED
))
1915 temp
= msi_get_patch_state(prodcode
, usersid
, context
,
1917 if (temp
== ERROR_BAD_CONFIGURATION
)
1919 r
= ERROR_BAD_CONFIGURATION
;
1923 if (temp
!= ERROR_SUCCESS
|| !(filter
& state
))
1927 else if (context
== MSIINSTALLCONTEXT_USERUNMANAGED
)
1929 if (!(filter
& MSIPATCHSTATE_APPLIED
))
1931 temp
= msi_get_patch_state(prodcode
, usersid
, context
,
1933 if (temp
== ERROR_BAD_CONFIGURATION
)
1935 r
= ERROR_BAD_CONFIGURATION
;
1939 if (temp
!= ERROR_SUCCESS
|| !(filter
& state
))
1944 temp
= MSIREG_OpenUserDataPatchKey(patch
, context
,
1946 RegCloseKey(patchkey
);
1947 if (temp
!= ERROR_SUCCESS
)
1951 else if (context
== MSIINSTALLCONTEXT_MACHINE
)
1955 if (MSIREG_OpenUserDataProductKey(prodcode
, context
, NULL
, &localprod
, FALSE
) == ERROR_SUCCESS
&&
1956 RegOpenKeyExW(localprod
, szPatches
, 0, KEY_READ
, &localpatch
) == ERROR_SUCCESS
&&
1957 RegOpenKeyExW(localpatch
, ptr
, 0, KEY_READ
, &patchkey
) == ERROR_SUCCESS
)
1959 res
= RegGetValueW(patchkey
, NULL
, szState
, RRF_RT_REG_DWORD
,
1960 &type
, &state
, &size
);
1962 if (!(filter
& state
))
1963 res
= ERROR_NO_MORE_ITEMS
;
1965 RegCloseKey(patchkey
);
1968 RegCloseKey(localpatch
);
1969 RegCloseKey(localprod
);
1971 if (res
!= ERROR_SUCCESS
)
1983 lstrcpyW(targetprod
, prodcode
);
1986 *targetctx
= context
;
1990 lstrcpynW(targetsid
, usersid
, *sidsize
);
1991 if (lstrlenW(usersid
) >= *sidsize
)
1992 r
= ERROR_MORE_DATA
;
1997 *sidsize
= lstrlenW(usersid
);
1999 *sidsize
*= sizeof(WCHAR
);
2010 static UINT
msi_enum_patches(LPCWSTR szProductCode
, LPCWSTR szUserSid
,
2011 DWORD dwContext
, DWORD dwFilter
, DWORD dwIndex
, DWORD
*idx
,
2012 LPWSTR szPatchCode
, LPWSTR szTargetProductCode
,
2013 MSIINSTALLCONTEXT
*pdwTargetProductContext
, LPWSTR szTargetUserSid
,
2014 LPDWORD pcchTargetUserSid
, LPWSTR
*szTransforms
)
2016 LPWSTR usersid
= NULL
;
2017 UINT r
= ERROR_INVALID_PARAMETER
;
2021 szUserSid
= usersid
= get_user_sid();
2022 if (!usersid
) return ERROR_FUNCTION_FAILED
;
2025 if (dwContext
& MSIINSTALLCONTEXT_USERMANAGED
)
2027 r
= msi_check_product_patches(szProductCode
, szUserSid
,
2028 MSIINSTALLCONTEXT_USERMANAGED
, dwFilter
,
2029 dwIndex
, idx
, szPatchCode
,
2030 szTargetProductCode
,
2031 pdwTargetProductContext
, szTargetUserSid
,
2032 pcchTargetUserSid
, szTransforms
);
2033 if (r
!= ERROR_NO_MORE_ITEMS
)
2037 if (dwContext
& MSIINSTALLCONTEXT_USERUNMANAGED
)
2039 r
= msi_check_product_patches(szProductCode
, szUserSid
,
2040 MSIINSTALLCONTEXT_USERUNMANAGED
, dwFilter
,
2041 dwIndex
, idx
, szPatchCode
,
2042 szTargetProductCode
,
2043 pdwTargetProductContext
, szTargetUserSid
,
2044 pcchTargetUserSid
, szTransforms
);
2045 if (r
!= ERROR_NO_MORE_ITEMS
)
2049 if (dwContext
& MSIINSTALLCONTEXT_MACHINE
)
2051 r
= msi_check_product_patches(szProductCode
, szUserSid
,
2052 MSIINSTALLCONTEXT_MACHINE
, dwFilter
,
2053 dwIndex
, idx
, szPatchCode
,
2054 szTargetProductCode
,
2055 pdwTargetProductContext
, szTargetUserSid
,
2056 pcchTargetUserSid
, szTransforms
);
2057 if (r
!= ERROR_NO_MORE_ITEMS
)
2066 /***********************************************************************
2067 * MsiEnumPatchesExW [MSI.@]
2069 UINT WINAPI
MsiEnumPatchesExW(LPCWSTR szProductCode
, LPCWSTR szUserSid
,
2070 DWORD dwContext
, DWORD dwFilter
, DWORD dwIndex
, LPWSTR szPatchCode
,
2071 LPWSTR szTargetProductCode
, MSIINSTALLCONTEXT
*pdwTargetProductContext
,
2072 LPWSTR szTargetUserSid
, LPDWORD pcchTargetUserSid
)
2074 WCHAR squished_pc
[GUID_SIZE
];
2078 static DWORD last_index
;
2080 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p, %p)\n",
2081 debugstr_w(szProductCode
), debugstr_w(szUserSid
), dwContext
, dwFilter
,
2082 dwIndex
, szPatchCode
, szTargetProductCode
, pdwTargetProductContext
,
2083 szTargetUserSid
, pcchTargetUserSid
);
2085 if (!szProductCode
|| !squash_guid(szProductCode
, squished_pc
))
2086 return ERROR_INVALID_PARAMETER
;
2088 if (szUserSid
&& !strcmpW( szUserSid
, szLocalSid
))
2089 return ERROR_INVALID_PARAMETER
;
2091 if (dwContext
& MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
2092 return ERROR_INVALID_PARAMETER
;
2094 if (dwContext
<= MSIINSTALLCONTEXT_NONE
||
2095 dwContext
> MSIINSTALLCONTEXT_ALL
)
2096 return ERROR_INVALID_PARAMETER
;
2098 if (dwFilter
<= MSIPATCHSTATE_INVALID
|| dwFilter
> MSIPATCHSTATE_ALL
)
2099 return ERROR_INVALID_PARAMETER
;
2101 if (dwIndex
&& dwIndex
- last_index
!= 1)
2102 return ERROR_INVALID_PARAMETER
;
2107 r
= msi_enum_patches(szProductCode
, szUserSid
, dwContext
, dwFilter
,
2108 dwIndex
, &idx
, szPatchCode
, szTargetProductCode
,
2109 pdwTargetProductContext
, szTargetUserSid
,
2110 pcchTargetUserSid
, NULL
);
2112 if (r
== ERROR_SUCCESS
)
2113 last_index
= dwIndex
;
2120 /***********************************************************************
2121 * MsiEnumPatchesA [MSI.@]
2123 UINT WINAPI
MsiEnumPatchesA(LPCSTR szProduct
, DWORD iPatchIndex
,
2124 LPSTR lpPatchBuf
, LPSTR lpTransformsBuf
, LPDWORD pcchTransformsBuf
)
2126 LPWSTR product
, transforms
;
2127 WCHAR patch
[GUID_SIZE
];
2131 TRACE("(%s %d %p %p %p)\n", debugstr_a(szProduct
), iPatchIndex
,
2132 lpPatchBuf
, lpTransformsBuf
, pcchTransformsBuf
);
2134 if (!szProduct
|| !lpPatchBuf
|| !lpTransformsBuf
|| !pcchTransformsBuf
)
2135 return ERROR_INVALID_PARAMETER
;
2137 product
= strdupAtoW(szProduct
);
2139 return ERROR_OUTOFMEMORY
;
2141 len
= *pcchTransformsBuf
;
2142 transforms
= msi_alloc( len
* sizeof(WCHAR
) );
2145 r
= ERROR_OUTOFMEMORY
;
2149 r
= MsiEnumPatchesW(product
, iPatchIndex
, patch
, transforms
, &len
);
2150 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
2153 WideCharToMultiByte(CP_ACP
, 0, patch
, -1, lpPatchBuf
,
2154 GUID_SIZE
, NULL
, NULL
);
2156 if (!WideCharToMultiByte(CP_ACP
, 0, transforms
, -1, lpTransformsBuf
,
2157 *pcchTransformsBuf
, NULL
, NULL
))
2158 r
= ERROR_MORE_DATA
;
2160 if (r
== ERROR_MORE_DATA
)
2162 lpTransformsBuf
[*pcchTransformsBuf
- 1] = '\0';
2163 *pcchTransformsBuf
= len
* 2;
2166 *pcchTransformsBuf
= strlen( lpTransformsBuf
);
2169 msi_free(transforms
);
2175 /***********************************************************************
2176 * MsiEnumPatchesW [MSI.@]
2178 UINT WINAPI
MsiEnumPatchesW(LPCWSTR szProduct
, DWORD iPatchIndex
,
2179 LPWSTR lpPatchBuf
, LPWSTR lpTransformsBuf
, LPDWORD pcchTransformsBuf
)
2181 WCHAR squished_pc
[GUID_SIZE
];
2182 LPWSTR transforms
= NULL
;
2187 TRACE("(%s %d %p %p %p)\n", debugstr_w(szProduct
), iPatchIndex
,
2188 lpPatchBuf
, lpTransformsBuf
, pcchTransformsBuf
);
2190 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
2191 return ERROR_INVALID_PARAMETER
;
2193 if (!lpPatchBuf
|| !lpTransformsBuf
|| !pcchTransformsBuf
)
2194 return ERROR_INVALID_PARAMETER
;
2196 if (MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
,
2197 &prod
, FALSE
) != ERROR_SUCCESS
&&
2198 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
2199 &prod
, FALSE
) != ERROR_SUCCESS
&&
2200 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
2201 &prod
, FALSE
) != ERROR_SUCCESS
)
2202 return ERROR_UNKNOWN_PRODUCT
;
2206 r
= msi_enum_patches(szProduct
, NULL
, MSIINSTALLCONTEXT_ALL
,
2207 MSIPATCHSTATE_ALL
, iPatchIndex
, &idx
, lpPatchBuf
,
2208 NULL
, NULL
, NULL
, NULL
, &transforms
);
2209 if (r
!= ERROR_SUCCESS
)
2212 lstrcpynW(lpTransformsBuf
, transforms
, *pcchTransformsBuf
);
2213 if (*pcchTransformsBuf
<= lstrlenW(transforms
))
2215 r
= ERROR_MORE_DATA
;
2216 *pcchTransformsBuf
= lstrlenW(transforms
);
2219 *pcchTransformsBuf
= lstrlenW(transforms
);
2222 msi_free(transforms
);
2226 UINT WINAPI
MsiEnumProductsExA( LPCSTR product
, LPCSTR usersid
, DWORD ctx
, DWORD index
,
2227 CHAR installed_product
[GUID_SIZE
],
2228 MSIINSTALLCONTEXT
*installed_ctx
, LPSTR sid
, LPDWORD sid_len
)
2231 WCHAR installed_productW
[GUID_SIZE
], *productW
= NULL
, *usersidW
= NULL
, *sidW
= NULL
;
2233 TRACE("%s, %s, %u, %u, %p, %p, %p, %p\n", debugstr_a(product
), debugstr_a(usersid
),
2234 ctx
, index
, installed_product
, installed_ctx
, sid
, sid_len
);
2236 if (sid
&& !sid_len
) return ERROR_INVALID_PARAMETER
;
2237 if (product
&& !(productW
= strdupAtoW( product
))) return ERROR_OUTOFMEMORY
;
2238 if (usersid
&& !(usersidW
= strdupAtoW( usersid
)))
2240 msi_free( productW
);
2241 return ERROR_OUTOFMEMORY
;
2243 if (sid
&& !(sidW
= msi_alloc( *sid_len
* sizeof(WCHAR
) )))
2245 msi_free( usersidW
);
2246 msi_free( productW
);
2247 return ERROR_OUTOFMEMORY
;
2249 r
= MsiEnumProductsExW( productW
, usersidW
, ctx
, index
, installed_productW
,
2250 installed_ctx
, sidW
, sid_len
);
2251 if (r
== ERROR_SUCCESS
)
2253 if (installed_product
) WideCharToMultiByte( CP_ACP
, 0, installed_productW
, GUID_SIZE
,
2254 installed_product
, GUID_SIZE
, NULL
, NULL
);
2255 if (sid
) WideCharToMultiByte( CP_ACP
, 0, sidW
, *sid_len
+ 1, sid
, *sid_len
+ 1, NULL
, NULL
);
2257 msi_free( productW
);
2258 msi_free( usersidW
);
2263 static UINT
fetch_machine_product( const WCHAR
*match
, DWORD index
, DWORD
*idx
,
2264 WCHAR installed_product
[GUID_SIZE
],
2265 MSIINSTALLCONTEXT
*installed_ctx
, WCHAR
*sid
, DWORD
*sid_len
)
2267 static const WCHAR productsW
[] =
2268 {'S','o','f','t','w','a','r','e','\\','C','l','a','s','s','e','s','\\',
2269 'I','n','s','t','a','l','l','e','r','\\','P','r','o','d','u','c','t','s',0};
2271 WCHAR product
[GUID_SIZE
];
2273 REGSAM access
= KEY_ENUMERATE_SUB_KEYS
| KEY_WOW64_64KEY
;
2276 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, productsW
, 0, access
, &key
))
2277 return ERROR_NO_MORE_ITEMS
;
2279 len
= sizeof(product
)/sizeof(product
[0]);
2280 while (!RegEnumKeyExW( key
, i
, product
, &len
, NULL
, NULL
, NULL
, NULL
))
2282 if (match
&& strcmpW( match
, product
))
2285 len
= sizeof(product
)/sizeof(product
[0]);
2288 if (*idx
== index
) goto found
;
2290 len
= sizeof(product
)/sizeof(product
[0]);
2294 return ERROR_NO_MORE_ITEMS
;
2297 if (sid_len
&& *sid_len
< 1)
2300 r
= ERROR_MORE_DATA
;
2304 if (installed_product
) unsquash_guid( product
, installed_product
);
2305 if (installed_ctx
) *installed_ctx
= MSIINSTALLCONTEXT_MACHINE
;
2317 static UINT
fetch_user_product( const WCHAR
*match
, const WCHAR
*usersid
, DWORD ctx
, DWORD index
,
2318 DWORD
*idx
, WCHAR installed_product
[GUID_SIZE
],
2319 MSIINSTALLCONTEXT
*installed_ctx
, WCHAR
*sid
, DWORD
*sid_len
)
2321 static const WCHAR managedW
[] =
2322 {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
2323 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s',
2324 'i','o','n','\\','I','n','s','t','a','l','l','e','r','\\','M','a','n','a','g','e','d',0};
2325 static const WCHAR managed_productsW
[] =
2326 {'\\','I','n','s','t','a','l','l','e','r','\\','P','r','o','d','u','c','t','s',0};
2327 static const WCHAR unmanaged_productsW
[] =
2328 {'\\','S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
2329 'I','n','s','t','a','l','l','e','r','\\','P','r','o','d','u','c','t','s',0};
2331 const WCHAR
*subkey
;
2332 WCHAR path
[MAX_PATH
], product
[GUID_SIZE
], user
[128];
2333 DWORD i
= 0, j
= 0, len_product
, len_user
;
2334 REGSAM access
= KEY_ENUMERATE_SUB_KEYS
| KEY_WOW64_64KEY
;
2335 HKEY key_users
, key_products
;
2337 if (ctx
== MSIINSTALLCONTEXT_USERMANAGED
)
2339 subkey
= managed_productsW
;
2340 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, managedW
, 0, access
, &key_users
))
2341 return ERROR_NO_MORE_ITEMS
;
2343 else if (ctx
== MSIINSTALLCONTEXT_USERUNMANAGED
)
2345 subkey
= unmanaged_productsW
;
2346 if (RegOpenKeyExW( HKEY_USERS
, NULL
, 0, access
, &key_users
))
2347 return ERROR_NO_MORE_ITEMS
;
2349 else return ERROR_INVALID_PARAMETER
;
2351 len_user
= sizeof(user
)/sizeof(user
[0]);
2352 while (!RegEnumKeyExW( key_users
, i
, user
, &len_user
, NULL
, NULL
, NULL
, NULL
))
2354 if (strcmpW( usersid
, user
) && strcmpW( usersid
, szAllSid
))
2357 len_user
= sizeof(user
)/sizeof(user
[0]);
2360 strcpyW( path
, user
);
2361 strcatW( path
, subkey
);
2362 if (RegOpenKeyExW( key_users
, path
, 0, access
, &key_products
))
2365 len_user
= sizeof(user
)/sizeof(user
[0]);
2368 len_product
= sizeof(product
)/sizeof(product
[0]);
2369 while (!RegEnumKeyExW( key_products
, j
, product
, &len_product
, NULL
, NULL
, NULL
, NULL
))
2371 if (match
&& strcmpW( match
, product
))
2374 len_product
= sizeof(product
)/sizeof(product
[0]);
2377 if (*idx
== index
) goto found
;
2379 len_product
= sizeof(product
)/sizeof(product
[0]);
2382 RegCloseKey( key_products
);
2383 len_user
= sizeof(user
)/sizeof(user
[0]);
2386 RegCloseKey( key_users
);
2387 return ERROR_NO_MORE_ITEMS
;
2390 if (sid_len
&& *sid_len
<= len_user
)
2392 *sid_len
= len_user
;
2393 r
= ERROR_MORE_DATA
;
2397 if (installed_product
) unsquash_guid( product
, installed_product
);
2398 if (installed_ctx
) *installed_ctx
= ctx
;
2401 strcpyW( sid
, user
);
2402 *sid_len
= len_user
;
2406 RegCloseKey( key_products
);
2407 RegCloseKey( key_users
);
2411 static UINT
enum_products( const WCHAR
*product
, const WCHAR
*usersid
, DWORD ctx
, DWORD index
,
2412 DWORD
*idx
, WCHAR installed_product
[GUID_SIZE
],
2413 MSIINSTALLCONTEXT
*installed_ctx
, WCHAR
*sid
, DWORD
*sid_len
)
2415 UINT r
= ERROR_NO_MORE_ITEMS
;
2420 usersid
= user
= get_user_sid();
2421 if (!user
) return ERROR_FUNCTION_FAILED
;
2423 if (ctx
& MSIINSTALLCONTEXT_MACHINE
)
2425 r
= fetch_machine_product( product
, index
, idx
, installed_product
, installed_ctx
,
2427 if (r
!= ERROR_NO_MORE_ITEMS
) goto done
;
2429 if (ctx
& MSIINSTALLCONTEXT_USERUNMANAGED
)
2431 r
= fetch_user_product( product
, usersid
, MSIINSTALLCONTEXT_USERUNMANAGED
, index
,
2432 idx
, installed_product
, installed_ctx
, sid
, sid_len
);
2433 if (r
!= ERROR_NO_MORE_ITEMS
) goto done
;
2435 if (ctx
& MSIINSTALLCONTEXT_USERMANAGED
)
2437 r
= fetch_user_product( product
, usersid
, MSIINSTALLCONTEXT_USERMANAGED
, index
,
2438 idx
, installed_product
, installed_ctx
, sid
, sid_len
);
2439 if (r
!= ERROR_NO_MORE_ITEMS
) goto done
;
2447 UINT WINAPI
MsiEnumProductsExW( LPCWSTR product
, LPCWSTR usersid
, DWORD ctx
, DWORD index
,
2448 WCHAR installed_product
[GUID_SIZE
],
2449 MSIINSTALLCONTEXT
*installed_ctx
, LPWSTR sid
, LPDWORD sid_len
)
2453 static DWORD last_index
;
2455 TRACE("%s, %s, %u, %u, %p, %p, %p, %p\n", debugstr_w(product
), debugstr_w(usersid
),
2456 ctx
, index
, installed_product
, installed_ctx
, sid
, sid_len
);
2458 if ((sid
&& !sid_len
) || !ctx
|| (usersid
&& ctx
== MSIINSTALLCONTEXT_MACHINE
))
2459 return ERROR_INVALID_PARAMETER
;
2461 if (index
&& index
- last_index
!= 1)
2462 return ERROR_INVALID_PARAMETER
;
2464 if (!index
) last_index
= 0;
2466 r
= enum_products( product
, usersid
, ctx
, index
, &idx
, installed_product
, installed_ctx
,
2468 if (r
== ERROR_SUCCESS
)