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_LocalManaged_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',0};
109 static const WCHAR szInstaller_LocalManagedProd_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','\\','P','r','o','d','u','c','t','s','\\','%','s',0};
115 static const WCHAR szInstaller_LocalManagedFeat_fmt
[] = {
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','\\','M','a','n','a','g','e','d','\\','%','s','\\',
119 'I','n','s','t','a','l','l','e','r','\\','F','e','a','t','u','r','e','s','\\','%','s',0};
121 static const WCHAR szInstaller_Products
[] = {
122 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
123 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
124 'I','n','s','t','a','l','l','e','r','\\','P','r','o','d','u','c','t','s',0};
126 static const WCHAR szInstaller_Patches
[] = {
127 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
128 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
129 'I','n','s','t','a','l','l','e','r','\\','P','a','t','c','h','e','s',0};
131 static const WCHAR szInstaller_Components
[] = {
132 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
133 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
134 'I','n','s','t','a','l','l','e','r','\\','C','o','m','p','o','n','e','n','t','s',0};
136 static const WCHAR szInstaller_LocalClassesProducts
[] = {
137 'S','o','f','t','w','a','r','e','\\','C','l','a','s','s','e','s','\\',
138 'I','n','s','t','a','l','l','e','r','\\','P','r','o','d','u','c','t','s',0};
140 static const WCHAR szInstaller_LocalClassesFeatures
[] = {
141 'S','o','f','t','w','a','r','e','\\','C','l','a','s','s','e','s','\\',
142 'I','n','s','t','a','l','l','e','r','\\','F','e','a','t','u','r','e','s',0};
144 static const WCHAR szInstaller_LocalClassesProd
[] = {
145 'S','o','f','t','w','a','r','e','\\','C','l','a','s','s','e','s','\\',
146 'I','n','s','t','a','l','l','e','r','\\','P','r','o','d','u','c','t','s','\\',0};
148 static const WCHAR szInstaller_LocalClassesFeat
[] = {
149 'S','o','f','t','w','a','r','e','\\','C','l','a','s','s','e','s','\\',
150 'I','n','s','t','a','l','l','e','r','\\','F','e','a','t','u','r','e','s','\\',0};
152 static const WCHAR szInstaller_ClassesUpgradeCode
[] = {
153 'S','o','f','t','w','a','r','e','\\','C','l','a','s','s','e','s','\\',
154 'I','n','s','t','a','l','l','e','r','\\','U','p','g','r','a','d','e','C','o','d','e','s','\\',0};
156 static const WCHAR szInstaller_ClassesUpgradeCodes
[] = {
157 'S','o','f','t','w','a','r','e','\\','C','l','a','s','s','e','s','\\',
158 'I','n','s','t','a','l','l','e','r','\\','U','p','g','r','a','d','e','C','o','d','e','s',0};
160 static const WCHAR szInstaller_Features
[] = {
161 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
162 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
163 'I','n','s','t','a','l','l','e','r','\\','F','e','a','t','u','r','e','s','\\',0};
165 static const WCHAR szInstaller_UpgradeCodes
[] = {
166 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
167 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
168 'I','n','s','t','a','l','l','e','r','\\','U','p','g','r','a','d','e','C','o','d','e','s','\\',0};
170 static const WCHAR szInstaller_UserUpgradeCodes
[] = {
171 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
172 'I','n','s','t','a','l','l','e','r','\\','U','p','g','r','a','d','e','C','o','d','e','s','\\',0};
174 static const WCHAR szUninstall
[] = {
175 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
176 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
177 'U','n','i','n','s','t','a','l','l','\\',0};
179 static const WCHAR szUninstall_32node
[] = {
180 'S','o','f','t','w','a','r','e','\\','W','o','w','6','4','3','2','N','o','d','e','\\',
181 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
182 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','U','n','i','n','s','t','a','l','l','\\',0};
184 static const WCHAR szUserComponents
[] = {
185 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
186 'I','n','s','t','a','l','l','e','r','\\','C','o','m','p','o','n','e','n','t','s','\\',0};
188 static const WCHAR szUserFeatures
[] = {
189 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
190 'I','n','s','t','a','l','l','e','r','\\','F','e','a','t','u','r','e','s','\\',0};
192 static const WCHAR szUserProducts
[] = {
193 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
194 'I','n','s','t','a','l','l','e','r','\\','P','r','o','d','u','c','t','s','\\',0};
196 static const WCHAR szUserPatches
[] = {
197 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
198 'I','n','s','t','a','l','l','e','r','\\','P','a','t','c','h','e','s','\\',0};
200 BOOL
unsquash_guid(LPCWSTR in
, LPWSTR out
)
204 if (lstrlenW(in
) != 32)
219 out
[n
++] = in
[17+i
*2];
220 out
[n
++] = in
[16+i
*2];
225 out
[n
++] = in
[17+i
*2];
226 out
[n
++] = in
[16+i
*2];
233 BOOL
squash_guid(LPCWSTR in
, LPWSTR out
)
240 if (FAILED(CLSIDFromString((LPCOLESTR
)in
, &guid
)))
254 out
[17+i
*2] = in
[n
++];
255 out
[16+i
*2] = in
[n
++];
260 out
[17+i
*2] = in
[n
++];
261 out
[16+i
*2] = in
[n
++];
268 /* tables for encoding and decoding base85 */
269 static const unsigned char table_dec85
[0x80] = {
270 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
271 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
272 0xff,0x00,0xff,0xff,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0xff,
273 0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0xff,0xff,0xff,0x16,0xff,0x17,
274 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,
275 0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0xff,0x34,0x35,0x36,
276 0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44,0x45,0x46,
277 0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0xff,0x53,0x54,0xff,
280 static const char table_enc85
[] =
281 "!$%&'()*+,-.0123456789=?@ABCDEFGHIJKLMNO"
282 "PQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwx"
286 * Converts a base85 encoded guid into a GUID pointer
287 * Base85 encoded GUIDs should be 20 characters long.
289 * returns TRUE if successful, FALSE if not
291 BOOL
decode_base85_guid( LPCWSTR str
, GUID
*guid
)
293 DWORD i
, val
= 0, base
= 1, *p
;
299 for( i
=0; i
<20; i
++ )
306 val
+= table_dec85
[str
[i
]] * base
;
309 if( table_dec85
[str
[i
]] == 0xff )
319 * Encodes a base85 guid given a GUID pointer
320 * Caller should provide a 21 character buffer for the encoded string.
322 * returns TRUE if successful, FALSE if not
324 BOOL
encode_base85_guid( GUID
*guid
, LPWSTR str
)
326 unsigned int x
, *p
, i
;
328 p
= (unsigned int*) guid
;
332 *str
++ = table_enc85
[x
%85];
334 *str
++ = table_enc85
[x
%85];
336 *str
++ = table_enc85
[x
%85];
338 *str
++ = table_enc85
[x
%85];
340 *str
++ = table_enc85
[x
%85];
347 DWORD
msi_version_str_to_dword(LPCWSTR p
)
349 DWORD major
, minor
= 0, build
= 0, version
= 0;
360 p
= strchrW(p
+1, '.');
365 return MAKELONG(build
, MAKEWORD(minor
, major
));
368 LONG
msi_reg_set_val_str( HKEY hkey
, LPCWSTR name
, LPCWSTR value
)
371 if (!value
) value
= szEmpty
;
372 len
= (lstrlenW(value
) + 1) * sizeof (WCHAR
);
373 return RegSetValueExW( hkey
, name
, 0, REG_SZ
, (const BYTE
*)value
, len
);
376 LONG
msi_reg_set_val_multi_str( HKEY hkey
, LPCWSTR name
, LPCWSTR value
)
379 while (*p
) p
+= lstrlenW(p
) + 1;
380 return RegSetValueExW( hkey
, name
, 0, REG_MULTI_SZ
,
381 (const BYTE
*)value
, (p
+ 1 - value
) * sizeof(WCHAR
) );
384 LONG
msi_reg_set_val_dword( HKEY hkey
, LPCWSTR name
, DWORD val
)
386 return RegSetValueExW( hkey
, name
, 0, REG_DWORD
, (LPBYTE
)&val
, sizeof (DWORD
) );
389 LONG
msi_reg_set_subkey_val( HKEY hkey
, LPCWSTR path
, LPCWSTR name
, LPCWSTR val
)
394 r
= RegCreateKeyW( hkey
, path
, &hsubkey
);
395 if (r
!= ERROR_SUCCESS
)
397 r
= msi_reg_set_val_str( hsubkey
, name
, val
);
398 RegCloseKey( hsubkey
);
402 LPWSTR
msi_reg_get_val_str( HKEY hkey
, LPCWSTR name
)
408 r
= RegQueryValueExW(hkey
, name
, NULL
, NULL
, NULL
, &len
);
409 if (r
!= ERROR_SUCCESS
)
412 len
+= sizeof (WCHAR
);
413 val
= msi_alloc( len
);
417 RegQueryValueExW(hkey
, name
, NULL
, NULL
, (LPBYTE
) val
, &len
);
421 BOOL
msi_reg_get_val_dword( HKEY hkey
, LPCWSTR name
, DWORD
*val
)
423 DWORD type
, len
= sizeof (DWORD
);
424 LONG r
= RegQueryValueExW(hkey
, name
, NULL
, &type
, (LPBYTE
) val
, &len
);
425 return r
== ERROR_SUCCESS
&& type
== REG_DWORD
;
428 static WCHAR
*get_user_sid(void)
435 if (!OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY
, &token
)) return NULL
;
436 if (!(user
= msi_alloc( size
)))
438 CloseHandle( token
);
441 if (!GetTokenInformation( token
, TokenUser
, user
, size
, &size
))
444 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
|| !(user
= msi_alloc( size
)))
446 CloseHandle( token
);
449 GetTokenInformation( token
, TokenUser
, user
, size
, &size
);
451 CloseHandle( token
);
452 if (!ConvertSidToStringSidW( user
->User
.Sid
, &ret
))
461 UINT
MSIREG_OpenUninstallKey(const WCHAR
*product
, enum platform platform
, HKEY
*key
, BOOL create
)
463 WCHAR keypath
[0x200];
465 TRACE("%s\n", debugstr_w(product
));
467 if (is_64bit
&& platform
== PLATFORM_INTEL
)
469 strcpyW(keypath
, szUninstall_32node
);
470 strcatW(keypath
, product
);
474 strcpyW(keypath
, szUninstall
);
475 strcatW(keypath
, product
);
477 if (create
) return RegCreateKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, key
, NULL
);
478 return RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, KEY_ALL_ACCESS
, key
);
481 UINT
MSIREG_DeleteUninstallKey(const WCHAR
*product
, enum platform platform
)
483 WCHAR keypath
[0x200];
485 TRACE("%s\n", debugstr_w(product
));
487 if (is_64bit
&& platform
== PLATFORM_INTEL
)
489 strcpyW(keypath
, szUninstall_32node
);
490 strcatW(keypath
, product
);
494 strcpyW(keypath
, szUninstall
);
495 strcatW(keypath
, product
);
497 return RegDeleteTreeW(HKEY_LOCAL_MACHINE
, keypath
);
500 UINT
MSIREG_OpenProductKey(LPCWSTR szProduct
, LPCWSTR szUserSid
, MSIINSTALLCONTEXT context
, HKEY
*key
, BOOL create
)
502 LPWSTR usersid
= NULL
;
503 HKEY root
= HKEY_LOCAL_MACHINE
;
504 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
505 WCHAR squished_pc
[GUID_SIZE
], keypath
[MAX_PATH
];
507 if (!squash_guid(szProduct
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
508 TRACE("%s squished %s\n", debugstr_w(szProduct
), debugstr_w(squished_pc
));
510 if (context
== MSIINSTALLCONTEXT_MACHINE
)
512 strcpyW(keypath
, szInstaller_LocalClassesProd
);
513 strcatW(keypath
, squished_pc
);
515 else if (context
== MSIINSTALLCONTEXT_USERUNMANAGED
)
517 root
= HKEY_CURRENT_USER
;
518 strcpyW(keypath
, szUserProducts
);
519 strcatW(keypath
, squished_pc
);
525 if (!(usersid
= get_user_sid()))
527 ERR("Failed to retrieve user SID\n");
528 return ERROR_FUNCTION_FAILED
;
532 sprintfW(keypath
, szInstaller_LocalManagedProd_fmt
, szUserSid
, squished_pc
);
535 if (create
) return RegCreateKeyExW(root
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
536 return RegOpenKeyExW(root
, keypath
, 0, access
, key
);
539 UINT
MSIREG_DeleteUserProductKey(LPCWSTR szProduct
)
541 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
543 if (!squash_guid(szProduct
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
544 TRACE("%s squished %s\n", debugstr_w(szProduct
), debugstr_w(squished_pc
));
546 strcpyW(keypath
, szUserProducts
);
547 strcatW(keypath
, squished_pc
);
548 return RegDeleteTreeW(HKEY_CURRENT_USER
, keypath
);
551 UINT
MSIREG_OpenUserPatchesKey(LPCWSTR szPatch
, HKEY
*key
, BOOL create
)
553 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
555 if (!squash_guid(szPatch
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
556 TRACE("%s squished %s\n", debugstr_w(szPatch
), debugstr_w(squished_pc
));
558 strcpyW(keypath
, szUserPatches
);
559 strcatW(keypath
, squished_pc
);
561 if (create
) return RegCreateKeyW(HKEY_CURRENT_USER
, keypath
, key
);
562 return RegOpenKeyW(HKEY_CURRENT_USER
, keypath
, key
);
565 UINT
MSIREG_OpenFeaturesKey(LPCWSTR szProduct
, MSIINSTALLCONTEXT context
, HKEY
*key
, BOOL create
)
568 HKEY root
= HKEY_LOCAL_MACHINE
;
569 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
570 WCHAR squished_pc
[GUID_SIZE
], keypath
[MAX_PATH
];
572 if (!squash_guid(szProduct
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
573 TRACE("%s squished %s\n", debugstr_w(szProduct
), debugstr_w(squished_pc
));
575 if (context
== MSIINSTALLCONTEXT_MACHINE
)
577 strcpyW(keypath
, szInstaller_LocalClassesFeat
);
578 strcatW(keypath
, squished_pc
);
580 else if (context
== MSIINSTALLCONTEXT_USERUNMANAGED
)
582 root
= HKEY_CURRENT_USER
;
583 strcpyW(keypath
, szUserFeatures
);
584 strcatW(keypath
, squished_pc
);
588 if (!(usersid
= get_user_sid()))
590 ERR("Failed to retrieve user SID\n");
591 return ERROR_FUNCTION_FAILED
;
593 sprintfW(keypath
, szInstaller_LocalManagedFeat_fmt
, usersid
, squished_pc
);
596 if (create
) return RegCreateKeyExW(root
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
597 return RegOpenKeyExW(root
, keypath
, 0, access
, key
);
600 UINT
MSIREG_DeleteUserFeaturesKey(LPCWSTR szProduct
)
602 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
604 if (!squash_guid(szProduct
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
605 TRACE("%s squished %s\n", debugstr_w(szProduct
), debugstr_w(squished_pc
));
607 strcpyW(keypath
, szUserFeatures
);
608 strcatW(keypath
, squished_pc
);
609 return RegDeleteTreeW(HKEY_CURRENT_USER
, keypath
);
612 static UINT
MSIREG_OpenInstallerFeaturesKey(LPCWSTR szProduct
, HKEY
*key
, BOOL create
)
614 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
615 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
617 if (!squash_guid(szProduct
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
618 TRACE("%s squished %s\n", debugstr_w(szProduct
), debugstr_w(squished_pc
));
620 strcpyW(keypath
, szInstaller_Features
);
621 strcatW(keypath
, squished_pc
);
623 if (create
) return RegCreateKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
624 return RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, key
);
627 UINT
MSIREG_OpenUserDataFeaturesKey(LPCWSTR szProduct
, MSIINSTALLCONTEXT context
, HKEY
*key
, BOOL create
)
630 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
631 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
633 if (!squash_guid(szProduct
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
634 TRACE("%s squished %s\n", debugstr_w(szProduct
), debugstr_w(squished_pc
));
636 if (context
== MSIINSTALLCONTEXT_MACHINE
)
638 sprintfW(keypath
, szUserDataFeatures_fmt
, szLocalSid
, squished_pc
);
642 if (!(usersid
= get_user_sid()))
644 ERR("Failed to retrieve user SID\n");
645 return ERROR_FUNCTION_FAILED
;
647 sprintfW(keypath
, szUserDataFeatures_fmt
, usersid
, squished_pc
);
650 if (create
) return RegCreateKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
651 return RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, key
);
654 UINT
MSIREG_OpenUserComponentsKey(LPCWSTR szComponent
, HKEY
*key
, BOOL create
)
656 WCHAR squished_cc
[GUID_SIZE
], keypath
[0x200];
658 if (!squash_guid(szComponent
, squished_cc
)) return ERROR_FUNCTION_FAILED
;
659 TRACE("%s squished %s\n", debugstr_w(szComponent
), debugstr_w(squished_cc
));
661 strcpyW(keypath
, szUserComponents
);
662 strcatW(keypath
, squished_cc
);
664 if (create
) return RegCreateKeyW(HKEY_CURRENT_USER
, keypath
, key
);
665 return RegOpenKeyW(HKEY_CURRENT_USER
, keypath
, key
);
668 UINT
MSIREG_OpenUserDataComponentKey(LPCWSTR szComponent
, LPCWSTR szUserSid
, HKEY
*key
, BOOL create
)
670 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
671 WCHAR comp
[GUID_SIZE
], keypath
[0x200];
674 if (!squash_guid(szComponent
, comp
)) return ERROR_FUNCTION_FAILED
;
675 TRACE("%s squished %s\n", debugstr_w(szComponent
), debugstr_w(comp
));
679 if (!(usersid
= get_user_sid()))
681 ERR("Failed to retrieve user SID\n");
682 return ERROR_FUNCTION_FAILED
;
684 sprintfW(keypath
, szUserDataComp_fmt
, usersid
, comp
);
688 sprintfW(keypath
, szUserDataComp_fmt
, szUserSid
, comp
);
690 if (create
) return RegCreateKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
691 return RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, key
);
694 UINT
MSIREG_DeleteUserDataComponentKey(LPCWSTR szComponent
, LPCWSTR szUserSid
)
696 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
697 WCHAR comp
[GUID_SIZE
], keypath
[0x200];
702 if (!squash_guid(szComponent
, comp
)) return ERROR_FUNCTION_FAILED
;
703 TRACE("%s squished %s\n", debugstr_w(szComponent
), debugstr_w(comp
));
707 if (!(usersid
= get_user_sid()))
709 ERR("Failed to retrieve user SID\n");
710 return ERROR_FUNCTION_FAILED
;
712 sprintfW(keypath
, szUserDataComponents_fmt
, usersid
);
716 sprintfW(keypath
, szUserDataComponents_fmt
, szUserSid
);
718 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, &hkey
)) return ERROR_SUCCESS
;
719 r
= RegDeleteTreeW(hkey
, comp
);
724 UINT
MSIREG_OpenUserDataProductKey(LPCWSTR szProduct
, MSIINSTALLCONTEXT dwContext
, LPCWSTR szUserSid
, HKEY
*key
, BOOL create
)
726 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
727 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
730 if (!squash_guid(szProduct
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
731 TRACE("%s squished %s\n", debugstr_w(szProduct
), debugstr_w(squished_pc
));
733 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
734 sprintfW(keypath
, szUserDataProd_fmt
, szLocalSid
, squished_pc
);
736 sprintfW(keypath
, szUserDataProd_fmt
, szUserSid
, squished_pc
);
739 if (!(usersid
= get_user_sid()))
741 ERR("Failed to retrieve user SID\n");
742 return ERROR_FUNCTION_FAILED
;
744 sprintfW(keypath
, szUserDataProd_fmt
, usersid
, squished_pc
);
747 if (create
) return RegCreateKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
748 return RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, key
);
751 UINT
MSIREG_OpenUserDataPatchKey(LPCWSTR szPatch
, MSIINSTALLCONTEXT dwContext
, HKEY
*key
, BOOL create
)
753 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
754 WCHAR squished_patch
[GUID_SIZE
], keypath
[0x200];
757 if (!squash_guid(szPatch
, squished_patch
)) return ERROR_FUNCTION_FAILED
;
758 TRACE("%s squished %s\n", debugstr_w(szPatch
), debugstr_w(squished_patch
));
760 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
761 sprintfW(keypath
, szUserDataPatch_fmt
, szLocalSid
, squished_patch
);
764 if (!(usersid
= get_user_sid()))
766 ERR("Failed to retrieve user SID\n");
767 return ERROR_FUNCTION_FAILED
;
769 sprintfW(keypath
, szUserDataPatch_fmt
, usersid
, squished_patch
);
772 if (create
) return RegCreateKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
773 return RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, key
);
776 UINT
MSIREG_DeleteUserDataPatchKey(LPCWSTR patch
, MSIINSTALLCONTEXT context
)
778 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
779 WCHAR squished_patch
[GUID_SIZE
], keypath
[0x200];
784 if (!squash_guid(patch
, squished_patch
)) return ERROR_FUNCTION_FAILED
;
785 TRACE("%s squished %s\n", debugstr_w(patch
), debugstr_w(squished_patch
));
787 if (context
== MSIINSTALLCONTEXT_MACHINE
)
788 sprintfW(keypath
, szUserDataPatches_fmt
, szLocalSid
);
791 if (!(usersid
= get_user_sid()))
793 ERR("Failed to retrieve user SID\n");
794 return ERROR_FUNCTION_FAILED
;
796 sprintfW(keypath
, szUserDataPatches_fmt
, usersid
);
799 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, &hkey
)) return ERROR_SUCCESS
;
800 r
= RegDeleteTreeW(hkey
, squished_patch
);
805 UINT
MSIREG_OpenUserDataProductPatchesKey(LPCWSTR product
, MSIINSTALLCONTEXT context
, HKEY
*key
, BOOL create
)
807 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
808 WCHAR squished_product
[GUID_SIZE
], keypath
[0x200];
811 if (!squash_guid(product
, squished_product
)) return ERROR_FUNCTION_FAILED
;
812 TRACE("%s squished %s\n", debugstr_w(product
), debugstr_w(squished_product
));
814 if (context
== MSIINSTALLCONTEXT_MACHINE
)
815 sprintfW(keypath
, szUserDataProductPatches_fmt
, szLocalSid
, squished_product
);
818 if (!(usersid
= get_user_sid()))
820 ERR("Failed to retrieve user SID\n");
821 return ERROR_FUNCTION_FAILED
;
823 sprintfW(keypath
, szUserDataProductPatches_fmt
, usersid
, squished_product
);
826 if (create
) return RegCreateKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
827 return RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, key
);
830 UINT
MSIREG_OpenInstallProps(LPCWSTR szProduct
, MSIINSTALLCONTEXT dwContext
, LPCWSTR szUserSid
, HKEY
*key
, BOOL create
)
833 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
834 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
836 if (!squash_guid(szProduct
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
837 TRACE("%s squished %s\n", debugstr_w(szProduct
), debugstr_w(squished_pc
));
839 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
840 sprintfW(keypath
, szInstallProperties_fmt
, szLocalSid
, squished_pc
);
842 sprintfW(keypath
, szInstallProperties_fmt
, szUserSid
, squished_pc
);
845 if (!(usersid
= get_user_sid()))
847 ERR("Failed to retrieve user SID\n");
848 return ERROR_FUNCTION_FAILED
;
850 sprintfW(keypath
, szInstallProperties_fmt
, usersid
, squished_pc
);
853 if (create
) return RegCreateKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
854 return RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, key
);
857 UINT
MSIREG_DeleteUserDataProductKey(LPCWSTR szProduct
)
859 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
860 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
865 if (!squash_guid(szProduct
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
866 TRACE("%s squished %s\n", debugstr_w(szProduct
), debugstr_w(squished_pc
));
868 if (!(usersid
= get_user_sid()))
870 ERR("Failed to retrieve user SID\n");
871 return ERROR_FUNCTION_FAILED
;
873 sprintfW(keypath
, szUserDataProducts_fmt
, usersid
);
876 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, &hkey
)) return ERROR_SUCCESS
;
877 r
= RegDeleteTreeW(hkey
, squished_pc
);
882 UINT
MSIREG_DeleteProductKey(LPCWSTR szProduct
)
884 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
885 WCHAR squished_pc
[GUID_SIZE
];
889 if (!squash_guid(szProduct
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
890 TRACE("%s squished %s\n", debugstr_w(szProduct
), debugstr_w(squished_pc
));
892 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, szInstaller_Products
, 0, access
, &hkey
)) return ERROR_SUCCESS
;
893 r
= RegDeleteTreeW(hkey
, squished_pc
);
898 UINT
MSIREG_OpenPatchesKey(LPCWSTR szPatch
, HKEY
*key
, BOOL create
)
900 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
901 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
903 if (!squash_guid(szPatch
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
904 TRACE("%s squished %s\n", debugstr_w(szPatch
), debugstr_w(squished_pc
));
906 sprintfW(keypath
, szInstaller_Patches
, squished_pc
);
908 if (create
) return RegCreateKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
909 return RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, key
);
912 UINT
MSIREG_OpenUpgradeCodesKey(LPCWSTR szUpgradeCode
, HKEY
*key
, BOOL create
)
914 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
915 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
917 if (!squash_guid(szUpgradeCode
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
918 TRACE("%s squished %s\n", debugstr_w(szUpgradeCode
), debugstr_w(squished_pc
));
920 strcpyW(keypath
, szInstaller_UpgradeCodes
);
921 strcatW(keypath
, squished_pc
);
923 if (create
) return RegCreateKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
924 return RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, key
);
927 UINT
MSIREG_OpenUserUpgradeCodesKey(LPCWSTR szUpgradeCode
, HKEY
* key
, BOOL create
)
929 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
931 if (!squash_guid(szUpgradeCode
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
932 TRACE("%s squished %s\n", debugstr_w(szUpgradeCode
), debugstr_w(squished_pc
));
934 strcpyW(keypath
, szInstaller_UserUpgradeCodes
);
935 strcatW(keypath
, squished_pc
);
937 if (create
) return RegCreateKeyW(HKEY_CURRENT_USER
, keypath
, key
);
938 return RegOpenKeyW(HKEY_CURRENT_USER
, keypath
, key
);
941 UINT
MSIREG_DeleteUserUpgradeCodesKey(LPCWSTR szUpgradeCode
)
943 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
945 if (!squash_guid(szUpgradeCode
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
946 TRACE("%s squished %s\n", debugstr_w(szUpgradeCode
), debugstr_w(squished_pc
));
948 strcpyW(keypath
, szInstaller_UserUpgradeCodes
);
949 strcatW(keypath
, squished_pc
);
950 return RegDeleteTreeW(HKEY_CURRENT_USER
, keypath
);
953 UINT
MSIREG_DeleteLocalClassesProductKey(LPCWSTR szProductCode
)
955 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
956 WCHAR squished_pc
[GUID_SIZE
];
960 if (!squash_guid(szProductCode
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
961 TRACE("%s squished %s\n", debugstr_w(szProductCode
), debugstr_w(squished_pc
));
963 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, szInstaller_LocalClassesProducts
, 0, access
, &hkey
)) return ERROR_SUCCESS
;
964 r
= RegDeleteTreeW(hkey
, squished_pc
);
969 UINT
MSIREG_DeleteLocalClassesFeaturesKey(LPCWSTR szProductCode
)
971 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
972 WCHAR squished_pc
[GUID_SIZE
];
976 if (!squash_guid(szProductCode
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
977 TRACE("%s squished %s\n", debugstr_w(szProductCode
), debugstr_w(squished_pc
));
979 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, szInstaller_LocalClassesFeatures
, 0, access
, &hkey
)) return ERROR_SUCCESS
;
980 r
= RegDeleteTreeW(hkey
, squished_pc
);
985 UINT
MSIREG_OpenClassesUpgradeCodesKey(LPCWSTR szUpgradeCode
, HKEY
*key
, BOOL create
)
987 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
988 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
990 if (!squash_guid(szUpgradeCode
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
991 TRACE("%s squished %s\n", debugstr_w(szUpgradeCode
), debugstr_w(squished_pc
));
993 strcpyW(keypath
, szInstaller_ClassesUpgradeCode
);
994 strcatW(keypath
, squished_pc
);
996 if (create
) return RegCreateKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
997 return RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, key
);
1000 UINT
MSIREG_DeleteClassesUpgradeCodesKey(LPCWSTR szUpgradeCode
)
1002 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
1003 WCHAR squished_pc
[GUID_SIZE
];
1007 if (!squash_guid(szUpgradeCode
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
1008 TRACE("%s squished %s\n", debugstr_w(szUpgradeCode
), debugstr_w(squished_pc
));
1010 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, szInstaller_ClassesUpgradeCodes
, 0, access
, &hkey
)) return ERROR_SUCCESS
;
1011 r
= RegDeleteTreeW(hkey
, squished_pc
);
1016 /*************************************************************************
1017 * MsiDecomposeDescriptorW [MSI.@]
1019 * Decomposes an MSI descriptor into product, feature and component parts.
1020 * An MSI descriptor is a string of the form:
1021 * [base 85 guid] [feature code] '>' [base 85 guid]
1024 * szDescriptor [I] the descriptor to decompose
1025 * szProduct [O] buffer of MAX_FEATURE_CHARS+1 for the product guid
1026 * szFeature [O] buffer of MAX_FEATURE_CHARS+1 for the feature code
1027 * szComponent [O] buffer of MAX_FEATURE_CHARS+1 for the component guid
1028 * pUsed [O] the length of the descriptor
1031 * ERROR_SUCCESS if everything worked correctly
1032 * ERROR_INVALID_PARAMETER if the descriptor was invalid
1035 UINT WINAPI
MsiDecomposeDescriptorW( LPCWSTR szDescriptor
, LPWSTR szProduct
,
1036 LPWSTR szFeature
, LPWSTR szComponent
, LPDWORD pUsed
)
1040 GUID product
, component
;
1042 TRACE("%s %p %p %p %p\n", debugstr_w(szDescriptor
), szProduct
,
1043 szFeature
, szComponent
, pUsed
);
1045 r
= decode_base85_guid( szDescriptor
, &product
);
1047 return ERROR_INVALID_PARAMETER
;
1049 TRACE("product %s\n", debugstr_guid( &product
));
1051 p
= strchrW(&szDescriptor
[20],'>');
1053 return ERROR_INVALID_PARAMETER
;
1055 len
= (p
- &szDescriptor
[20]);
1056 if( len
> MAX_FEATURE_CHARS
)
1057 return ERROR_INVALID_PARAMETER
;
1059 TRACE("feature %s\n", debugstr_wn( &szDescriptor
[20], len
));
1061 r
= decode_base85_guid( p
+1, &component
);
1063 return ERROR_INVALID_PARAMETER
;
1065 TRACE("component %s\n", debugstr_guid( &component
));
1068 StringFromGUID2( &product
, szProduct
, MAX_FEATURE_CHARS
+1 );
1070 StringFromGUID2( &component
, szComponent
, MAX_FEATURE_CHARS
+1 );
1073 memcpy( szFeature
, &szDescriptor
[20], len
*sizeof(WCHAR
) );
1076 len
= ( &p
[21] - szDescriptor
);
1078 TRACE("length = %d\n", len
);
1079 if (pUsed
) *pUsed
= len
;
1081 return ERROR_SUCCESS
;
1084 UINT WINAPI
MsiDecomposeDescriptorA( LPCSTR szDescriptor
, LPSTR szProduct
,
1085 LPSTR szFeature
, LPSTR szComponent
, LPDWORD pUsed
)
1087 WCHAR product
[MAX_FEATURE_CHARS
+1];
1088 WCHAR feature
[MAX_FEATURE_CHARS
+1];
1089 WCHAR component
[MAX_FEATURE_CHARS
+1];
1090 LPWSTR str
= NULL
, p
= NULL
, f
= NULL
, c
= NULL
;
1093 TRACE("%s %p %p %p %p\n", debugstr_a(szDescriptor
), szProduct
,
1094 szFeature
, szComponent
, pUsed
);
1096 str
= strdupAtoW( szDescriptor
);
1097 if( szDescriptor
&& !str
)
1098 return ERROR_OUTOFMEMORY
;
1107 r
= MsiDecomposeDescriptorW( str
, p
, f
, c
, pUsed
);
1109 if (r
== ERROR_SUCCESS
)
1111 WideCharToMultiByte( CP_ACP
, 0, p
, -1,
1112 szProduct
, MAX_FEATURE_CHARS
+1, NULL
, NULL
);
1113 WideCharToMultiByte( CP_ACP
, 0, f
, -1,
1114 szFeature
, MAX_FEATURE_CHARS
+1, NULL
, NULL
);
1115 WideCharToMultiByte( CP_ACP
, 0, c
, -1,
1116 szComponent
, MAX_FEATURE_CHARS
+1, NULL
, NULL
);
1124 UINT WINAPI
MsiEnumProductsA(DWORD index
, LPSTR lpguid
)
1127 WCHAR szwGuid
[GUID_SIZE
];
1129 TRACE("%d %p\n", index
, lpguid
);
1132 return ERROR_INVALID_PARAMETER
;
1133 r
= MsiEnumProductsW(index
, szwGuid
);
1134 if( r
== ERROR_SUCCESS
)
1135 WideCharToMultiByte(CP_ACP
, 0, szwGuid
, -1, lpguid
, GUID_SIZE
, NULL
, NULL
);
1140 UINT WINAPI
MsiEnumProductsW(DWORD index
, LPWSTR lpguid
)
1142 TRACE("%d %p\n", index
, lpguid
);
1145 return ERROR_INVALID_PARAMETER
;
1147 return MsiEnumProductsExW( NULL
, szAllSid
, MSIINSTALLCONTEXT_ALL
, index
, lpguid
,
1151 UINT WINAPI
MsiEnumFeaturesA(LPCSTR szProduct
, DWORD index
,
1152 LPSTR szFeature
, LPSTR szParent
)
1155 WCHAR szwFeature
[GUID_SIZE
], szwParent
[GUID_SIZE
];
1156 LPWSTR szwProduct
= NULL
;
1158 TRACE("%s %d %p %p\n", debugstr_a(szProduct
), index
, szFeature
, szParent
);
1162 szwProduct
= strdupAtoW( szProduct
);
1164 return ERROR_OUTOFMEMORY
;
1167 r
= MsiEnumFeaturesW(szwProduct
, index
, szwFeature
, szwParent
);
1168 if( r
== ERROR_SUCCESS
)
1170 WideCharToMultiByte(CP_ACP
, 0, szwFeature
, -1,
1171 szFeature
, GUID_SIZE
, NULL
, NULL
);
1172 WideCharToMultiByte(CP_ACP
, 0, szwParent
, -1,
1173 szParent
, GUID_SIZE
, NULL
, NULL
);
1176 msi_free( szwProduct
);
1181 UINT WINAPI
MsiEnumFeaturesW(LPCWSTR szProduct
, DWORD index
,
1182 LPWSTR szFeature
, LPWSTR szParent
)
1184 HKEY hkeyProduct
= 0;
1187 TRACE("%s %d %p %p\n", debugstr_w(szProduct
), index
, szFeature
, szParent
);
1190 return ERROR_INVALID_PARAMETER
;
1192 r
= MSIREG_OpenInstallerFeaturesKey(szProduct
,&hkeyProduct
,FALSE
);
1193 if( r
!= ERROR_SUCCESS
)
1194 return ERROR_NO_MORE_ITEMS
;
1197 r
= RegEnumValueW(hkeyProduct
, index
, szFeature
, &sz
, NULL
, NULL
, NULL
, NULL
);
1198 RegCloseKey(hkeyProduct
);
1203 UINT WINAPI
MsiEnumComponentsA(DWORD index
, LPSTR lpguid
)
1206 WCHAR szwGuid
[GUID_SIZE
];
1208 TRACE("%u, %p\n", index
, lpguid
);
1210 if (!lpguid
) return ERROR_INVALID_PARAMETER
;
1212 r
= MsiEnumComponentsW(index
, szwGuid
);
1213 if( r
== ERROR_SUCCESS
)
1214 WideCharToMultiByte(CP_ACP
, 0, szwGuid
, -1, lpguid
, GUID_SIZE
, NULL
, NULL
);
1219 UINT WINAPI
MsiEnumComponentsW(DWORD index
, LPWSTR lpguid
)
1221 TRACE("%u, %p\n", index
, lpguid
);
1223 if (!lpguid
) return ERROR_INVALID_PARAMETER
;
1225 return MsiEnumComponentsExW( szAllSid
, MSIINSTALLCONTEXT_ALL
, index
, lpguid
, NULL
, NULL
, NULL
);
1228 UINT WINAPI
MsiEnumComponentsExA( LPCSTR user_sid
, DWORD ctx
, DWORD index
, CHAR guid
[39],
1229 MSIINSTALLCONTEXT
*installed_ctx
, LPSTR sid
, LPDWORD sid_len
)
1232 WCHAR
*user_sidW
= NULL
, *sidW
= NULL
, guidW
[GUID_SIZE
];
1234 TRACE("%s, %u, %u, %p, %p, %p, %p\n", debugstr_a(user_sid
), ctx
, index
, guid
, installed_ctx
,
1237 if (sid
&& !sid_len
) return ERROR_INVALID_PARAMETER
;
1238 if (user_sid
&& !(user_sidW
= strdupAtoW( user_sid
))) return ERROR_OUTOFMEMORY
;
1239 if (sid
&& !(sidW
= msi_alloc( *sid_len
* sizeof(WCHAR
) )))
1241 msi_free( user_sidW
);
1242 return ERROR_OUTOFMEMORY
;
1244 r
= MsiEnumComponentsExW( user_sidW
, ctx
, index
, guidW
, installed_ctx
, sidW
, sid_len
);
1245 if (r
== ERROR_SUCCESS
)
1247 if (guid
) WideCharToMultiByte( CP_ACP
, 0, guidW
, GUID_SIZE
, guid
, GUID_SIZE
, NULL
, NULL
);
1248 if (sid
) WideCharToMultiByte( CP_ACP
, 0, sidW
, *sid_len
+ 1, sid
, *sid_len
+ 1, NULL
, NULL
);
1250 msi_free( user_sidW
);
1255 static UINT
fetch_machine_component( DWORD ctx
, DWORD index
, DWORD
*idx
, WCHAR guid
[39],
1256 MSIINSTALLCONTEXT
*installed_ctx
, LPWSTR sid
, LPDWORD sid_len
)
1258 static const WCHAR componentsW
[] =
1259 {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
1260 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1261 'I','n','s','t','a','l','l','e','r','\\','U','s','e','r','D','a','t','a','\\',
1262 'S','-','1','-','5','-','1','8','\\','C','o','m','p','o','n','e','n','t','s',0};
1263 UINT r
= ERROR_SUCCESS
;
1264 WCHAR component
[GUID_SIZE
];
1265 DWORD i
= 0, len_component
;
1266 REGSAM access
= KEY_ENUMERATE_SUB_KEYS
| KEY_WOW64_64KEY
;
1267 HKEY key_components
;
1269 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, componentsW
, 0, access
, &key_components
))
1270 return ERROR_NO_MORE_ITEMS
;
1272 len_component
= sizeof(component
)/sizeof(component
[0]);
1273 while (!RegEnumKeyExW( key_components
, i
, component
, &len_component
, NULL
, NULL
, NULL
, NULL
))
1275 if (*idx
== index
) goto found
;
1277 len_component
= sizeof(component
)/sizeof(component
[0]);
1280 RegCloseKey( key_components
);
1281 return ERROR_NO_MORE_ITEMS
;
1289 r
= ERROR_MORE_DATA
;
1297 if (guid
) unsquash_guid( component
, guid
);
1298 if (installed_ctx
) *installed_ctx
= MSIINSTALLCONTEXT_MACHINE
;
1299 RegCloseKey( key_components
);
1303 static UINT
fetch_user_component( const WCHAR
*usersid
, DWORD ctx
, DWORD index
, DWORD
*idx
,
1304 WCHAR guid
[39], MSIINSTALLCONTEXT
*installed_ctx
, LPWSTR sid
,
1307 static const WCHAR userdataW
[] =
1308 {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
1309 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1310 'I','n','s','t','a','l','l','e','r','\\','U','s','e','r','D','a','t','a',0};
1311 static const WCHAR componentsW
[] = {'\\','C','o','m','p','o','n','e','n','t','s',0};
1312 UINT r
= ERROR_SUCCESS
;
1313 WCHAR path
[MAX_PATH
], component
[GUID_SIZE
], user
[128];
1314 DWORD i
= 0, j
= 0, len_component
, len_user
;
1315 REGSAM access
= KEY_ENUMERATE_SUB_KEYS
| KEY_WOW64_64KEY
;
1316 HKEY key_users
, key_components
;
1318 if (ctx
== MSIINSTALLCONTEXT_USERMANAGED
) /* FIXME: were to find these? */
1319 return ERROR_NO_MORE_ITEMS
;
1321 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, userdataW
, 0, access
, &key_users
))
1322 return ERROR_NO_MORE_ITEMS
;
1324 len_user
= sizeof(user
)/sizeof(user
[0]);
1325 while (!RegEnumKeyExW( key_users
, i
, user
, &len_user
, NULL
, NULL
, NULL
, NULL
))
1327 if ((strcmpW( usersid
, szAllSid
) && strcmpW( usersid
, user
)) ||
1328 !strcmpW( szLocalSid
, user
))
1331 len_user
= sizeof(user
)/sizeof(user
[0]);
1334 strcpyW( path
, user
);
1335 strcatW( path
, componentsW
);
1336 if (RegOpenKeyExW( key_users
, path
, 0, access
, &key_components
))
1339 len_user
= sizeof(user
)/sizeof(user
[0]);
1342 len_component
= sizeof(component
)/sizeof(component
[0]);
1343 while (!RegEnumKeyExW( key_components
, j
, component
, &len_component
, NULL
, NULL
, NULL
, NULL
))
1345 if (*idx
== index
) goto found
;
1347 len_component
= sizeof(component
)/sizeof(component
[0]);
1350 RegCloseKey( key_components
);
1351 len_user
= sizeof(user
)/sizeof(user
[0]);
1354 RegCloseKey( key_users
);
1355 return ERROR_NO_MORE_ITEMS
;
1360 if (*sid_len
< len_user
+ 1)
1362 *sid_len
= len_user
+ 1;
1363 r
= ERROR_MORE_DATA
;
1367 *sid_len
= len_user
;
1368 strcpyW( sid
, user
);
1371 if (guid
) unsquash_guid( component
, guid
);
1372 if (installed_ctx
) *installed_ctx
= ctx
;
1373 RegCloseKey( key_components
);
1374 RegCloseKey( key_users
);
1378 static UINT
enum_components( const WCHAR
*usersid
, DWORD ctx
, DWORD index
, DWORD
*idx
, WCHAR guid
[39],
1379 MSIINSTALLCONTEXT
*installed_ctx
, LPWSTR sid
, LPDWORD sid_len
)
1381 UINT r
= ERROR_NO_MORE_ITEMS
;
1386 usersid
= user
= get_user_sid();
1387 if (!user
) return ERROR_FUNCTION_FAILED
;
1389 if (ctx
& MSIINSTALLCONTEXT_USERMANAGED
)
1391 r
= fetch_user_component( usersid
, MSIINSTALLCONTEXT_USERMANAGED
, index
, idx
, guid
,
1392 installed_ctx
, sid
, sid_len
);
1393 if (r
!= ERROR_NO_MORE_ITEMS
) goto done
;
1395 if (ctx
& MSIINSTALLCONTEXT_USERUNMANAGED
)
1397 r
= fetch_user_component( usersid
, MSIINSTALLCONTEXT_USERUNMANAGED
, index
, idx
, guid
,
1398 installed_ctx
, sid
, sid_len
);
1399 if (r
!= ERROR_NO_MORE_ITEMS
) goto done
;
1401 if (ctx
& MSIINSTALLCONTEXT_MACHINE
)
1403 r
= fetch_machine_component( MSIINSTALLCONTEXT_MACHINE
, index
, idx
, guid
, installed_ctx
,
1405 if (r
!= ERROR_NO_MORE_ITEMS
) goto done
;
1413 UINT WINAPI
MsiEnumComponentsExW( LPCWSTR user_sid
, DWORD ctx
, DWORD index
, WCHAR guid
[39],
1414 MSIINSTALLCONTEXT
*installed_ctx
, LPWSTR sid
, LPDWORD sid_len
)
1418 static DWORD last_index
;
1420 TRACE("%s, %u, %u, %p, %p, %p, %p\n", debugstr_w(user_sid
), ctx
, index
, guid
, installed_ctx
,
1423 if ((sid
&& !sid_len
) || !ctx
|| (user_sid
&& ctx
== MSIINSTALLCONTEXT_MACHINE
))
1424 return ERROR_INVALID_PARAMETER
;
1426 if (index
&& index
- last_index
!= 1)
1427 return ERROR_INVALID_PARAMETER
;
1429 if (!index
) last_index
= 0;
1431 r
= enum_components( user_sid
, ctx
, index
, &idx
, guid
, installed_ctx
, sid
, sid_len
);
1432 if (r
== ERROR_SUCCESS
)
1440 UINT WINAPI
MsiEnumClientsA(LPCSTR szComponent
, DWORD index
, LPSTR szProduct
)
1443 WCHAR szwProduct
[GUID_SIZE
];
1444 LPWSTR szwComponent
= NULL
;
1446 TRACE("%s %d %p\n", debugstr_a(szComponent
), index
, szProduct
);
1449 return ERROR_INVALID_PARAMETER
;
1453 szwComponent
= strdupAtoW( szComponent
);
1455 return ERROR_OUTOFMEMORY
;
1458 r
= MsiEnumClientsW(szComponent
?szwComponent
:NULL
, index
, szwProduct
);
1459 if( r
== ERROR_SUCCESS
)
1461 WideCharToMultiByte(CP_ACP
, 0, szwProduct
, -1,
1462 szProduct
, GUID_SIZE
, NULL
, NULL
);
1465 msi_free( szwComponent
);
1470 UINT WINAPI
MsiEnumClientsW(LPCWSTR szComponent
, DWORD index
, LPWSTR szProduct
)
1474 WCHAR szValName
[SQUISH_GUID_SIZE
];
1476 TRACE("%s %d %p\n", debugstr_w(szComponent
), index
, szProduct
);
1478 if (!szComponent
|| !*szComponent
|| !szProduct
)
1479 return ERROR_INVALID_PARAMETER
;
1481 if (MSIREG_OpenUserDataComponentKey(szComponent
, NULL
, &hkeyComp
, FALSE
) != ERROR_SUCCESS
&&
1482 MSIREG_OpenUserDataComponentKey(szComponent
, szLocalSid
, &hkeyComp
, FALSE
) != ERROR_SUCCESS
)
1483 return ERROR_UNKNOWN_COMPONENT
;
1485 /* see if there are any products at all */
1486 sz
= SQUISH_GUID_SIZE
;
1487 r
= RegEnumValueW(hkeyComp
, 0, szValName
, &sz
, NULL
, NULL
, NULL
, NULL
);
1488 if (r
!= ERROR_SUCCESS
)
1490 RegCloseKey(hkeyComp
);
1493 return ERROR_INVALID_PARAMETER
;
1495 return ERROR_UNKNOWN_COMPONENT
;
1498 sz
= SQUISH_GUID_SIZE
;
1499 r
= RegEnumValueW(hkeyComp
, index
, szValName
, &sz
, NULL
, NULL
, NULL
, NULL
);
1500 if( r
== ERROR_SUCCESS
)
1502 unsquash_guid(szValName
, szProduct
);
1503 TRACE("-> %s\n", debugstr_w(szProduct
));
1505 RegCloseKey(hkeyComp
);
1509 static UINT
MSI_EnumComponentQualifiers( LPCWSTR szComponent
, DWORD iIndex
,
1510 awstring
*lpQualBuf
, LPDWORD pcchQual
,
1511 awstring
*lpAppBuf
, LPDWORD pcchAppBuf
)
1513 DWORD name_sz
, val_sz
, name_max
, val_max
, type
, ofs
;
1514 LPWSTR name
= NULL
, val
= NULL
;
1518 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent
), iIndex
,
1519 lpQualBuf
, pcchQual
, lpAppBuf
, pcchAppBuf
);
1522 return ERROR_INVALID_PARAMETER
;
1524 r
= MSIREG_OpenUserComponentsKey( szComponent
, &key
, FALSE
);
1525 if (r
!= ERROR_SUCCESS
)
1526 return ERROR_UNKNOWN_COMPONENT
;
1528 /* figure out how big the name is we want to return */
1530 r
= ERROR_OUTOFMEMORY
;
1531 name
= msi_alloc( name_max
* sizeof(WCHAR
) );
1536 r
= ERROR_OUTOFMEMORY
;
1537 val
= msi_alloc( val_max
);
1541 /* loop until we allocate enough memory */
1546 r
= RegEnumValueW( key
, iIndex
, name
, &name_sz
,
1547 NULL
, &type
, (LPBYTE
)val
, &val_sz
);
1548 if (r
== ERROR_SUCCESS
)
1550 if (r
!= ERROR_MORE_DATA
)
1553 if (type
!= REG_MULTI_SZ
)
1555 ERR("component data has wrong type (%d)\n", type
);
1559 r
= ERROR_OUTOFMEMORY
;
1560 if (name_sz
+ 1 >= name_max
)
1564 name
= msi_alloc( name_max
* sizeof (WCHAR
) );
1569 if (val_sz
> val_max
)
1571 val_max
= val_sz
+ sizeof (WCHAR
);
1573 val
= msi_alloc( val_max
* sizeof (WCHAR
) );
1578 ERR("should be enough data, but isn't %d %d\n", name_sz
, val_sz
);
1583 r
= MsiDecomposeDescriptorW( val
, NULL
, NULL
, NULL
, &ofs
);
1584 if (r
!= ERROR_SUCCESS
)
1587 TRACE("Providing %s and %s\n", debugstr_w(name
), debugstr_w(val
+ofs
));
1589 r
= msi_strcpy_to_awstring( name
, -1, lpQualBuf
, pcchQual
);
1590 r2
= msi_strcpy_to_awstring( val
+ofs
, -1, lpAppBuf
, pcchAppBuf
);
1592 if (r2
!= ERROR_SUCCESS
)
1602 /*************************************************************************
1603 * MsiEnumComponentQualifiersA [MSI.@]
1605 UINT WINAPI
MsiEnumComponentQualifiersA( LPCSTR szComponent
, DWORD iIndex
,
1606 LPSTR lpQualifierBuf
, LPDWORD pcchQualifierBuf
,
1607 LPSTR lpApplicationDataBuf
, LPDWORD pcchApplicationDataBuf
)
1609 awstring qual
, appdata
;
1613 TRACE("%s %08x %p %p %p %p\n", debugstr_a(szComponent
), iIndex
,
1614 lpQualifierBuf
, pcchQualifierBuf
, lpApplicationDataBuf
,
1615 pcchApplicationDataBuf
);
1617 comp
= strdupAtoW( szComponent
);
1618 if (szComponent
&& !comp
)
1619 return ERROR_OUTOFMEMORY
;
1621 qual
.unicode
= FALSE
;
1622 qual
.str
.a
= lpQualifierBuf
;
1624 appdata
.unicode
= FALSE
;
1625 appdata
.str
.a
= lpApplicationDataBuf
;
1627 r
= MSI_EnumComponentQualifiers( comp
, iIndex
,
1628 &qual
, pcchQualifierBuf
, &appdata
, pcchApplicationDataBuf
);
1633 /*************************************************************************
1634 * MsiEnumComponentQualifiersW [MSI.@]
1636 UINT WINAPI
MsiEnumComponentQualifiersW( LPCWSTR szComponent
, DWORD iIndex
,
1637 LPWSTR lpQualifierBuf
, LPDWORD pcchQualifierBuf
,
1638 LPWSTR lpApplicationDataBuf
, LPDWORD pcchApplicationDataBuf
)
1640 awstring qual
, appdata
;
1642 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent
), iIndex
,
1643 lpQualifierBuf
, pcchQualifierBuf
, lpApplicationDataBuf
,
1644 pcchApplicationDataBuf
);
1646 qual
.unicode
= TRUE
;
1647 qual
.str
.w
= lpQualifierBuf
;
1649 appdata
.unicode
= TRUE
;
1650 appdata
.str
.w
= lpApplicationDataBuf
;
1652 return MSI_EnumComponentQualifiers( szComponent
, iIndex
,
1653 &qual
, pcchQualifierBuf
, &appdata
, pcchApplicationDataBuf
);
1656 /*************************************************************************
1657 * MsiEnumRelatedProductsW [MSI.@]
1660 UINT WINAPI
MsiEnumRelatedProductsW(LPCWSTR szUpgradeCode
, DWORD dwReserved
,
1661 DWORD iProductIndex
, LPWSTR lpProductBuf
)
1665 DWORD dwSize
= SQUISH_GUID_SIZE
;
1666 WCHAR szKeyName
[SQUISH_GUID_SIZE
];
1668 TRACE("%s %u %u %p\n", debugstr_w(szUpgradeCode
), dwReserved
,
1669 iProductIndex
, lpProductBuf
);
1671 if (NULL
== szUpgradeCode
)
1672 return ERROR_INVALID_PARAMETER
;
1673 if (NULL
== lpProductBuf
)
1674 return ERROR_INVALID_PARAMETER
;
1676 r
= MSIREG_OpenUpgradeCodesKey(szUpgradeCode
, &hkey
, FALSE
);
1677 if (r
!= ERROR_SUCCESS
)
1678 return ERROR_NO_MORE_ITEMS
;
1680 r
= RegEnumValueW(hkey
, iProductIndex
, szKeyName
, &dwSize
, NULL
, NULL
, NULL
, NULL
);
1681 if( r
== ERROR_SUCCESS
)
1682 unsquash_guid(szKeyName
, lpProductBuf
);
1688 /*************************************************************************
1689 * MsiEnumRelatedProductsA [MSI.@]
1692 UINT WINAPI
MsiEnumRelatedProductsA(LPCSTR szUpgradeCode
, DWORD dwReserved
,
1693 DWORD iProductIndex
, LPSTR lpProductBuf
)
1695 LPWSTR szwUpgradeCode
= NULL
;
1696 WCHAR productW
[GUID_SIZE
];
1699 TRACE("%s %u %u %p\n", debugstr_a(szUpgradeCode
), dwReserved
,
1700 iProductIndex
, lpProductBuf
);
1704 szwUpgradeCode
= strdupAtoW( szUpgradeCode
);
1705 if( !szwUpgradeCode
)
1706 return ERROR_OUTOFMEMORY
;
1709 r
= MsiEnumRelatedProductsW( szwUpgradeCode
, dwReserved
,
1710 iProductIndex
, productW
);
1711 if (r
== ERROR_SUCCESS
)
1713 WideCharToMultiByte( CP_ACP
, 0, productW
, GUID_SIZE
,
1714 lpProductBuf
, GUID_SIZE
, NULL
, NULL
);
1716 msi_free( szwUpgradeCode
);
1720 /***********************************************************************
1721 * MsiEnumPatchesExA [MSI.@]
1723 UINT WINAPI
MsiEnumPatchesExA(LPCSTR szProductCode
, LPCSTR szUserSid
,
1724 DWORD dwContext
, DWORD dwFilter
, DWORD dwIndex
, LPSTR szPatchCode
,
1725 LPSTR szTargetProductCode
, MSIINSTALLCONTEXT
*pdwTargetProductContext
,
1726 LPSTR szTargetUserSid
, LPDWORD pcchTargetUserSid
)
1728 LPWSTR prodcode
= NULL
;
1729 LPWSTR usersid
= NULL
;
1730 LPWSTR targsid
= NULL
;
1731 WCHAR patch
[GUID_SIZE
];
1732 WCHAR targprod
[GUID_SIZE
];
1736 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p, %p)\n",
1737 debugstr_a(szProductCode
), debugstr_a(szUserSid
), dwContext
, dwFilter
,
1738 dwIndex
, szPatchCode
, szTargetProductCode
, pdwTargetProductContext
,
1739 szTargetUserSid
, pcchTargetUserSid
);
1741 if (szTargetUserSid
&& !pcchTargetUserSid
)
1742 return ERROR_INVALID_PARAMETER
;
1744 if (szProductCode
) prodcode
= strdupAtoW(szProductCode
);
1745 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1747 r
= MsiEnumPatchesExW(prodcode
, usersid
, dwContext
, dwFilter
, dwIndex
,
1748 patch
, targprod
, pdwTargetProductContext
,
1750 if (r
!= ERROR_SUCCESS
)
1753 WideCharToMultiByte(CP_ACP
, 0, patch
, -1, szPatchCode
,
1754 GUID_SIZE
, NULL
, NULL
);
1755 WideCharToMultiByte(CP_ACP
, 0, targprod
, -1, szTargetProductCode
,
1756 GUID_SIZE
, NULL
, NULL
);
1758 if (!szTargetUserSid
)
1760 if (pcchTargetUserSid
)
1761 *pcchTargetUserSid
= len
;
1766 targsid
= msi_alloc(++len
* sizeof(WCHAR
));
1769 r
= ERROR_OUTOFMEMORY
;
1773 r
= MsiEnumPatchesExW(prodcode
, usersid
, dwContext
, dwFilter
, dwIndex
,
1774 patch
, targprod
, pdwTargetProductContext
,
1776 if (r
!= ERROR_SUCCESS
|| !szTargetUserSid
)
1779 WideCharToMultiByte(CP_ACP
, 0, targsid
, -1, szTargetUserSid
,
1780 *pcchTargetUserSid
, NULL
, NULL
);
1782 len
= lstrlenW(targsid
);
1783 if (*pcchTargetUserSid
< len
+ 1)
1785 r
= ERROR_MORE_DATA
;
1786 *pcchTargetUserSid
= len
* sizeof(WCHAR
);
1789 *pcchTargetUserSid
= len
;
1799 static UINT
msi_get_patch_state(LPCWSTR prodcode
, LPCWSTR usersid
,
1800 MSIINSTALLCONTEXT context
,
1801 LPWSTR patch
, MSIPATCHSTATE
*state
)
1803 DWORD type
, val
, size
;
1804 HKEY prod
, hkey
= 0;
1807 UINT r
= ERROR_NO_MORE_ITEMS
;
1809 *state
= MSIPATCHSTATE_INVALID
;
1811 r
= MSIREG_OpenUserDataProductKey(prodcode
, context
,
1812 usersid
, &prod
, FALSE
);
1813 if (r
!= ERROR_SUCCESS
)
1814 return ERROR_NO_MORE_ITEMS
;
1816 res
= RegOpenKeyExW(prod
, szPatches
, 0, KEY_READ
, &hkey
);
1817 if (res
!= ERROR_SUCCESS
)
1820 res
= RegOpenKeyExW(hkey
, patch
, 0, KEY_READ
, &udpatch
);
1821 if (res
!= ERROR_SUCCESS
)
1824 size
= sizeof(DWORD
);
1825 res
= RegGetValueW(udpatch
, NULL
, szState
, RRF_RT_DWORD
, &type
, &val
, &size
);
1826 if (res
!= ERROR_SUCCESS
||
1827 val
< MSIPATCHSTATE_APPLIED
|| val
> MSIPATCHSTATE_REGISTERED
)
1829 r
= ERROR_BAD_CONFIGURATION
;
1837 RegCloseKey(udpatch
);
1844 static UINT
msi_check_product_patches(LPCWSTR prodcode
, LPCWSTR usersid
,
1845 MSIINSTALLCONTEXT context
, DWORD filter
, DWORD index
, DWORD
*idx
,
1846 LPWSTR patch
, LPWSTR targetprod
, MSIINSTALLCONTEXT
*targetctx
,
1847 LPWSTR targetsid
, DWORD
*sidsize
, LPWSTR
*transforms
)
1849 MSIPATCHSTATE state
= MSIPATCHSTATE_INVALID
;
1850 LPWSTR ptr
, patches
= NULL
;
1851 HKEY prod
, patchkey
= 0;
1852 HKEY localprod
= 0, localpatch
= 0;
1855 UINT temp
, r
= ERROR_NO_MORE_ITEMS
;
1857 if (MSIREG_OpenProductKey(prodcode
, usersid
, context
,
1858 &prod
, FALSE
) != ERROR_SUCCESS
)
1859 return ERROR_NO_MORE_ITEMS
;
1862 res
= RegGetValueW(prod
, szPatches
, szPatches
, RRF_RT_ANY
, &type
, NULL
,
1864 if (res
!= ERROR_SUCCESS
)
1867 if (type
!= REG_MULTI_SZ
)
1869 r
= ERROR_BAD_CONFIGURATION
;
1873 patches
= msi_alloc(size
);
1876 r
= ERROR_OUTOFMEMORY
;
1880 res
= RegGetValueW(prod
, szPatches
, szPatches
, RRF_RT_ANY
, &type
,
1882 if (res
!= ERROR_SUCCESS
)
1885 for (ptr
= patches
; *ptr
&& r
== ERROR_NO_MORE_ITEMS
; ptr
+= lstrlenW(ptr
) + 1)
1887 if (!unsquash_guid(ptr
, patch
))
1889 r
= ERROR_BAD_CONFIGURATION
;
1894 res
= RegGetValueW(prod
, szPatches
, ptr
, RRF_RT_REG_SZ
,
1895 &type
, NULL
, &size
);
1896 if (res
!= ERROR_SUCCESS
)
1901 *transforms
= msi_alloc(size
);
1904 r
= ERROR_OUTOFMEMORY
;
1908 res
= RegGetValueW(prod
, szPatches
, ptr
, RRF_RT_REG_SZ
,
1909 &type
, *transforms
, &size
);
1910 if (res
!= ERROR_SUCCESS
)
1914 if (context
== MSIINSTALLCONTEXT_USERMANAGED
)
1916 if (!(filter
& MSIPATCHSTATE_APPLIED
))
1918 temp
= msi_get_patch_state(prodcode
, usersid
, context
,
1920 if (temp
== ERROR_BAD_CONFIGURATION
)
1922 r
= ERROR_BAD_CONFIGURATION
;
1926 if (temp
!= ERROR_SUCCESS
|| !(filter
& state
))
1930 else if (context
== MSIINSTALLCONTEXT_USERUNMANAGED
)
1932 if (!(filter
& MSIPATCHSTATE_APPLIED
))
1934 temp
= msi_get_patch_state(prodcode
, usersid
, context
,
1936 if (temp
== ERROR_BAD_CONFIGURATION
)
1938 r
= ERROR_BAD_CONFIGURATION
;
1942 if (temp
!= ERROR_SUCCESS
|| !(filter
& state
))
1947 temp
= MSIREG_OpenUserDataPatchKey(patch
, context
,
1949 RegCloseKey(patchkey
);
1950 if (temp
!= ERROR_SUCCESS
)
1954 else if (context
== MSIINSTALLCONTEXT_MACHINE
)
1958 if (MSIREG_OpenUserDataProductKey(prodcode
, context
, NULL
, &localprod
, FALSE
) == ERROR_SUCCESS
&&
1959 RegOpenKeyExW(localprod
, szPatches
, 0, KEY_READ
, &localpatch
) == ERROR_SUCCESS
&&
1960 RegOpenKeyExW(localpatch
, ptr
, 0, KEY_READ
, &patchkey
) == ERROR_SUCCESS
)
1962 res
= RegGetValueW(patchkey
, NULL
, szState
, RRF_RT_REG_DWORD
,
1963 &type
, &state
, &size
);
1965 if (!(filter
& state
))
1966 res
= ERROR_NO_MORE_ITEMS
;
1968 RegCloseKey(patchkey
);
1971 RegCloseKey(localpatch
);
1972 RegCloseKey(localprod
);
1974 if (res
!= ERROR_SUCCESS
)
1986 lstrcpyW(targetprod
, prodcode
);
1989 *targetctx
= context
;
1993 lstrcpynW(targetsid
, usersid
, *sidsize
);
1994 if (lstrlenW(usersid
) >= *sidsize
)
1995 r
= ERROR_MORE_DATA
;
2000 *sidsize
= lstrlenW(usersid
);
2002 *sidsize
*= sizeof(WCHAR
);
2013 static UINT
msi_enum_patches(LPCWSTR szProductCode
, LPCWSTR szUserSid
,
2014 DWORD dwContext
, DWORD dwFilter
, DWORD dwIndex
, DWORD
*idx
,
2015 LPWSTR szPatchCode
, LPWSTR szTargetProductCode
,
2016 MSIINSTALLCONTEXT
*pdwTargetProductContext
, LPWSTR szTargetUserSid
,
2017 LPDWORD pcchTargetUserSid
, LPWSTR
*szTransforms
)
2019 LPWSTR usersid
= NULL
;
2020 UINT r
= ERROR_INVALID_PARAMETER
;
2024 szUserSid
= usersid
= get_user_sid();
2025 if (!usersid
) return ERROR_FUNCTION_FAILED
;
2028 if (dwContext
& MSIINSTALLCONTEXT_USERMANAGED
)
2030 r
= msi_check_product_patches(szProductCode
, szUserSid
,
2031 MSIINSTALLCONTEXT_USERMANAGED
, dwFilter
,
2032 dwIndex
, idx
, szPatchCode
,
2033 szTargetProductCode
,
2034 pdwTargetProductContext
, szTargetUserSid
,
2035 pcchTargetUserSid
, szTransforms
);
2036 if (r
!= ERROR_NO_MORE_ITEMS
)
2040 if (dwContext
& MSIINSTALLCONTEXT_USERUNMANAGED
)
2042 r
= msi_check_product_patches(szProductCode
, szUserSid
,
2043 MSIINSTALLCONTEXT_USERUNMANAGED
, dwFilter
,
2044 dwIndex
, idx
, szPatchCode
,
2045 szTargetProductCode
,
2046 pdwTargetProductContext
, szTargetUserSid
,
2047 pcchTargetUserSid
, szTransforms
);
2048 if (r
!= ERROR_NO_MORE_ITEMS
)
2052 if (dwContext
& MSIINSTALLCONTEXT_MACHINE
)
2054 r
= msi_check_product_patches(szProductCode
, szUserSid
,
2055 MSIINSTALLCONTEXT_MACHINE
, dwFilter
,
2056 dwIndex
, idx
, szPatchCode
,
2057 szTargetProductCode
,
2058 pdwTargetProductContext
, szTargetUserSid
,
2059 pcchTargetUserSid
, szTransforms
);
2060 if (r
!= ERROR_NO_MORE_ITEMS
)
2069 /***********************************************************************
2070 * MsiEnumPatchesExW [MSI.@]
2072 UINT WINAPI
MsiEnumPatchesExW(LPCWSTR szProductCode
, LPCWSTR szUserSid
,
2073 DWORD dwContext
, DWORD dwFilter
, DWORD dwIndex
, LPWSTR szPatchCode
,
2074 LPWSTR szTargetProductCode
, MSIINSTALLCONTEXT
*pdwTargetProductContext
,
2075 LPWSTR szTargetUserSid
, LPDWORD pcchTargetUserSid
)
2077 WCHAR squished_pc
[GUID_SIZE
];
2081 static DWORD last_index
;
2083 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p, %p)\n",
2084 debugstr_w(szProductCode
), debugstr_w(szUserSid
), dwContext
, dwFilter
,
2085 dwIndex
, szPatchCode
, szTargetProductCode
, pdwTargetProductContext
,
2086 szTargetUserSid
, pcchTargetUserSid
);
2088 if (!szProductCode
|| !squash_guid(szProductCode
, squished_pc
))
2089 return ERROR_INVALID_PARAMETER
;
2091 if (szUserSid
&& !strcmpW( szUserSid
, szLocalSid
))
2092 return ERROR_INVALID_PARAMETER
;
2094 if (dwContext
& MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
2095 return ERROR_INVALID_PARAMETER
;
2097 if (dwContext
<= MSIINSTALLCONTEXT_NONE
||
2098 dwContext
> MSIINSTALLCONTEXT_ALL
)
2099 return ERROR_INVALID_PARAMETER
;
2101 if (dwFilter
<= MSIPATCHSTATE_INVALID
|| dwFilter
> MSIPATCHSTATE_ALL
)
2102 return ERROR_INVALID_PARAMETER
;
2104 if (dwIndex
&& dwIndex
- last_index
!= 1)
2105 return ERROR_INVALID_PARAMETER
;
2110 r
= msi_enum_patches(szProductCode
, szUserSid
, dwContext
, dwFilter
,
2111 dwIndex
, &idx
, szPatchCode
, szTargetProductCode
,
2112 pdwTargetProductContext
, szTargetUserSid
,
2113 pcchTargetUserSid
, NULL
);
2115 if (r
== ERROR_SUCCESS
)
2116 last_index
= dwIndex
;
2123 /***********************************************************************
2124 * MsiEnumPatchesA [MSI.@]
2126 UINT WINAPI
MsiEnumPatchesA(LPCSTR szProduct
, DWORD iPatchIndex
,
2127 LPSTR lpPatchBuf
, LPSTR lpTransformsBuf
, LPDWORD pcchTransformsBuf
)
2129 LPWSTR product
, transforms
;
2130 WCHAR patch
[GUID_SIZE
];
2134 TRACE("(%s %d %p %p %p)\n", debugstr_a(szProduct
), iPatchIndex
,
2135 lpPatchBuf
, lpTransformsBuf
, pcchTransformsBuf
);
2137 if (!szProduct
|| !lpPatchBuf
|| !lpTransformsBuf
|| !pcchTransformsBuf
)
2138 return ERROR_INVALID_PARAMETER
;
2140 product
= strdupAtoW(szProduct
);
2142 return ERROR_OUTOFMEMORY
;
2144 len
= *pcchTransformsBuf
;
2145 transforms
= msi_alloc( len
* sizeof(WCHAR
) );
2148 r
= ERROR_OUTOFMEMORY
;
2152 r
= MsiEnumPatchesW(product
, iPatchIndex
, patch
, transforms
, &len
);
2153 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
2156 WideCharToMultiByte(CP_ACP
, 0, patch
, -1, lpPatchBuf
,
2157 GUID_SIZE
, NULL
, NULL
);
2159 if (!WideCharToMultiByte(CP_ACP
, 0, transforms
, -1, lpTransformsBuf
,
2160 *pcchTransformsBuf
, NULL
, NULL
))
2161 r
= ERROR_MORE_DATA
;
2163 if (r
== ERROR_MORE_DATA
)
2165 lpTransformsBuf
[*pcchTransformsBuf
- 1] = '\0';
2166 *pcchTransformsBuf
= len
* 2;
2169 *pcchTransformsBuf
= strlen( lpTransformsBuf
);
2172 msi_free(transforms
);
2178 /***********************************************************************
2179 * MsiEnumPatchesW [MSI.@]
2181 UINT WINAPI
MsiEnumPatchesW(LPCWSTR szProduct
, DWORD iPatchIndex
,
2182 LPWSTR lpPatchBuf
, LPWSTR lpTransformsBuf
, LPDWORD pcchTransformsBuf
)
2184 WCHAR squished_pc
[GUID_SIZE
];
2185 LPWSTR transforms
= NULL
;
2190 TRACE("(%s %d %p %p %p)\n", debugstr_w(szProduct
), iPatchIndex
,
2191 lpPatchBuf
, lpTransformsBuf
, pcchTransformsBuf
);
2193 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
2194 return ERROR_INVALID_PARAMETER
;
2196 if (!lpPatchBuf
|| !lpTransformsBuf
|| !pcchTransformsBuf
)
2197 return ERROR_INVALID_PARAMETER
;
2199 if (MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
,
2200 &prod
, FALSE
) != ERROR_SUCCESS
&&
2201 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
2202 &prod
, FALSE
) != ERROR_SUCCESS
&&
2203 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
2204 &prod
, FALSE
) != ERROR_SUCCESS
)
2205 return ERROR_UNKNOWN_PRODUCT
;
2209 r
= msi_enum_patches(szProduct
, NULL
, MSIINSTALLCONTEXT_ALL
,
2210 MSIPATCHSTATE_ALL
, iPatchIndex
, &idx
, lpPatchBuf
,
2211 NULL
, NULL
, NULL
, NULL
, &transforms
);
2212 if (r
!= ERROR_SUCCESS
)
2215 lstrcpynW(lpTransformsBuf
, transforms
, *pcchTransformsBuf
);
2216 if (*pcchTransformsBuf
<= lstrlenW(transforms
))
2218 r
= ERROR_MORE_DATA
;
2219 *pcchTransformsBuf
= lstrlenW(transforms
);
2222 *pcchTransformsBuf
= lstrlenW(transforms
);
2225 msi_free(transforms
);
2229 UINT WINAPI
MsiEnumProductsExA( LPCSTR product
, LPCSTR usersid
, DWORD ctx
, DWORD index
,
2230 CHAR installed_product
[GUID_SIZE
],
2231 MSIINSTALLCONTEXT
*installed_ctx
, LPSTR sid
, LPDWORD sid_len
)
2234 WCHAR installed_productW
[GUID_SIZE
], *productW
= NULL
, *usersidW
= NULL
, *sidW
= NULL
;
2236 TRACE("%s, %s, %u, %u, %p, %p, %p, %p\n", debugstr_a(product
), debugstr_a(usersid
),
2237 ctx
, index
, installed_product
, installed_ctx
, sid
, sid_len
);
2239 if (sid
&& !sid_len
) return ERROR_INVALID_PARAMETER
;
2240 if (product
&& !(productW
= strdupAtoW( product
))) return ERROR_OUTOFMEMORY
;
2241 if (usersid
&& !(usersidW
= strdupAtoW( usersid
)))
2243 msi_free( productW
);
2244 return ERROR_OUTOFMEMORY
;
2246 if (sid
&& !(sidW
= msi_alloc( *sid_len
* sizeof(WCHAR
) )))
2248 msi_free( usersidW
);
2249 msi_free( productW
);
2250 return ERROR_OUTOFMEMORY
;
2252 r
= MsiEnumProductsExW( productW
, usersidW
, ctx
, index
, installed_productW
,
2253 installed_ctx
, sidW
, sid_len
);
2254 if (r
== ERROR_SUCCESS
)
2256 if (installed_product
) WideCharToMultiByte( CP_ACP
, 0, installed_productW
, GUID_SIZE
,
2257 installed_product
, GUID_SIZE
, NULL
, NULL
);
2258 if (sid
) WideCharToMultiByte( CP_ACP
, 0, sidW
, *sid_len
+ 1, sid
, *sid_len
+ 1, NULL
, NULL
);
2260 msi_free( productW
);
2261 msi_free( usersidW
);
2266 static UINT
fetch_machine_product( const WCHAR
*match
, DWORD index
, DWORD
*idx
,
2267 WCHAR installed_product
[GUID_SIZE
],
2268 MSIINSTALLCONTEXT
*installed_ctx
, WCHAR
*sid
, DWORD
*sid_len
)
2270 static const WCHAR productsW
[] =
2271 {'S','o','f','t','w','a','r','e','\\','C','l','a','s','s','e','s','\\',
2272 'I','n','s','t','a','l','l','e','r','\\','P','r','o','d','u','c','t','s',0};
2274 WCHAR product
[GUID_SIZE
];
2276 REGSAM access
= KEY_ENUMERATE_SUB_KEYS
| KEY_WOW64_64KEY
;
2279 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, productsW
, 0, access
, &key
))
2280 return ERROR_NO_MORE_ITEMS
;
2282 len
= sizeof(product
)/sizeof(product
[0]);
2283 while (!RegEnumKeyExW( key
, i
, product
, &len
, NULL
, NULL
, NULL
, NULL
))
2285 if (match
&& strcmpW( match
, product
))
2288 len
= sizeof(product
)/sizeof(product
[0]);
2291 if (*idx
== index
) goto found
;
2293 len
= sizeof(product
)/sizeof(product
[0]);
2297 return ERROR_NO_MORE_ITEMS
;
2300 if (sid_len
&& *sid_len
< 1)
2303 r
= ERROR_MORE_DATA
;
2307 if (installed_product
) unsquash_guid( product
, installed_product
);
2308 if (installed_ctx
) *installed_ctx
= MSIINSTALLCONTEXT_MACHINE
;
2320 static UINT
fetch_user_product( const WCHAR
*match
, const WCHAR
*usersid
, DWORD ctx
, DWORD index
,
2321 DWORD
*idx
, WCHAR installed_product
[GUID_SIZE
],
2322 MSIINSTALLCONTEXT
*installed_ctx
, WCHAR
*sid
, DWORD
*sid_len
)
2324 static const WCHAR managedW
[] =
2325 {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
2326 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s',
2327 'i','o','n','\\','I','n','s','t','a','l','l','e','r','\\','M','a','n','a','g','e','d',0};
2328 static const WCHAR managed_productsW
[] =
2329 {'\\','I','n','s','t','a','l','l','e','r','\\','P','r','o','d','u','c','t','s',0};
2330 static const WCHAR unmanaged_productsW
[] =
2331 {'\\','S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
2332 'I','n','s','t','a','l','l','e','r','\\','P','r','o','d','u','c','t','s',0};
2334 const WCHAR
*subkey
;
2335 WCHAR path
[MAX_PATH
], product
[GUID_SIZE
], user
[128];
2336 DWORD i
= 0, j
= 0, len_product
, len_user
;
2337 REGSAM access
= KEY_ENUMERATE_SUB_KEYS
| KEY_WOW64_64KEY
;
2338 HKEY key_users
, key_products
;
2340 if (ctx
== MSIINSTALLCONTEXT_USERMANAGED
)
2342 subkey
= managed_productsW
;
2343 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, managedW
, 0, access
, &key_users
))
2344 return ERROR_NO_MORE_ITEMS
;
2346 else if (ctx
== MSIINSTALLCONTEXT_USERUNMANAGED
)
2348 subkey
= unmanaged_productsW
;
2349 if (RegOpenKeyExW( HKEY_USERS
, NULL
, 0, access
, &key_users
))
2350 return ERROR_NO_MORE_ITEMS
;
2352 else return ERROR_INVALID_PARAMETER
;
2354 len_user
= sizeof(user
)/sizeof(user
[0]);
2355 while (!RegEnumKeyExW( key_users
, i
, user
, &len_user
, NULL
, NULL
, NULL
, NULL
))
2357 if (strcmpW( usersid
, user
) && strcmpW( usersid
, szAllSid
))
2360 len_user
= sizeof(user
)/sizeof(user
[0]);
2363 strcpyW( path
, user
);
2364 strcatW( path
, subkey
);
2365 if (RegOpenKeyExW( key_users
, path
, 0, access
, &key_products
))
2368 len_user
= sizeof(user
)/sizeof(user
[0]);
2371 len_product
= sizeof(product
)/sizeof(product
[0]);
2372 while (!RegEnumKeyExW( key_products
, j
, product
, &len_product
, NULL
, NULL
, NULL
, NULL
))
2374 if (match
&& strcmpW( match
, product
))
2377 len_product
= sizeof(product
)/sizeof(product
[0]);
2380 if (*idx
== index
) goto found
;
2382 len_product
= sizeof(product
)/sizeof(product
[0]);
2385 RegCloseKey( key_products
);
2386 len_user
= sizeof(user
)/sizeof(user
[0]);
2389 RegCloseKey( key_users
);
2390 return ERROR_NO_MORE_ITEMS
;
2393 if (sid_len
&& *sid_len
<= len_user
)
2395 *sid_len
= len_user
;
2396 r
= ERROR_MORE_DATA
;
2400 if (installed_product
) unsquash_guid( product
, installed_product
);
2401 if (installed_ctx
) *installed_ctx
= ctx
;
2404 strcpyW( sid
, user
);
2405 *sid_len
= len_user
;
2409 RegCloseKey( key_products
);
2410 RegCloseKey( key_users
);
2414 static UINT
enum_products( const WCHAR
*product
, const WCHAR
*usersid
, DWORD ctx
, DWORD index
,
2415 DWORD
*idx
, WCHAR installed_product
[GUID_SIZE
],
2416 MSIINSTALLCONTEXT
*installed_ctx
, WCHAR
*sid
, DWORD
*sid_len
)
2418 UINT r
= ERROR_NO_MORE_ITEMS
;
2423 usersid
= user
= get_user_sid();
2424 if (!user
) return ERROR_FUNCTION_FAILED
;
2426 if (ctx
& MSIINSTALLCONTEXT_MACHINE
)
2428 r
= fetch_machine_product( product
, index
, idx
, installed_product
, installed_ctx
,
2430 if (r
!= ERROR_NO_MORE_ITEMS
) goto done
;
2432 if (ctx
& MSIINSTALLCONTEXT_USERUNMANAGED
)
2434 r
= fetch_user_product( product
, usersid
, MSIINSTALLCONTEXT_USERUNMANAGED
, index
,
2435 idx
, installed_product
, installed_ctx
, sid
, sid_len
);
2436 if (r
!= ERROR_NO_MORE_ITEMS
) goto done
;
2438 if (ctx
& MSIINSTALLCONTEXT_USERMANAGED
)
2440 r
= fetch_user_product( product
, usersid
, MSIINSTALLCONTEXT_USERMANAGED
, index
,
2441 idx
, installed_product
, installed_ctx
, sid
, sid_len
);
2442 if (r
!= ERROR_NO_MORE_ITEMS
) goto done
;
2450 UINT WINAPI
MsiEnumProductsExW( LPCWSTR product
, LPCWSTR usersid
, DWORD ctx
, DWORD index
,
2451 WCHAR installed_product
[GUID_SIZE
],
2452 MSIINSTALLCONTEXT
*installed_ctx
, LPWSTR sid
, LPDWORD sid_len
)
2456 static DWORD last_index
;
2458 TRACE("%s, %s, %u, %u, %p, %p, %p, %p\n", debugstr_w(product
), debugstr_w(usersid
),
2459 ctx
, index
, installed_product
, installed_ctx
, sid
, sid_len
);
2461 if ((sid
&& !sid_len
) || !ctx
|| (usersid
&& ctx
== MSIINSTALLCONTEXT_MACHINE
))
2462 return ERROR_INVALID_PARAMETER
;
2464 if (index
&& index
- last_index
!= 1)
2465 return ERROR_INVALID_PARAMETER
;
2467 if (!index
) last_index
= 0;
2469 r
= enum_products( product
, usersid
, ctx
, index
, &idx
, installed_product
, installed_ctx
,
2471 if (r
== ERROR_SUCCESS
)