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 UINT WINAPI
MsiEnumClientsExA(LPCSTR component
, LPCSTR usersid
, DWORD ctx
, DWORD index
,
1507 CHAR installed_product
[GUID_SIZE
],
1508 MSIINSTALLCONTEXT
*installed_ctx
, LPSTR sid
, LPDWORD sid_len
)
1510 FIXME("%s, %s, %u, %u, %p, %p, %p, %p\n", debugstr_a(component
), debugstr_a(usersid
),
1511 ctx
, index
, installed_product
, installed_ctx
, sid
, sid_len
);
1512 return ERROR_ACCESS_DENIED
;
1515 UINT WINAPI
MsiEnumClientsExW(LPCWSTR component
, LPCWSTR usersid
, DWORD ctx
, DWORD index
,
1516 WCHAR installed_product
[GUID_SIZE
],
1517 MSIINSTALLCONTEXT
*installed_ctx
, LPWSTR sid
, LPDWORD sid_len
)
1519 FIXME("%s, %s, %u, %u, %p, %p, %p, %p\n", debugstr_w(component
), debugstr_w(usersid
),
1520 ctx
, index
, installed_product
, installed_ctx
, sid
, sid_len
);
1521 return ERROR_ACCESS_DENIED
;
1524 static UINT
MSI_EnumComponentQualifiers( LPCWSTR szComponent
, DWORD iIndex
,
1525 awstring
*lpQualBuf
, LPDWORD pcchQual
,
1526 awstring
*lpAppBuf
, LPDWORD pcchAppBuf
)
1528 DWORD name_sz
, val_sz
, name_max
, val_max
, type
, ofs
;
1529 LPWSTR name
= NULL
, val
= NULL
;
1533 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent
), iIndex
,
1534 lpQualBuf
, pcchQual
, lpAppBuf
, pcchAppBuf
);
1537 return ERROR_INVALID_PARAMETER
;
1539 r
= MSIREG_OpenUserComponentsKey( szComponent
, &key
, FALSE
);
1540 if (r
!= ERROR_SUCCESS
)
1541 return ERROR_UNKNOWN_COMPONENT
;
1543 /* figure out how big the name is we want to return */
1545 r
= ERROR_OUTOFMEMORY
;
1546 name
= msi_alloc( name_max
* sizeof(WCHAR
) );
1551 r
= ERROR_OUTOFMEMORY
;
1552 val
= msi_alloc( val_max
);
1556 /* loop until we allocate enough memory */
1561 r
= RegEnumValueW( key
, iIndex
, name
, &name_sz
,
1562 NULL
, &type
, (LPBYTE
)val
, &val_sz
);
1563 if (r
== ERROR_SUCCESS
)
1565 if (r
!= ERROR_MORE_DATA
)
1568 if (type
!= REG_MULTI_SZ
)
1570 ERR("component data has wrong type (%d)\n", type
);
1574 r
= ERROR_OUTOFMEMORY
;
1575 if (name_sz
+ 1 >= name_max
)
1579 name
= msi_alloc( name_max
* sizeof (WCHAR
) );
1584 if (val_sz
> val_max
)
1586 val_max
= val_sz
+ sizeof (WCHAR
);
1588 val
= msi_alloc( val_max
* sizeof (WCHAR
) );
1593 ERR("should be enough data, but isn't %d %d\n", name_sz
, val_sz
);
1598 r
= MsiDecomposeDescriptorW( val
, NULL
, NULL
, NULL
, &ofs
);
1599 if (r
!= ERROR_SUCCESS
)
1602 TRACE("Providing %s and %s\n", debugstr_w(name
), debugstr_w(val
+ofs
));
1604 r
= msi_strcpy_to_awstring( name
, -1, lpQualBuf
, pcchQual
);
1605 r2
= msi_strcpy_to_awstring( val
+ofs
, -1, lpAppBuf
, pcchAppBuf
);
1607 if (r2
!= ERROR_SUCCESS
)
1617 /*************************************************************************
1618 * MsiEnumComponentQualifiersA [MSI.@]
1620 UINT WINAPI
MsiEnumComponentQualifiersA( LPCSTR szComponent
, DWORD iIndex
,
1621 LPSTR lpQualifierBuf
, LPDWORD pcchQualifierBuf
,
1622 LPSTR lpApplicationDataBuf
, LPDWORD pcchApplicationDataBuf
)
1624 awstring qual
, appdata
;
1628 TRACE("%s %08x %p %p %p %p\n", debugstr_a(szComponent
), iIndex
,
1629 lpQualifierBuf
, pcchQualifierBuf
, lpApplicationDataBuf
,
1630 pcchApplicationDataBuf
);
1632 comp
= strdupAtoW( szComponent
);
1633 if (szComponent
&& !comp
)
1634 return ERROR_OUTOFMEMORY
;
1636 qual
.unicode
= FALSE
;
1637 qual
.str
.a
= lpQualifierBuf
;
1639 appdata
.unicode
= FALSE
;
1640 appdata
.str
.a
= lpApplicationDataBuf
;
1642 r
= MSI_EnumComponentQualifiers( comp
, iIndex
,
1643 &qual
, pcchQualifierBuf
, &appdata
, pcchApplicationDataBuf
);
1648 /*************************************************************************
1649 * MsiEnumComponentQualifiersW [MSI.@]
1651 UINT WINAPI
MsiEnumComponentQualifiersW( LPCWSTR szComponent
, DWORD iIndex
,
1652 LPWSTR lpQualifierBuf
, LPDWORD pcchQualifierBuf
,
1653 LPWSTR lpApplicationDataBuf
, LPDWORD pcchApplicationDataBuf
)
1655 awstring qual
, appdata
;
1657 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent
), iIndex
,
1658 lpQualifierBuf
, pcchQualifierBuf
, lpApplicationDataBuf
,
1659 pcchApplicationDataBuf
);
1661 qual
.unicode
= TRUE
;
1662 qual
.str
.w
= lpQualifierBuf
;
1664 appdata
.unicode
= TRUE
;
1665 appdata
.str
.w
= lpApplicationDataBuf
;
1667 return MSI_EnumComponentQualifiers( szComponent
, iIndex
,
1668 &qual
, pcchQualifierBuf
, &appdata
, pcchApplicationDataBuf
);
1671 /*************************************************************************
1672 * MsiEnumRelatedProductsW [MSI.@]
1675 UINT WINAPI
MsiEnumRelatedProductsW(LPCWSTR szUpgradeCode
, DWORD dwReserved
,
1676 DWORD iProductIndex
, LPWSTR lpProductBuf
)
1680 DWORD dwSize
= SQUISH_GUID_SIZE
;
1681 WCHAR szKeyName
[SQUISH_GUID_SIZE
];
1683 TRACE("%s %u %u %p\n", debugstr_w(szUpgradeCode
), dwReserved
,
1684 iProductIndex
, lpProductBuf
);
1686 if (NULL
== szUpgradeCode
)
1687 return ERROR_INVALID_PARAMETER
;
1688 if (NULL
== lpProductBuf
)
1689 return ERROR_INVALID_PARAMETER
;
1691 r
= MSIREG_OpenUpgradeCodesKey(szUpgradeCode
, &hkey
, FALSE
);
1692 if (r
!= ERROR_SUCCESS
)
1693 return ERROR_NO_MORE_ITEMS
;
1695 r
= RegEnumValueW(hkey
, iProductIndex
, szKeyName
, &dwSize
, NULL
, NULL
, NULL
, NULL
);
1696 if( r
== ERROR_SUCCESS
)
1697 unsquash_guid(szKeyName
, lpProductBuf
);
1703 /*************************************************************************
1704 * MsiEnumRelatedProductsA [MSI.@]
1707 UINT WINAPI
MsiEnumRelatedProductsA(LPCSTR szUpgradeCode
, DWORD dwReserved
,
1708 DWORD iProductIndex
, LPSTR lpProductBuf
)
1710 LPWSTR szwUpgradeCode
= NULL
;
1711 WCHAR productW
[GUID_SIZE
];
1714 TRACE("%s %u %u %p\n", debugstr_a(szUpgradeCode
), dwReserved
,
1715 iProductIndex
, lpProductBuf
);
1719 szwUpgradeCode
= strdupAtoW( szUpgradeCode
);
1720 if( !szwUpgradeCode
)
1721 return ERROR_OUTOFMEMORY
;
1724 r
= MsiEnumRelatedProductsW( szwUpgradeCode
, dwReserved
,
1725 iProductIndex
, productW
);
1726 if (r
== ERROR_SUCCESS
)
1728 WideCharToMultiByte( CP_ACP
, 0, productW
, GUID_SIZE
,
1729 lpProductBuf
, GUID_SIZE
, NULL
, NULL
);
1731 msi_free( szwUpgradeCode
);
1735 /***********************************************************************
1736 * MsiEnumPatchesExA [MSI.@]
1738 UINT WINAPI
MsiEnumPatchesExA(LPCSTR szProductCode
, LPCSTR szUserSid
,
1739 DWORD dwContext
, DWORD dwFilter
, DWORD dwIndex
, LPSTR szPatchCode
,
1740 LPSTR szTargetProductCode
, MSIINSTALLCONTEXT
*pdwTargetProductContext
,
1741 LPSTR szTargetUserSid
, LPDWORD pcchTargetUserSid
)
1743 LPWSTR prodcode
= NULL
;
1744 LPWSTR usersid
= NULL
;
1745 LPWSTR targsid
= NULL
;
1746 WCHAR patch
[GUID_SIZE
];
1747 WCHAR targprod
[GUID_SIZE
];
1751 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p, %p)\n",
1752 debugstr_a(szProductCode
), debugstr_a(szUserSid
), dwContext
, dwFilter
,
1753 dwIndex
, szPatchCode
, szTargetProductCode
, pdwTargetProductContext
,
1754 szTargetUserSid
, pcchTargetUserSid
);
1756 if (szTargetUserSid
&& !pcchTargetUserSid
)
1757 return ERROR_INVALID_PARAMETER
;
1759 if (szProductCode
) prodcode
= strdupAtoW(szProductCode
);
1760 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1762 r
= MsiEnumPatchesExW(prodcode
, usersid
, dwContext
, dwFilter
, dwIndex
,
1763 patch
, targprod
, pdwTargetProductContext
,
1765 if (r
!= ERROR_SUCCESS
)
1768 WideCharToMultiByte(CP_ACP
, 0, patch
, -1, szPatchCode
,
1769 GUID_SIZE
, NULL
, NULL
);
1770 WideCharToMultiByte(CP_ACP
, 0, targprod
, -1, szTargetProductCode
,
1771 GUID_SIZE
, NULL
, NULL
);
1773 if (!szTargetUserSid
)
1775 if (pcchTargetUserSid
)
1776 *pcchTargetUserSid
= len
;
1781 targsid
= msi_alloc(++len
* sizeof(WCHAR
));
1784 r
= ERROR_OUTOFMEMORY
;
1788 r
= MsiEnumPatchesExW(prodcode
, usersid
, dwContext
, dwFilter
, dwIndex
,
1789 patch
, targprod
, pdwTargetProductContext
,
1791 if (r
!= ERROR_SUCCESS
|| !szTargetUserSid
)
1794 WideCharToMultiByte(CP_ACP
, 0, targsid
, -1, szTargetUserSid
,
1795 *pcchTargetUserSid
, NULL
, NULL
);
1797 len
= lstrlenW(targsid
);
1798 if (*pcchTargetUserSid
< len
+ 1)
1800 r
= ERROR_MORE_DATA
;
1801 *pcchTargetUserSid
= len
* sizeof(WCHAR
);
1804 *pcchTargetUserSid
= len
;
1814 static UINT
msi_get_patch_state(LPCWSTR prodcode
, LPCWSTR usersid
,
1815 MSIINSTALLCONTEXT context
,
1816 LPWSTR patch
, MSIPATCHSTATE
*state
)
1818 DWORD type
, val
, size
;
1819 HKEY prod
, hkey
= 0;
1822 UINT r
= ERROR_NO_MORE_ITEMS
;
1824 *state
= MSIPATCHSTATE_INVALID
;
1826 r
= MSIREG_OpenUserDataProductKey(prodcode
, context
,
1827 usersid
, &prod
, FALSE
);
1828 if (r
!= ERROR_SUCCESS
)
1829 return ERROR_NO_MORE_ITEMS
;
1831 res
= RegOpenKeyExW(prod
, szPatches
, 0, KEY_READ
, &hkey
);
1832 if (res
!= ERROR_SUCCESS
)
1835 res
= RegOpenKeyExW(hkey
, patch
, 0, KEY_READ
, &udpatch
);
1836 if (res
!= ERROR_SUCCESS
)
1839 size
= sizeof(DWORD
);
1840 res
= RegGetValueW(udpatch
, NULL
, szState
, RRF_RT_DWORD
, &type
, &val
, &size
);
1841 if (res
!= ERROR_SUCCESS
||
1842 val
< MSIPATCHSTATE_APPLIED
|| val
> MSIPATCHSTATE_REGISTERED
)
1844 r
= ERROR_BAD_CONFIGURATION
;
1852 RegCloseKey(udpatch
);
1859 static UINT
msi_check_product_patches(LPCWSTR prodcode
, LPCWSTR usersid
,
1860 MSIINSTALLCONTEXT context
, DWORD filter
, DWORD index
, DWORD
*idx
,
1861 LPWSTR patch
, LPWSTR targetprod
, MSIINSTALLCONTEXT
*targetctx
,
1862 LPWSTR targetsid
, DWORD
*sidsize
, LPWSTR
*transforms
)
1864 MSIPATCHSTATE state
= MSIPATCHSTATE_INVALID
;
1865 LPWSTR ptr
, patches
= NULL
;
1866 HKEY prod
, patchkey
= 0;
1867 HKEY localprod
= 0, localpatch
= 0;
1870 UINT temp
, r
= ERROR_NO_MORE_ITEMS
;
1872 if (MSIREG_OpenProductKey(prodcode
, usersid
, context
,
1873 &prod
, FALSE
) != ERROR_SUCCESS
)
1874 return ERROR_NO_MORE_ITEMS
;
1877 res
= RegGetValueW(prod
, szPatches
, szPatches
, RRF_RT_ANY
, &type
, NULL
,
1879 if (res
!= ERROR_SUCCESS
)
1882 if (type
!= REG_MULTI_SZ
)
1884 r
= ERROR_BAD_CONFIGURATION
;
1888 patches
= msi_alloc(size
);
1891 r
= ERROR_OUTOFMEMORY
;
1895 res
= RegGetValueW(prod
, szPatches
, szPatches
, RRF_RT_ANY
, &type
,
1897 if (res
!= ERROR_SUCCESS
)
1900 for (ptr
= patches
; *ptr
&& r
== ERROR_NO_MORE_ITEMS
; ptr
+= lstrlenW(ptr
) + 1)
1902 if (!unsquash_guid(ptr
, patch
))
1904 r
= ERROR_BAD_CONFIGURATION
;
1909 res
= RegGetValueW(prod
, szPatches
, ptr
, RRF_RT_REG_SZ
,
1910 &type
, NULL
, &size
);
1911 if (res
!= ERROR_SUCCESS
)
1916 *transforms
= msi_alloc(size
);
1919 r
= ERROR_OUTOFMEMORY
;
1923 res
= RegGetValueW(prod
, szPatches
, ptr
, RRF_RT_REG_SZ
,
1924 &type
, *transforms
, &size
);
1925 if (res
!= ERROR_SUCCESS
)
1929 if (context
== MSIINSTALLCONTEXT_USERMANAGED
)
1931 if (!(filter
& MSIPATCHSTATE_APPLIED
))
1933 temp
= msi_get_patch_state(prodcode
, usersid
, context
,
1935 if (temp
== ERROR_BAD_CONFIGURATION
)
1937 r
= ERROR_BAD_CONFIGURATION
;
1941 if (temp
!= ERROR_SUCCESS
|| !(filter
& state
))
1945 else if (context
== MSIINSTALLCONTEXT_USERUNMANAGED
)
1947 if (!(filter
& MSIPATCHSTATE_APPLIED
))
1949 temp
= msi_get_patch_state(prodcode
, usersid
, context
,
1951 if (temp
== ERROR_BAD_CONFIGURATION
)
1953 r
= ERROR_BAD_CONFIGURATION
;
1957 if (temp
!= ERROR_SUCCESS
|| !(filter
& state
))
1962 temp
= MSIREG_OpenUserDataPatchKey(patch
, context
,
1964 RegCloseKey(patchkey
);
1965 if (temp
!= ERROR_SUCCESS
)
1969 else if (context
== MSIINSTALLCONTEXT_MACHINE
)
1973 if (MSIREG_OpenUserDataProductKey(prodcode
, context
, NULL
, &localprod
, FALSE
) == ERROR_SUCCESS
&&
1974 RegOpenKeyExW(localprod
, szPatches
, 0, KEY_READ
, &localpatch
) == ERROR_SUCCESS
&&
1975 RegOpenKeyExW(localpatch
, ptr
, 0, KEY_READ
, &patchkey
) == ERROR_SUCCESS
)
1977 res
= RegGetValueW(patchkey
, NULL
, szState
, RRF_RT_REG_DWORD
,
1978 &type
, &state
, &size
);
1980 if (!(filter
& state
))
1981 res
= ERROR_NO_MORE_ITEMS
;
1983 RegCloseKey(patchkey
);
1986 RegCloseKey(localpatch
);
1987 RegCloseKey(localprod
);
1989 if (res
!= ERROR_SUCCESS
)
2001 lstrcpyW(targetprod
, prodcode
);
2004 *targetctx
= context
;
2008 lstrcpynW(targetsid
, usersid
, *sidsize
);
2009 if (lstrlenW(usersid
) >= *sidsize
)
2010 r
= ERROR_MORE_DATA
;
2015 *sidsize
= lstrlenW(usersid
);
2017 *sidsize
*= sizeof(WCHAR
);
2028 static UINT
msi_enum_patches(LPCWSTR szProductCode
, LPCWSTR szUserSid
,
2029 DWORD dwContext
, DWORD dwFilter
, DWORD dwIndex
, DWORD
*idx
,
2030 LPWSTR szPatchCode
, LPWSTR szTargetProductCode
,
2031 MSIINSTALLCONTEXT
*pdwTargetProductContext
, LPWSTR szTargetUserSid
,
2032 LPDWORD pcchTargetUserSid
, LPWSTR
*szTransforms
)
2034 LPWSTR usersid
= NULL
;
2035 UINT r
= ERROR_INVALID_PARAMETER
;
2039 szUserSid
= usersid
= get_user_sid();
2040 if (!usersid
) return ERROR_FUNCTION_FAILED
;
2043 if (dwContext
& MSIINSTALLCONTEXT_USERMANAGED
)
2045 r
= msi_check_product_patches(szProductCode
, szUserSid
,
2046 MSIINSTALLCONTEXT_USERMANAGED
, dwFilter
,
2047 dwIndex
, idx
, szPatchCode
,
2048 szTargetProductCode
,
2049 pdwTargetProductContext
, szTargetUserSid
,
2050 pcchTargetUserSid
, szTransforms
);
2051 if (r
!= ERROR_NO_MORE_ITEMS
)
2055 if (dwContext
& MSIINSTALLCONTEXT_USERUNMANAGED
)
2057 r
= msi_check_product_patches(szProductCode
, szUserSid
,
2058 MSIINSTALLCONTEXT_USERUNMANAGED
, dwFilter
,
2059 dwIndex
, idx
, szPatchCode
,
2060 szTargetProductCode
,
2061 pdwTargetProductContext
, szTargetUserSid
,
2062 pcchTargetUserSid
, szTransforms
);
2063 if (r
!= ERROR_NO_MORE_ITEMS
)
2067 if (dwContext
& MSIINSTALLCONTEXT_MACHINE
)
2069 r
= msi_check_product_patches(szProductCode
, szUserSid
,
2070 MSIINSTALLCONTEXT_MACHINE
, dwFilter
,
2071 dwIndex
, idx
, szPatchCode
,
2072 szTargetProductCode
,
2073 pdwTargetProductContext
, szTargetUserSid
,
2074 pcchTargetUserSid
, szTransforms
);
2075 if (r
!= ERROR_NO_MORE_ITEMS
)
2084 /***********************************************************************
2085 * MsiEnumPatchesExW [MSI.@]
2087 UINT WINAPI
MsiEnumPatchesExW(LPCWSTR szProductCode
, LPCWSTR szUserSid
,
2088 DWORD dwContext
, DWORD dwFilter
, DWORD dwIndex
, LPWSTR szPatchCode
,
2089 LPWSTR szTargetProductCode
, MSIINSTALLCONTEXT
*pdwTargetProductContext
,
2090 LPWSTR szTargetUserSid
, LPDWORD pcchTargetUserSid
)
2092 WCHAR squished_pc
[GUID_SIZE
];
2096 static DWORD last_index
;
2098 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p, %p)\n",
2099 debugstr_w(szProductCode
), debugstr_w(szUserSid
), dwContext
, dwFilter
,
2100 dwIndex
, szPatchCode
, szTargetProductCode
, pdwTargetProductContext
,
2101 szTargetUserSid
, pcchTargetUserSid
);
2103 if (!szProductCode
|| !squash_guid(szProductCode
, squished_pc
))
2104 return ERROR_INVALID_PARAMETER
;
2106 if (szUserSid
&& !strcmpW( szUserSid
, szLocalSid
))
2107 return ERROR_INVALID_PARAMETER
;
2109 if (dwContext
& MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
2110 return ERROR_INVALID_PARAMETER
;
2112 if (dwContext
<= MSIINSTALLCONTEXT_NONE
||
2113 dwContext
> MSIINSTALLCONTEXT_ALL
)
2114 return ERROR_INVALID_PARAMETER
;
2116 if (dwFilter
<= MSIPATCHSTATE_INVALID
|| dwFilter
> MSIPATCHSTATE_ALL
)
2117 return ERROR_INVALID_PARAMETER
;
2119 if (dwIndex
&& dwIndex
- last_index
!= 1)
2120 return ERROR_INVALID_PARAMETER
;
2125 r
= msi_enum_patches(szProductCode
, szUserSid
, dwContext
, dwFilter
,
2126 dwIndex
, &idx
, szPatchCode
, szTargetProductCode
,
2127 pdwTargetProductContext
, szTargetUserSid
,
2128 pcchTargetUserSid
, NULL
);
2130 if (r
== ERROR_SUCCESS
)
2131 last_index
= dwIndex
;
2138 /***********************************************************************
2139 * MsiEnumPatchesA [MSI.@]
2141 UINT WINAPI
MsiEnumPatchesA(LPCSTR szProduct
, DWORD iPatchIndex
,
2142 LPSTR lpPatchBuf
, LPSTR lpTransformsBuf
, LPDWORD pcchTransformsBuf
)
2144 LPWSTR product
, transforms
;
2145 WCHAR patch
[GUID_SIZE
];
2149 TRACE("(%s %d %p %p %p)\n", debugstr_a(szProduct
), iPatchIndex
,
2150 lpPatchBuf
, lpTransformsBuf
, pcchTransformsBuf
);
2152 if (!szProduct
|| !lpPatchBuf
|| !lpTransformsBuf
|| !pcchTransformsBuf
)
2153 return ERROR_INVALID_PARAMETER
;
2155 product
= strdupAtoW(szProduct
);
2157 return ERROR_OUTOFMEMORY
;
2159 len
= *pcchTransformsBuf
;
2160 transforms
= msi_alloc( len
* sizeof(WCHAR
) );
2163 r
= ERROR_OUTOFMEMORY
;
2167 r
= MsiEnumPatchesW(product
, iPatchIndex
, patch
, transforms
, &len
);
2168 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
2171 WideCharToMultiByte(CP_ACP
, 0, patch
, -1, lpPatchBuf
,
2172 GUID_SIZE
, NULL
, NULL
);
2174 if (!WideCharToMultiByte(CP_ACP
, 0, transforms
, -1, lpTransformsBuf
,
2175 *pcchTransformsBuf
, NULL
, NULL
))
2176 r
= ERROR_MORE_DATA
;
2178 if (r
== ERROR_MORE_DATA
)
2180 lpTransformsBuf
[*pcchTransformsBuf
- 1] = '\0';
2181 *pcchTransformsBuf
= len
* 2;
2184 *pcchTransformsBuf
= strlen( lpTransformsBuf
);
2187 msi_free(transforms
);
2193 /***********************************************************************
2194 * MsiEnumPatchesW [MSI.@]
2196 UINT WINAPI
MsiEnumPatchesW(LPCWSTR szProduct
, DWORD iPatchIndex
,
2197 LPWSTR lpPatchBuf
, LPWSTR lpTransformsBuf
, LPDWORD pcchTransformsBuf
)
2199 WCHAR squished_pc
[GUID_SIZE
];
2200 LPWSTR transforms
= NULL
;
2205 TRACE("(%s %d %p %p %p)\n", debugstr_w(szProduct
), iPatchIndex
,
2206 lpPatchBuf
, lpTransformsBuf
, pcchTransformsBuf
);
2208 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
2209 return ERROR_INVALID_PARAMETER
;
2211 if (!lpPatchBuf
|| !lpTransformsBuf
|| !pcchTransformsBuf
)
2212 return ERROR_INVALID_PARAMETER
;
2214 if (MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
,
2215 &prod
, FALSE
) != ERROR_SUCCESS
&&
2216 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
2217 &prod
, FALSE
) != ERROR_SUCCESS
&&
2218 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
2219 &prod
, FALSE
) != ERROR_SUCCESS
)
2220 return ERROR_UNKNOWN_PRODUCT
;
2224 r
= msi_enum_patches(szProduct
, NULL
, MSIINSTALLCONTEXT_ALL
,
2225 MSIPATCHSTATE_ALL
, iPatchIndex
, &idx
, lpPatchBuf
,
2226 NULL
, NULL
, NULL
, NULL
, &transforms
);
2227 if (r
!= ERROR_SUCCESS
)
2230 lstrcpynW(lpTransformsBuf
, transforms
, *pcchTransformsBuf
);
2231 if (*pcchTransformsBuf
<= lstrlenW(transforms
))
2233 r
= ERROR_MORE_DATA
;
2234 *pcchTransformsBuf
= lstrlenW(transforms
);
2237 *pcchTransformsBuf
= lstrlenW(transforms
);
2240 msi_free(transforms
);
2244 UINT WINAPI
MsiEnumProductsExA( LPCSTR product
, LPCSTR usersid
, DWORD ctx
, DWORD index
,
2245 CHAR installed_product
[GUID_SIZE
],
2246 MSIINSTALLCONTEXT
*installed_ctx
, LPSTR sid
, LPDWORD sid_len
)
2249 WCHAR installed_productW
[GUID_SIZE
], *productW
= NULL
, *usersidW
= NULL
, *sidW
= NULL
;
2251 TRACE("%s, %s, %u, %u, %p, %p, %p, %p\n", debugstr_a(product
), debugstr_a(usersid
),
2252 ctx
, index
, installed_product
, installed_ctx
, sid
, sid_len
);
2254 if (sid
&& !sid_len
) return ERROR_INVALID_PARAMETER
;
2255 if (product
&& !(productW
= strdupAtoW( product
))) return ERROR_OUTOFMEMORY
;
2256 if (usersid
&& !(usersidW
= strdupAtoW( usersid
)))
2258 msi_free( productW
);
2259 return ERROR_OUTOFMEMORY
;
2261 if (sid
&& !(sidW
= msi_alloc( *sid_len
* sizeof(WCHAR
) )))
2263 msi_free( usersidW
);
2264 msi_free( productW
);
2265 return ERROR_OUTOFMEMORY
;
2267 r
= MsiEnumProductsExW( productW
, usersidW
, ctx
, index
, installed_productW
,
2268 installed_ctx
, sidW
, sid_len
);
2269 if (r
== ERROR_SUCCESS
)
2271 if (installed_product
) WideCharToMultiByte( CP_ACP
, 0, installed_productW
, GUID_SIZE
,
2272 installed_product
, GUID_SIZE
, NULL
, NULL
);
2273 if (sid
) WideCharToMultiByte( CP_ACP
, 0, sidW
, *sid_len
+ 1, sid
, *sid_len
+ 1, NULL
, NULL
);
2275 msi_free( productW
);
2276 msi_free( usersidW
);
2281 static UINT
fetch_machine_product( const WCHAR
*match
, DWORD index
, DWORD
*idx
,
2282 WCHAR installed_product
[GUID_SIZE
],
2283 MSIINSTALLCONTEXT
*installed_ctx
, WCHAR
*sid
, DWORD
*sid_len
)
2285 static const WCHAR productsW
[] =
2286 {'S','o','f','t','w','a','r','e','\\','C','l','a','s','s','e','s','\\',
2287 'I','n','s','t','a','l','l','e','r','\\','P','r','o','d','u','c','t','s',0};
2289 WCHAR product
[GUID_SIZE
];
2291 REGSAM access
= KEY_ENUMERATE_SUB_KEYS
| KEY_WOW64_64KEY
;
2294 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, productsW
, 0, access
, &key
))
2295 return ERROR_NO_MORE_ITEMS
;
2297 len
= sizeof(product
)/sizeof(product
[0]);
2298 while (!RegEnumKeyExW( key
, i
, product
, &len
, NULL
, NULL
, NULL
, NULL
))
2300 if (match
&& strcmpW( match
, product
))
2303 len
= sizeof(product
)/sizeof(product
[0]);
2306 if (*idx
== index
) goto found
;
2308 len
= sizeof(product
)/sizeof(product
[0]);
2312 return ERROR_NO_MORE_ITEMS
;
2315 if (sid_len
&& *sid_len
< 1)
2318 r
= ERROR_MORE_DATA
;
2322 if (installed_product
) unsquash_guid( product
, installed_product
);
2323 if (installed_ctx
) *installed_ctx
= MSIINSTALLCONTEXT_MACHINE
;
2335 static UINT
fetch_user_product( const WCHAR
*match
, const WCHAR
*usersid
, DWORD ctx
, DWORD index
,
2336 DWORD
*idx
, WCHAR installed_product
[GUID_SIZE
],
2337 MSIINSTALLCONTEXT
*installed_ctx
, WCHAR
*sid
, DWORD
*sid_len
)
2339 static const WCHAR managedW
[] =
2340 {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
2341 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s',
2342 'i','o','n','\\','I','n','s','t','a','l','l','e','r','\\','M','a','n','a','g','e','d',0};
2343 static const WCHAR managed_productsW
[] =
2344 {'\\','I','n','s','t','a','l','l','e','r','\\','P','r','o','d','u','c','t','s',0};
2345 static const WCHAR unmanaged_productsW
[] =
2346 {'\\','S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
2347 'I','n','s','t','a','l','l','e','r','\\','P','r','o','d','u','c','t','s',0};
2349 const WCHAR
*subkey
;
2350 WCHAR path
[MAX_PATH
], product
[GUID_SIZE
], user
[128];
2351 DWORD i
= 0, j
= 0, len_product
, len_user
;
2352 REGSAM access
= KEY_ENUMERATE_SUB_KEYS
| KEY_WOW64_64KEY
;
2353 HKEY key_users
, key_products
;
2355 if (ctx
== MSIINSTALLCONTEXT_USERMANAGED
)
2357 subkey
= managed_productsW
;
2358 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, managedW
, 0, access
, &key_users
))
2359 return ERROR_NO_MORE_ITEMS
;
2361 else if (ctx
== MSIINSTALLCONTEXT_USERUNMANAGED
)
2363 subkey
= unmanaged_productsW
;
2364 if (RegOpenKeyExW( HKEY_USERS
, NULL
, 0, access
, &key_users
))
2365 return ERROR_NO_MORE_ITEMS
;
2367 else return ERROR_INVALID_PARAMETER
;
2369 len_user
= sizeof(user
)/sizeof(user
[0]);
2370 while (!RegEnumKeyExW( key_users
, i
, user
, &len_user
, NULL
, NULL
, NULL
, NULL
))
2372 if (strcmpW( usersid
, user
) && strcmpW( usersid
, szAllSid
))
2375 len_user
= sizeof(user
)/sizeof(user
[0]);
2378 strcpyW( path
, user
);
2379 strcatW( path
, subkey
);
2380 if (RegOpenKeyExW( key_users
, path
, 0, access
, &key_products
))
2383 len_user
= sizeof(user
)/sizeof(user
[0]);
2386 len_product
= sizeof(product
)/sizeof(product
[0]);
2387 while (!RegEnumKeyExW( key_products
, j
, product
, &len_product
, NULL
, NULL
, NULL
, NULL
))
2389 if (match
&& strcmpW( match
, product
))
2392 len_product
= sizeof(product
)/sizeof(product
[0]);
2395 if (*idx
== index
) goto found
;
2397 len_product
= sizeof(product
)/sizeof(product
[0]);
2400 RegCloseKey( key_products
);
2401 len_user
= sizeof(user
)/sizeof(user
[0]);
2404 RegCloseKey( key_users
);
2405 return ERROR_NO_MORE_ITEMS
;
2408 if (sid_len
&& *sid_len
<= len_user
)
2410 *sid_len
= len_user
;
2411 r
= ERROR_MORE_DATA
;
2415 if (installed_product
) unsquash_guid( product
, installed_product
);
2416 if (installed_ctx
) *installed_ctx
= ctx
;
2419 strcpyW( sid
, user
);
2420 *sid_len
= len_user
;
2424 RegCloseKey( key_products
);
2425 RegCloseKey( key_users
);
2429 static UINT
enum_products( const WCHAR
*product
, const WCHAR
*usersid
, DWORD ctx
, DWORD index
,
2430 DWORD
*idx
, WCHAR installed_product
[GUID_SIZE
],
2431 MSIINSTALLCONTEXT
*installed_ctx
, WCHAR
*sid
, DWORD
*sid_len
)
2433 UINT r
= ERROR_NO_MORE_ITEMS
;
2438 usersid
= user
= get_user_sid();
2439 if (!user
) return ERROR_FUNCTION_FAILED
;
2441 if (ctx
& MSIINSTALLCONTEXT_MACHINE
)
2443 r
= fetch_machine_product( product
, index
, idx
, installed_product
, installed_ctx
,
2445 if (r
!= ERROR_NO_MORE_ITEMS
) goto done
;
2447 if (ctx
& MSIINSTALLCONTEXT_USERUNMANAGED
)
2449 r
= fetch_user_product( product
, usersid
, MSIINSTALLCONTEXT_USERUNMANAGED
, index
,
2450 idx
, installed_product
, installed_ctx
, sid
, sid_len
);
2451 if (r
!= ERROR_NO_MORE_ITEMS
) goto done
;
2453 if (ctx
& MSIINSTALLCONTEXT_USERMANAGED
)
2455 r
= fetch_user_product( product
, usersid
, MSIINSTALLCONTEXT_USERMANAGED
, index
,
2456 idx
, installed_product
, installed_ctx
, sid
, sid_len
);
2457 if (r
!= ERROR_NO_MORE_ITEMS
) goto done
;
2465 UINT WINAPI
MsiEnumProductsExW( LPCWSTR product
, LPCWSTR usersid
, DWORD ctx
, DWORD index
,
2466 WCHAR installed_product
[GUID_SIZE
],
2467 MSIINSTALLCONTEXT
*installed_ctx
, LPWSTR sid
, LPDWORD sid_len
)
2471 static DWORD last_index
;
2473 TRACE("%s, %s, %u, %u, %p, %p, %p, %p\n", debugstr_w(product
), debugstr_w(usersid
),
2474 ctx
, index
, installed_product
, installed_ctx
, sid
, sid_len
);
2476 if ((sid
&& !sid_len
) || !ctx
|| (usersid
&& ctx
== MSIINSTALLCONTEXT_MACHINE
))
2477 return ERROR_INVALID_PARAMETER
;
2479 if (index
&& index
- last_index
!= 1)
2480 return ERROR_INVALID_PARAMETER
;
2482 if (!index
) last_index
= 0;
2484 r
= enum_products( product
, usersid
, ctx
, index
, &idx
, installed_product
, installed_ctx
,
2486 if (r
== ERROR_SUCCESS
)