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
);
43 static const BOOL is_64bit
= sizeof(void *) > sizeof(int);
46 * This module will be all the helper functions for registry access by the
49 static const WCHAR szUserFeatures_fmt
[] = {
50 'S','o','f','t','w','a','r','e','\\',
51 'M','i','c','r','o','s','o','f','t','\\',
52 'I','n','s','t','a','l','l','e','r','\\',
53 'F','e','a','t','u','r','e','s','\\',
56 static const WCHAR szUserDataFeatures_fmt
[] = {
57 'S','o','f','t','w','a','r','e','\\',
58 'M','i','c','r','o','s','o','f','t','\\',
59 'W','i','n','d','o','w','s','\\',
60 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
61 'I','n','s','t','a','l','l','e','r','\\',
62 'U','s','e','r','D','a','t','a','\\',
63 '%','s','\\','P','r','o','d','u','c','t','s','\\',
64 '%','s','\\','F','e','a','t','u','r','e','s',0};
66 static const WCHAR szInstaller_Features_fmt
[] = {
67 'S','o','f','t','w','a','r','e','\\',
68 'M','i','c','r','o','s','o','f','t','\\',
69 'W','i','n','d','o','w','s','\\',
70 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
71 'I','n','s','t','a','l','l','e','r','\\',
72 'F','e','a','t','u','r','e','s','\\',
75 static const WCHAR szInstaller_Components
[] = {
76 'S','o','f','t','w','a','r','e','\\',
77 'M','i','c','r','o','s','o','f','t','\\',
78 'W','i','n','d','o','w','s','\\',
79 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
80 'I','n','s','t','a','l','l','e','r','\\',
81 'C','o','m','p','o','n','e','n','t','s',0 };
83 static const WCHAR szUser_Components_fmt
[] = {
84 'S','o','f','t','w','a','r','e','\\',
85 'M','i','c','r','o','s','o','f','t','\\',
86 'I','n','s','t','a','l','l','e','r','\\',
87 'C','o','m','p','o','n','e','n','t','s','\\',
90 static const WCHAR szUserDataComp_fmt
[] = {
91 'S','o','f','t','w','a','r','e','\\',
92 'M','i','c','r','o','s','o','f','t','\\',
93 'W','i','n','d','o','w','s','\\',
94 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
95 'I','n','s','t','a','l','l','e','r','\\',
96 'U','s','e','r','D','a','t','a','\\',
97 '%','s','\\','C','o','m','p','o','n','e','n','t','s','\\','%','s',0};
99 static const WCHAR szUninstall_fmt
[] = {
100 'S','o','f','t','w','a','r','e','\\',
101 'M','i','c','r','o','s','o','f','t','\\',
102 'W','i','n','d','o','w','s','\\',
103 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
104 'U','n','i','n','s','t','a','l','l','\\',
107 static const WCHAR szUninstall_32node_fmt
[] = {
108 'S','o','f','t','w','a','r','e','\\',
109 'W','o','w','6','4','3','2','N','o','d','e','\\',
110 'M','i','c','r','o','s','o','f','t','\\',
111 'W','i','n','d','o','w','s','\\',
112 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
113 'U','n','i','n','s','t','a','l','l','\\',
116 static const WCHAR szUserProduct
[] = {
117 'S','o','f','t','w','a','r','e','\\',
118 'M','i','c','r','o','s','o','f','t','\\',
119 'I','n','s','t','a','l','l','e','r','\\',
120 'P','r','o','d','u','c','t','s',0};
122 static const WCHAR szUserProduct_fmt
[] = {
123 'S','o','f','t','w','a','r','e','\\',
124 'M','i','c','r','o','s','o','f','t','\\',
125 'I','n','s','t','a','l','l','e','r','\\',
126 'P','r','o','d','u','c','t','s','\\',
129 static const WCHAR szUserPatch_fmt
[] = {
130 'S','o','f','t','w','a','r','e','\\',
131 'M','i','c','r','o','s','o','f','t','\\',
132 'I','n','s','t','a','l','l','e','r','\\',
133 'P','a','t','c','h','e','s','\\',
136 static const WCHAR szInstaller_Products
[] = {
137 'S','o','f','t','w','a','r','e','\\',
138 'M','i','c','r','o','s','o','f','t','\\',
139 'W','i','n','d','o','w','s','\\',
140 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
141 'I','n','s','t','a','l','l','e','r','\\',
142 'P','r','o','d','u','c','t','s',0};
144 static const WCHAR szInstaller_Products_fmt
[] = {
145 'S','o','f','t','w','a','r','e','\\',
146 'M','i','c','r','o','s','o','f','t','\\',
147 'W','i','n','d','o','w','s','\\',
148 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
149 'I','n','s','t','a','l','l','e','r','\\',
150 'P','r','o','d','u','c','t','s','\\',
153 static const WCHAR szInstaller_Patches_fmt
[] = {
154 'S','o','f','t','w','a','r','e','\\',
155 'M','i','c','r','o','s','o','f','t','\\',
156 'W','i','n','d','o','w','s','\\',
157 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
158 'I','n','s','t','a','l','l','e','r','\\',
159 'P','a','t','c','h','e','s','\\',
162 static const WCHAR szInstaller_UpgradeCodes_fmt
[] = {
163 'S','o','f','t','w','a','r','e','\\',
164 'M','i','c','r','o','s','o','f','t','\\',
165 'W','i','n','d','o','w','s','\\',
166 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
167 'I','n','s','t','a','l','l','e','r','\\',
168 'U','p','g','r','a','d','e','C','o','d','e','s','\\',
171 static const WCHAR szInstaller_UserUpgradeCodes_fmt
[] = {
172 'S','o','f','t','w','a','r','e','\\',
173 'M','i','c','r','o','s','o','f','t','\\',
174 'I','n','s','t','a','l','l','e','r','\\',
175 'U','p','g','r','a','d','e','C','o','d','e','s','\\',
178 static const WCHAR szUserDataProd_fmt
[] = {
179 'S','o','f','t','w','a','r','e','\\',
180 'M','i','c','r','o','s','o','f','t','\\',
181 'W','i','n','d','o','w','s','\\',
182 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
183 'I','n','s','t','a','l','l','e','r','\\',
184 'U','s','e','r','D','a','t','a','\\',
185 '%','s','\\','P','r','o','d','u','c','t','s','\\','%','s',0};
187 static const WCHAR szUserDataPatch_fmt
[] = {
188 'S','o','f','t','w','a','r','e','\\',
189 'M','i','c','r','o','s','o','f','t','\\',
190 'W','i','n','d','o','w','s','\\',
191 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
192 'I','n','s','t','a','l','l','e','r','\\',
193 'U','s','e','r','D','a','t','a','\\',
194 '%','s','\\','P','a','t','c','h','e','s','\\','%','s',0};
196 static const WCHAR szUserDataProductPatches_fmt
[] = {
197 'S','o','f','t','w','a','r','e','\\',
198 'M','i','c','r','o','s','o','f','t','\\',
199 'W','i','n','d','o','w','s','\\',
200 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
201 'I','n','s','t','a','l','l','e','r','\\',
202 'U','s','e','r','D','a','t','a','\\',
203 '%','s','\\','P','r','o','d','u','c','t','s','\\','%','s','\\',
204 'P','a','t','c','h','e','s',0};
206 static const WCHAR szInstallProperties_fmt
[] = {
207 'S','o','f','t','w','a','r','e','\\',
208 'M','i','c','r','o','s','o','f','t','\\',
209 'W','i','n','d','o','w','s','\\',
210 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
211 'I','n','s','t','a','l','l','e','r','\\',
212 'U','s','e','r','D','a','t','a','\\',
213 '%','s','\\','P','r','o','d','u','c','t','s','\\','%','s','\\',
214 'I','n','s','t','a','l','l','P','r','o','p','e','r','t','i','e','s',0};
216 static const WCHAR szInstaller_LocalClassesProd
[] = {
217 'S','o','f','t','w','a','r','e','\\',
218 'C','l','a','s','s','e','s','\\',
219 'I','n','s','t','a','l','l','e','r','\\',
220 'P','r','o','d','u','c','t','s',0};
222 static const WCHAR szInstaller_LocalClassesProd_fmt
[] = {
223 'S','o','f','t','w','a','r','e','\\',
224 'C','l','a','s','s','e','s','\\',
225 'I','n','s','t','a','l','l','e','r','\\',
226 'P','r','o','d','u','c','t','s','\\','%','s',0};
228 static const WCHAR szInstaller_LocalClassesFeat_fmt
[] = {
229 'S','o','f','t','w','a','r','e','\\',
230 'C','l','a','s','s','e','s','\\',
231 'I','n','s','t','a','l','l','e','r','\\',
232 'F','e','a','t','u','r','e','s','\\','%','s',0};
234 static const WCHAR szInstaller_LocalManaged_fmt
[] = {
235 'S','o','f','t','w','a','r','e','\\',
236 'M','i','c','r','o','s','o','f','t','\\',
237 'W','i','n','d','o','w','s','\\',
238 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
239 'I','n','s','t','a','l','l','e','r','\\',
240 'M','a','n','a','g','e','d','\\','%','s','\\',
241 'I','n','s','t','a','l','l','e','r','\\',
242 'P','r','o','d','u','c','t','s',0};
244 static const WCHAR szInstaller_LocalManagedProd_fmt
[] = {
245 'S','o','f','t','w','a','r','e','\\',
246 'M','i','c','r','o','s','o','f','t','\\',
247 'W','i','n','d','o','w','s','\\',
248 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
249 'I','n','s','t','a','l','l','e','r','\\',
250 'M','a','n','a','g','e','d','\\','%','s','\\',
251 'I','n','s','t','a','l','l','e','r','\\',
252 'P','r','o','d','u','c','t','s','\\','%','s',0};
254 static const WCHAR szInstaller_LocalManagedFeat_fmt
[] = {
255 'S','o','f','t','w','a','r','e','\\',
256 'M','i','c','r','o','s','o','f','t','\\',
257 'W','i','n','d','o','w','s','\\',
258 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
259 'I','n','s','t','a','l','l','e','r','\\',
260 'M','a','n','a','g','e','d','\\','%','s','\\',
261 'I','n','s','t','a','l','l','e','r','\\',
262 'F','e','a','t','u','r','e','s','\\','%','s',0};
264 static const WCHAR szInstaller_ClassesUpgrade_fmt
[] = {
265 'I','n','s','t','a','l','l','e','r','\\',
266 'U','p','g','r','a','d','e','C','o','d','e','s','\\',
269 BOOL
unsquash_guid(LPCWSTR in
, LPWSTR out
)
273 if (lstrlenW(in
) != 32)
288 out
[n
++] = in
[17+i
*2];
289 out
[n
++] = in
[16+i
*2];
294 out
[n
++] = in
[17+i
*2];
295 out
[n
++] = in
[16+i
*2];
302 BOOL
squash_guid(LPCWSTR in
, LPWSTR out
)
309 if (FAILED(CLSIDFromString((LPCOLESTR
)in
, &guid
)))
323 out
[17+i
*2] = in
[n
++];
324 out
[16+i
*2] = in
[n
++];
329 out
[17+i
*2] = in
[n
++];
330 out
[16+i
*2] = in
[n
++];
337 /* tables for encoding and decoding base85 */
338 static const unsigned char table_dec85
[0x80] = {
339 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
340 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
341 0xff,0x00,0xff,0xff,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0xff,
342 0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0xff,0xff,0xff,0x16,0xff,0x17,
343 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,
344 0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0xff,0x34,0x35,0x36,
345 0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44,0x45,0x46,
346 0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0xff,0x53,0x54,0xff,
349 static const char table_enc85
[] =
350 "!$%&'()*+,-.0123456789=?@ABCDEFGHIJKLMNO"
351 "PQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwx"
355 * Converts a base85 encoded guid into a GUID pointer
356 * Base85 encoded GUIDs should be 20 characters long.
358 * returns TRUE if successful, FALSE if not
360 BOOL
decode_base85_guid( LPCWSTR str
, GUID
*guid
)
362 DWORD i
, val
= 0, base
= 1, *p
;
368 for( i
=0; i
<20; i
++ )
375 val
+= table_dec85
[str
[i
]] * base
;
378 if( table_dec85
[str
[i
]] == 0xff )
388 * Encodes a base85 guid given a GUID pointer
389 * Caller should provide a 21 character buffer for the encoded string.
391 * returns TRUE if successful, FALSE if not
393 BOOL
encode_base85_guid( GUID
*guid
, LPWSTR str
)
395 unsigned int x
, *p
, i
;
397 p
= (unsigned int*) guid
;
401 *str
++ = table_enc85
[x
%85];
403 *str
++ = table_enc85
[x
%85];
405 *str
++ = table_enc85
[x
%85];
407 *str
++ = table_enc85
[x
%85];
409 *str
++ = table_enc85
[x
%85];
416 DWORD
msi_version_str_to_dword(LPCWSTR p
)
418 DWORD major
, minor
= 0, build
= 0, version
= 0;
429 p
= strchrW(p
+1, '.');
434 return MAKELONG(build
, MAKEWORD(minor
, major
));
437 LONG
msi_reg_set_val_str( HKEY hkey
, LPCWSTR name
, LPCWSTR value
)
440 if (!value
) value
= szEmpty
;
441 len
= (lstrlenW(value
) + 1) * sizeof (WCHAR
);
442 return RegSetValueExW( hkey
, name
, 0, REG_SZ
, (const BYTE
*)value
, len
);
445 LONG
msi_reg_set_val_multi_str( HKEY hkey
, LPCWSTR name
, LPCWSTR value
)
448 while (*p
) p
+= lstrlenW(p
) + 1;
449 return RegSetValueExW( hkey
, name
, 0, REG_MULTI_SZ
,
450 (const BYTE
*)value
, (p
+ 1 - value
) * sizeof(WCHAR
) );
453 LONG
msi_reg_set_val_dword( HKEY hkey
, LPCWSTR name
, DWORD val
)
455 return RegSetValueExW( hkey
, name
, 0, REG_DWORD
, (LPBYTE
)&val
, sizeof (DWORD
) );
458 LONG
msi_reg_set_subkey_val( HKEY hkey
, LPCWSTR path
, LPCWSTR name
, LPCWSTR val
)
463 r
= RegCreateKeyW( hkey
, path
, &hsubkey
);
464 if (r
!= ERROR_SUCCESS
)
466 r
= msi_reg_set_val_str( hsubkey
, name
, val
);
467 RegCloseKey( hsubkey
);
471 LPWSTR
msi_reg_get_val_str( HKEY hkey
, LPCWSTR name
)
477 r
= RegQueryValueExW(hkey
, name
, NULL
, NULL
, NULL
, &len
);
478 if (r
!= ERROR_SUCCESS
)
481 len
+= sizeof (WCHAR
);
482 val
= msi_alloc( len
);
486 RegQueryValueExW(hkey
, name
, NULL
, NULL
, (LPBYTE
) val
, &len
);
490 BOOL
msi_reg_get_val_dword( HKEY hkey
, LPCWSTR name
, DWORD
*val
)
492 DWORD type
, len
= sizeof (DWORD
);
493 LONG r
= RegQueryValueExW(hkey
, name
, NULL
, &type
, (LPBYTE
) val
, &len
);
494 return r
== ERROR_SUCCESS
&& type
== REG_DWORD
;
497 static UINT
get_user_sid(LPWSTR
*usersid
)
504 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY
, &token
))
505 return ERROR_FUNCTION_FAILED
;
508 if (!GetTokenInformation(token
, TokenUser
, buf
, size
, &size
)) {
510 return ERROR_FUNCTION_FAILED
;
513 user
= (PTOKEN_USER
)buf
;
514 if (!ConvertSidToStringSidW(user
->User
.Sid
, usersid
)) {
516 return ERROR_FUNCTION_FAILED
;
519 return ERROR_SUCCESS
;
522 UINT
MSIREG_OpenUninstallKey(MSIPACKAGE
*package
, HKEY
*key
, BOOL create
)
525 WCHAR keypath
[0x200];
527 TRACE("%s\n", debugstr_w(package
->ProductCode
));
529 if (is_64bit
&& package
->platform
== PLATFORM_INTEL
)
530 sprintfW(keypath
, szUninstall_32node_fmt
, package
->ProductCode
);
532 sprintfW(keypath
, szUninstall_fmt
, package
->ProductCode
);
535 rc
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, key
, NULL
);
537 rc
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, KEY_ALL_ACCESS
, key
);
542 UINT
MSIREG_DeleteUninstallKey(MSIPACKAGE
*package
)
544 WCHAR keypath
[0x200];
546 TRACE("%s\n", debugstr_w(package
->ProductCode
));
548 if (is_64bit
&& package
->platform
== PLATFORM_INTEL
)
549 sprintfW(keypath
, szUninstall_32node_fmt
, package
->ProductCode
);
551 sprintfW(keypath
, szUninstall_fmt
, package
->ProductCode
);
553 return RegDeleteTreeW(HKEY_LOCAL_MACHINE
, keypath
);
556 UINT
MSIREG_OpenProductKey(LPCWSTR szProduct
, LPCWSTR szUserSid
,
557 MSIINSTALLCONTEXT context
, HKEY
*key
, BOOL create
)
560 LPWSTR usersid
= NULL
;
561 HKEY root
= HKEY_LOCAL_MACHINE
;
562 WCHAR squished_pc
[GUID_SIZE
];
563 WCHAR keypath
[MAX_PATH
];
565 TRACE("(%s, %d, %d)\n", debugstr_w(szProduct
), context
, create
);
567 if (!squash_guid(szProduct
, squished_pc
))
568 return ERROR_FUNCTION_FAILED
;
570 TRACE("squished (%s)\n", debugstr_w(squished_pc
));
572 if (context
== MSIINSTALLCONTEXT_MACHINE
)
574 sprintfW(keypath
, szInstaller_LocalClassesProd_fmt
, squished_pc
);
576 else if (context
== MSIINSTALLCONTEXT_USERUNMANAGED
)
578 root
= HKEY_CURRENT_USER
;
579 sprintfW(keypath
, szUserProduct_fmt
, squished_pc
);
585 r
= get_user_sid(&usersid
);
586 if (r
!= ERROR_SUCCESS
|| !usersid
)
588 ERR("Failed to retrieve user SID: %d\n", r
);
595 sprintfW(keypath
, szInstaller_LocalManagedProd_fmt
,
596 szUserSid
, squished_pc
);
601 return RegCreateKeyW(root
, keypath
, key
);
603 return RegOpenKeyW(root
, keypath
, key
);
606 UINT
MSIREG_DeleteUserProductKey(LPCWSTR szProduct
)
608 WCHAR squished_pc
[GUID_SIZE
];
609 WCHAR keypath
[0x200];
611 TRACE("%s\n",debugstr_w(szProduct
));
612 if (!squash_guid(szProduct
,squished_pc
))
613 return ERROR_FUNCTION_FAILED
;
614 TRACE("squished (%s)\n", debugstr_w(squished_pc
));
616 sprintfW(keypath
,szUserProduct_fmt
,squished_pc
);
618 return RegDeleteTreeW(HKEY_CURRENT_USER
, keypath
);
621 UINT
MSIREG_OpenUserPatchesKey(LPCWSTR szPatch
, HKEY
* key
, BOOL create
)
624 WCHAR squished_pc
[GUID_SIZE
];
625 WCHAR keypath
[0x200];
627 TRACE("%s\n",debugstr_w(szPatch
));
628 if (!squash_guid(szPatch
,squished_pc
))
629 return ERROR_FUNCTION_FAILED
;
630 TRACE("squished (%s)\n", debugstr_w(squished_pc
));
632 sprintfW(keypath
,szUserPatch_fmt
,squished_pc
);
635 rc
= RegCreateKeyW(HKEY_CURRENT_USER
,keypath
,key
);
637 rc
= RegOpenKeyW(HKEY_CURRENT_USER
,keypath
,key
);
642 UINT
MSIREG_OpenFeaturesKey(LPCWSTR szProduct
, MSIINSTALLCONTEXT context
,
643 HKEY
*key
, BOOL create
)
647 HKEY root
= HKEY_LOCAL_MACHINE
;
648 WCHAR squished_pc
[GUID_SIZE
];
649 WCHAR keypath
[MAX_PATH
];
651 TRACE("(%s, %d, %d)\n", debugstr_w(szProduct
), context
, create
);
653 if (!squash_guid(szProduct
, squished_pc
))
654 return ERROR_FUNCTION_FAILED
;
656 TRACE("squished (%s)\n", debugstr_w(squished_pc
));
658 if (context
== MSIINSTALLCONTEXT_MACHINE
)
660 sprintfW(keypath
, szInstaller_LocalClassesFeat_fmt
, squished_pc
);
662 else if (context
== MSIINSTALLCONTEXT_USERUNMANAGED
)
664 root
= HKEY_CURRENT_USER
;
665 sprintfW(keypath
, szUserFeatures_fmt
, squished_pc
);
669 r
= get_user_sid(&usersid
);
670 if (r
!= ERROR_SUCCESS
|| !usersid
)
672 ERR("Failed to retrieve user SID: %d\n", r
);
676 sprintfW(keypath
, szInstaller_LocalManagedFeat_fmt
, usersid
, squished_pc
);
681 return RegCreateKeyW(root
, keypath
, key
);
683 return RegOpenKeyW(root
, keypath
, key
);
686 UINT
MSIREG_DeleteUserFeaturesKey(LPCWSTR szProduct
)
688 WCHAR squished_pc
[GUID_SIZE
];
689 WCHAR keypath
[0x200];
691 TRACE("%s\n",debugstr_w(szProduct
));
692 if (!squash_guid(szProduct
,squished_pc
))
693 return ERROR_FUNCTION_FAILED
;
694 TRACE("squished (%s)\n", debugstr_w(squished_pc
));
696 sprintfW(keypath
,szUserFeatures_fmt
,squished_pc
);
697 return RegDeleteTreeW(HKEY_CURRENT_USER
, keypath
);
700 static UINT
MSIREG_OpenInstallerFeaturesKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
)
703 WCHAR squished_pc
[GUID_SIZE
];
704 WCHAR keypath
[0x200];
706 TRACE("%s\n",debugstr_w(szProduct
));
707 if (!squash_guid(szProduct
,squished_pc
))
708 return ERROR_FUNCTION_FAILED
;
709 TRACE("squished (%s)\n", debugstr_w(squished_pc
));
711 sprintfW(keypath
,szInstaller_Features_fmt
,squished_pc
);
714 rc
= RegCreateKeyW(HKEY_LOCAL_MACHINE
,keypath
,key
);
716 rc
= RegOpenKeyW(HKEY_LOCAL_MACHINE
,keypath
,key
);
721 UINT
MSIREG_OpenUserDataFeaturesKey(LPCWSTR szProduct
, MSIINSTALLCONTEXT context
,
722 HKEY
*key
, BOOL create
)
726 WCHAR squished_pc
[GUID_SIZE
];
727 WCHAR keypath
[0x200];
729 TRACE("(%s, %d, %d)\n", debugstr_w(szProduct
), context
, create
);
731 if (!squash_guid(szProduct
, squished_pc
))
732 return ERROR_FUNCTION_FAILED
;
734 TRACE("squished (%s)\n", debugstr_w(squished_pc
));
736 if (context
== MSIINSTALLCONTEXT_MACHINE
)
738 sprintfW(keypath
, szUserDataFeatures_fmt
, szLocalSid
, squished_pc
);
742 r
= get_user_sid(&usersid
);
743 if (r
!= ERROR_SUCCESS
|| !usersid
)
745 ERR("Failed to retrieve user SID: %d\n", r
);
749 sprintfW(keypath
, szUserDataFeatures_fmt
, usersid
, squished_pc
);
754 return RegCreateKeyW(HKEY_LOCAL_MACHINE
, keypath
, key
);
756 return RegOpenKeyW(HKEY_LOCAL_MACHINE
, keypath
, key
);
759 UINT
MSIREG_OpenUserComponentsKey(LPCWSTR szComponent
, HKEY
* key
, BOOL create
)
762 WCHAR squished_cc
[GUID_SIZE
];
763 WCHAR keypath
[0x200];
765 TRACE("%s\n",debugstr_w(szComponent
));
766 if (!squash_guid(szComponent
,squished_cc
))
767 return ERROR_FUNCTION_FAILED
;
768 TRACE("squished (%s)\n", debugstr_w(squished_cc
));
770 sprintfW(keypath
,szUser_Components_fmt
,squished_cc
);
773 rc
= RegCreateKeyW(HKEY_CURRENT_USER
,keypath
,key
);
775 rc
= RegOpenKeyW(HKEY_CURRENT_USER
,keypath
,key
);
780 UINT
MSIREG_OpenUserDataComponentKey(LPCWSTR szComponent
, LPCWSTR szUserSid
,
781 HKEY
*key
, BOOL create
)
784 WCHAR comp
[GUID_SIZE
];
785 WCHAR keypath
[0x200];
788 TRACE("%s\n", debugstr_w(szComponent
));
789 if (!squash_guid(szComponent
, comp
))
790 return ERROR_FUNCTION_FAILED
;
791 TRACE("squished (%s)\n", debugstr_w(comp
));
795 rc
= get_user_sid(&usersid
);
796 if (rc
!= ERROR_SUCCESS
|| !usersid
)
798 ERR("Failed to retrieve user SID: %d\n", rc
);
802 sprintfW(keypath
, szUserDataComp_fmt
, usersid
, comp
);
806 sprintfW(keypath
, szUserDataComp_fmt
, szUserSid
, comp
);
809 rc
= RegCreateKeyW(HKEY_LOCAL_MACHINE
, keypath
, key
);
811 rc
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, keypath
, key
);
816 UINT
MSIREG_DeleteUserDataComponentKey(LPCWSTR szComponent
, LPCWSTR szUserSid
)
819 WCHAR comp
[GUID_SIZE
];
820 WCHAR keypath
[0x200];
823 TRACE("%s\n", debugstr_w(szComponent
));
824 if (!squash_guid(szComponent
, comp
))
825 return ERROR_FUNCTION_FAILED
;
826 TRACE("squished (%s)\n", debugstr_w(comp
));
830 rc
= get_user_sid(&usersid
);
831 if (rc
!= ERROR_SUCCESS
|| !usersid
)
833 ERR("Failed to retrieve user SID: %d\n", rc
);
837 sprintfW(keypath
, szUserDataComp_fmt
, usersid
, comp
);
841 sprintfW(keypath
, szUserDataComp_fmt
, szUserSid
, comp
);
843 return RegDeleteTreeW(HKEY_LOCAL_MACHINE
, keypath
);
846 UINT
MSIREG_OpenUserDataProductKey(LPCWSTR szProduct
, MSIINSTALLCONTEXT dwContext
,
847 LPCWSTR szUserSid
, HKEY
*key
, BOOL create
)
850 WCHAR squished_pc
[GUID_SIZE
];
851 WCHAR keypath
[0x200];
854 TRACE("%s\n", debugstr_w(szProduct
));
855 if (!squash_guid(szProduct
, squished_pc
))
856 return ERROR_FUNCTION_FAILED
;
857 TRACE("squished (%s)\n", debugstr_w(squished_pc
));
859 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
860 sprintfW(keypath
, szUserDataProd_fmt
, szLocalSid
, squished_pc
);
862 sprintfW(keypath
, szUserDataProd_fmt
, szUserSid
, squished_pc
);
865 rc
= get_user_sid(&usersid
);
866 if (rc
!= ERROR_SUCCESS
|| !usersid
)
868 ERR("Failed to retrieve user SID: %d\n", rc
);
872 sprintfW(keypath
, szUserDataProd_fmt
, usersid
, squished_pc
);
877 rc
= RegCreateKeyW(HKEY_LOCAL_MACHINE
, keypath
, key
);
879 rc
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, keypath
, key
);
884 UINT
MSIREG_OpenUserDataPatchKey(LPCWSTR szPatch
, MSIINSTALLCONTEXT dwContext
,
885 HKEY
*key
, BOOL create
)
888 WCHAR squished_patch
[GUID_SIZE
];
889 WCHAR keypath
[0x200];
892 TRACE("%s\n", debugstr_w(szPatch
));
893 if (!squash_guid(szPatch
, squished_patch
))
894 return ERROR_FUNCTION_FAILED
;
895 TRACE("squished (%s)\n", debugstr_w(squished_patch
));
897 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
898 sprintfW(keypath
, szUserDataPatch_fmt
, szLocalSid
, squished_patch
);
901 rc
= get_user_sid(&usersid
);
902 if (rc
!= ERROR_SUCCESS
|| !usersid
)
904 ERR("Failed to retrieve user SID: %d\n", rc
);
908 sprintfW(keypath
, szUserDataPatch_fmt
, usersid
, squished_patch
);
913 return RegCreateKeyW(HKEY_LOCAL_MACHINE
, keypath
, key
);
915 return RegOpenKeyW(HKEY_LOCAL_MACHINE
, keypath
, key
);
918 UINT
MSIREG_DeleteUserDataPatchKey(LPCWSTR patch
, MSIINSTALLCONTEXT context
)
921 WCHAR squished_patch
[GUID_SIZE
];
922 WCHAR keypath
[0x200];
925 TRACE("%s\n", debugstr_w(patch
));
926 if (!squash_guid(patch
, squished_patch
))
927 return ERROR_FUNCTION_FAILED
;
928 TRACE("squished (%s)\n", debugstr_w(squished_patch
));
930 if (context
== MSIINSTALLCONTEXT_MACHINE
)
931 sprintfW(keypath
, szUserDataPatch_fmt
, szLocalSid
, squished_patch
);
934 r
= get_user_sid(&usersid
);
935 if (r
!= ERROR_SUCCESS
|| !usersid
)
937 ERR("Failed to retrieve user SID: %d\n", r
);
941 sprintfW(keypath
, szUserDataPatch_fmt
, usersid
, squished_patch
);
945 return RegDeleteTreeW(HKEY_LOCAL_MACHINE
, keypath
);
948 UINT
MSIREG_OpenUserDataProductPatchesKey(LPCWSTR product
, MSIINSTALLCONTEXT context
,
949 HKEY
*key
, BOOL create
)
952 WCHAR squished_product
[GUID_SIZE
];
953 WCHAR keypath
[0x200];
956 TRACE("%s\n", debugstr_w(product
));
957 if (!squash_guid(product
, squished_product
))
958 return ERROR_FUNCTION_FAILED
;
960 if (context
== MSIINSTALLCONTEXT_MACHINE
)
961 sprintfW(keypath
, szUserDataProductPatches_fmt
, szLocalSid
, squished_product
);
964 rc
= get_user_sid(&usersid
);
965 if (rc
!= ERROR_SUCCESS
|| !usersid
)
967 ERR("Failed to retrieve user SID: %d\n", rc
);
971 sprintfW(keypath
, szUserDataProductPatches_fmt
, usersid
, squished_product
);
976 return RegCreateKeyW(HKEY_LOCAL_MACHINE
, keypath
, key
);
978 return RegOpenKeyW(HKEY_LOCAL_MACHINE
, keypath
, key
);
981 UINT
MSIREG_OpenInstallProps(LPCWSTR szProduct
, MSIINSTALLCONTEXT dwContext
,
982 LPCWSTR szUserSid
, HKEY
*key
, BOOL create
)
986 WCHAR squished_pc
[GUID_SIZE
];
987 WCHAR keypath
[0x200];
989 TRACE("%s\n", debugstr_w(szProduct
));
990 if (!squash_guid(szProduct
, squished_pc
))
991 return ERROR_FUNCTION_FAILED
;
992 TRACE("squished (%s)\n", debugstr_w(squished_pc
));
994 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
995 sprintfW(keypath
, szInstallProperties_fmt
, szLocalSid
, squished_pc
);
997 sprintfW(keypath
, szInstallProperties_fmt
, szUserSid
, squished_pc
);
1000 rc
= get_user_sid(&usersid
);
1001 if (rc
!= ERROR_SUCCESS
|| !usersid
)
1003 ERR("Failed to retrieve user SID: %d\n", rc
);
1007 sprintfW(keypath
, szInstallProperties_fmt
, usersid
, squished_pc
);
1012 return RegCreateKeyW(HKEY_LOCAL_MACHINE
, keypath
, key
);
1014 return RegOpenKeyW(HKEY_LOCAL_MACHINE
, keypath
, key
);
1017 UINT
MSIREG_DeleteUserDataProductKey(LPCWSTR szProduct
)
1020 WCHAR squished_pc
[GUID_SIZE
];
1021 WCHAR keypath
[0x200];
1024 TRACE("%s\n", debugstr_w(szProduct
));
1025 if (!squash_guid(szProduct
, squished_pc
))
1026 return ERROR_FUNCTION_FAILED
;
1027 TRACE("squished (%s)\n", debugstr_w(squished_pc
));
1029 rc
= get_user_sid(&usersid
);
1030 if (rc
!= ERROR_SUCCESS
|| !usersid
)
1032 ERR("Failed to retrieve user SID: %d\n", rc
);
1036 sprintfW(keypath
, szUserDataProd_fmt
, usersid
, squished_pc
);
1039 return RegDeleteTreeW(HKEY_LOCAL_MACHINE
, keypath
);
1042 UINT
MSIREG_DeleteProductKey(LPCWSTR szProduct
)
1044 WCHAR squished_pc
[GUID_SIZE
];
1045 WCHAR keypath
[0x200];
1047 TRACE("%s\n", debugstr_w(szProduct
));
1048 if (!squash_guid(szProduct
, squished_pc
))
1049 return ERROR_FUNCTION_FAILED
;
1050 TRACE("squished (%s)\n", debugstr_w(squished_pc
));
1052 sprintfW(keypath
, szInstaller_Products_fmt
, squished_pc
);
1054 return RegDeleteTreeW(HKEY_LOCAL_MACHINE
, keypath
);
1057 UINT
MSIREG_OpenPatchesKey(LPCWSTR szPatch
, HKEY
* key
, BOOL create
)
1060 WCHAR squished_pc
[GUID_SIZE
];
1061 WCHAR keypath
[0x200];
1063 TRACE("%s\n",debugstr_w(szPatch
));
1064 if (!squash_guid(szPatch
,squished_pc
))
1065 return ERROR_FUNCTION_FAILED
;
1066 TRACE("squished (%s)\n", debugstr_w(squished_pc
));
1068 sprintfW(keypath
,szInstaller_Patches_fmt
,squished_pc
);
1071 rc
= RegCreateKeyW(HKEY_LOCAL_MACHINE
,keypath
,key
);
1073 rc
= RegOpenKeyW(HKEY_LOCAL_MACHINE
,keypath
,key
);
1078 UINT
MSIREG_OpenUpgradeCodesKey(LPCWSTR szUpgradeCode
, HKEY
* key
, BOOL create
)
1081 WCHAR squished_pc
[GUID_SIZE
];
1082 WCHAR keypath
[0x200];
1084 TRACE("%s\n",debugstr_w(szUpgradeCode
));
1085 if (!squash_guid(szUpgradeCode
,squished_pc
))
1086 return ERROR_FUNCTION_FAILED
;
1087 TRACE("squished (%s)\n", debugstr_w(squished_pc
));
1089 sprintfW(keypath
,szInstaller_UpgradeCodes_fmt
,squished_pc
);
1092 rc
= RegCreateKeyW(HKEY_LOCAL_MACHINE
,keypath
,key
);
1094 rc
= RegOpenKeyW(HKEY_LOCAL_MACHINE
,keypath
,key
);
1099 UINT
MSIREG_OpenUserUpgradeCodesKey(LPCWSTR szUpgradeCode
, HKEY
* key
, BOOL create
)
1102 WCHAR squished_pc
[GUID_SIZE
];
1103 WCHAR keypath
[0x200];
1105 TRACE("%s\n",debugstr_w(szUpgradeCode
));
1106 if (!squash_guid(szUpgradeCode
,squished_pc
))
1107 return ERROR_FUNCTION_FAILED
;
1108 TRACE("squished (%s)\n", debugstr_w(squished_pc
));
1110 sprintfW(keypath
,szInstaller_UserUpgradeCodes_fmt
,squished_pc
);
1113 rc
= RegCreateKeyW(HKEY_CURRENT_USER
,keypath
,key
);
1115 rc
= RegOpenKeyW(HKEY_CURRENT_USER
,keypath
,key
);
1120 UINT
MSIREG_DeleteUserUpgradeCodesKey(LPCWSTR szUpgradeCode
)
1122 WCHAR squished_pc
[GUID_SIZE
];
1123 WCHAR keypath
[0x200];
1125 TRACE("%s\n",debugstr_w(szUpgradeCode
));
1126 if (!squash_guid(szUpgradeCode
,squished_pc
))
1127 return ERROR_FUNCTION_FAILED
;
1128 TRACE("squished (%s)\n", debugstr_w(squished_pc
));
1130 sprintfW(keypath
,szInstaller_UserUpgradeCodes_fmt
,squished_pc
);
1132 return RegDeleteTreeW(HKEY_CURRENT_USER
, keypath
);
1135 UINT
MSIREG_DeleteLocalClassesProductKey(LPCWSTR szProductCode
)
1137 WCHAR squished_pc
[GUID_SIZE
];
1138 WCHAR keypath
[0x200];
1140 TRACE("%s\n", debugstr_w(szProductCode
));
1142 if (!squash_guid(szProductCode
, squished_pc
))
1143 return ERROR_FUNCTION_FAILED
;
1145 TRACE("squished (%s)\n", debugstr_w(squished_pc
));
1147 sprintfW(keypath
, szInstaller_LocalClassesProd_fmt
, squished_pc
);
1149 return RegDeleteTreeW(HKEY_LOCAL_MACHINE
, keypath
);
1152 UINT
MSIREG_DeleteLocalClassesFeaturesKey(LPCWSTR szProductCode
)
1154 WCHAR squished_pc
[GUID_SIZE
];
1155 WCHAR keypath
[0x200];
1157 TRACE("%s\n", debugstr_w(szProductCode
));
1159 if (!squash_guid(szProductCode
, squished_pc
))
1160 return ERROR_FUNCTION_FAILED
;
1162 TRACE("squished (%s)\n", debugstr_w(squished_pc
));
1164 sprintfW(keypath
, szInstaller_LocalClassesFeat_fmt
, squished_pc
);
1166 return RegDeleteTreeW(HKEY_LOCAL_MACHINE
, keypath
);
1169 UINT
MSIREG_OpenClassesUpgradeCodesKey(LPCWSTR szUpgradeCode
, HKEY
* key
, BOOL create
)
1171 WCHAR squished_pc
[GUID_SIZE
];
1172 WCHAR keypath
[0x200];
1174 TRACE("%s\n", debugstr_w(szUpgradeCode
));
1175 if (!squash_guid(szUpgradeCode
, squished_pc
))
1176 return ERROR_FUNCTION_FAILED
;
1177 TRACE("squished (%s)\n", debugstr_w(squished_pc
));
1179 sprintfW(keypath
, szInstaller_ClassesUpgrade_fmt
, squished_pc
);
1182 return RegCreateKeyW(HKEY_CLASSES_ROOT
, keypath
, key
);
1184 return RegOpenKeyW(HKEY_CLASSES_ROOT
, keypath
, key
);
1187 /*************************************************************************
1188 * MsiDecomposeDescriptorW [MSI.@]
1190 * Decomposes an MSI descriptor into product, feature and component parts.
1191 * An MSI descriptor is a string of the form:
1192 * [base 85 guid] [feature code] '>' [base 85 guid]
1195 * szDescriptor [I] the descriptor to decompose
1196 * szProduct [O] buffer of MAX_FEATURE_CHARS+1 for the product guid
1197 * szFeature [O] buffer of MAX_FEATURE_CHARS+1 for the feature code
1198 * szComponent [O] buffer of MAX_FEATURE_CHARS+1 for the component guid
1199 * pUsed [O] the length of the descriptor
1202 * ERROR_SUCCESS if everything worked correctly
1203 * ERROR_INVALID_PARAMETER if the descriptor was invalid
1206 UINT WINAPI
MsiDecomposeDescriptorW( LPCWSTR szDescriptor
, LPWSTR szProduct
,
1207 LPWSTR szFeature
, LPWSTR szComponent
, LPDWORD pUsed
)
1211 GUID product
, component
;
1213 TRACE("%s %p %p %p %p\n", debugstr_w(szDescriptor
), szProduct
,
1214 szFeature
, szComponent
, pUsed
);
1216 r
= decode_base85_guid( szDescriptor
, &product
);
1218 return ERROR_INVALID_PARAMETER
;
1220 TRACE("product %s\n", debugstr_guid( &product
));
1222 p
= strchrW(&szDescriptor
[20],'>');
1224 return ERROR_INVALID_PARAMETER
;
1226 len
= (p
- &szDescriptor
[20]);
1227 if( len
> MAX_FEATURE_CHARS
)
1228 return ERROR_INVALID_PARAMETER
;
1230 TRACE("feature %s\n", debugstr_wn( &szDescriptor
[20], len
));
1232 r
= decode_base85_guid( p
+1, &component
);
1234 return ERROR_INVALID_PARAMETER
;
1236 TRACE("component %s\n", debugstr_guid( &component
));
1239 StringFromGUID2( &product
, szProduct
, MAX_FEATURE_CHARS
+1 );
1241 StringFromGUID2( &component
, szComponent
, MAX_FEATURE_CHARS
+1 );
1244 memcpy( szFeature
, &szDescriptor
[20], len
*sizeof(WCHAR
) );
1247 len
= ( &p
[21] - szDescriptor
);
1249 TRACE("length = %d\n", len
);
1250 if (pUsed
) *pUsed
= len
;
1252 return ERROR_SUCCESS
;
1255 UINT WINAPI
MsiDecomposeDescriptorA( LPCSTR szDescriptor
, LPSTR szProduct
,
1256 LPSTR szFeature
, LPSTR szComponent
, LPDWORD pUsed
)
1258 WCHAR product
[MAX_FEATURE_CHARS
+1];
1259 WCHAR feature
[MAX_FEATURE_CHARS
+1];
1260 WCHAR component
[MAX_FEATURE_CHARS
+1];
1261 LPWSTR str
= NULL
, p
= NULL
, f
= NULL
, c
= NULL
;
1264 TRACE("%s %p %p %p %p\n", debugstr_a(szDescriptor
), szProduct
,
1265 szFeature
, szComponent
, pUsed
);
1267 str
= strdupAtoW( szDescriptor
);
1268 if( szDescriptor
&& !str
)
1269 return ERROR_OUTOFMEMORY
;
1278 r
= MsiDecomposeDescriptorW( str
, p
, f
, c
, pUsed
);
1280 if (r
== ERROR_SUCCESS
)
1282 WideCharToMultiByte( CP_ACP
, 0, p
, -1,
1283 szProduct
, MAX_FEATURE_CHARS
+1, NULL
, NULL
);
1284 WideCharToMultiByte( CP_ACP
, 0, f
, -1,
1285 szFeature
, MAX_FEATURE_CHARS
+1, NULL
, NULL
);
1286 WideCharToMultiByte( CP_ACP
, 0, c
, -1,
1287 szComponent
, MAX_FEATURE_CHARS
+1, NULL
, NULL
);
1295 UINT WINAPI
MsiEnumProductsA(DWORD index
, LPSTR lpguid
)
1298 WCHAR szwGuid
[GUID_SIZE
];
1300 TRACE("%d %p\n", index
, lpguid
);
1303 return ERROR_INVALID_PARAMETER
;
1304 r
= MsiEnumProductsW(index
, szwGuid
);
1305 if( r
== ERROR_SUCCESS
)
1306 WideCharToMultiByte(CP_ACP
, 0, szwGuid
, -1, lpguid
, GUID_SIZE
, NULL
, NULL
);
1311 UINT WINAPI
MsiEnumProductsW(DWORD index
, LPWSTR lpguid
)
1314 WCHAR szKeyName
[SQUISH_GUID_SIZE
];
1316 DWORD machine_count
, managed_count
, unmanaged_count
;
1317 WCHAR keypath
[MAX_PATH
];
1318 LPWSTR usersid
= NULL
;
1320 static DWORD last_index
;
1322 TRACE("%d %p\n", index
, lpguid
);
1325 return ERROR_INVALID_PARAMETER
;
1327 if (index
&& index
- last_index
!= 1)
1328 return ERROR_INVALID_PARAMETER
;
1331 r
= RegCreateKeyW(HKEY_LOCAL_MACHINE
, szInstaller_LocalClassesProd
, &key
);
1332 if( r
!= ERROR_SUCCESS
) goto failed
;
1334 r
= RegQueryInfoKeyW(key
, NULL
, NULL
, NULL
, &machine_count
, NULL
, NULL
,
1335 NULL
, NULL
, NULL
, NULL
, NULL
);
1336 if( r
!= ERROR_SUCCESS
) goto failed
;
1338 if (machine_count
&& index
<= machine_count
)
1340 r
= RegEnumKeyW(key
, index
, szKeyName
, SQUISH_GUID_SIZE
);
1341 if( r
== ERROR_SUCCESS
)
1343 unsquash_guid(szKeyName
, lpguid
);
1346 return ERROR_SUCCESS
;
1352 r
= get_user_sid(&usersid
);
1353 if (r
!= ERROR_SUCCESS
|| !usersid
)
1355 ERR("Failed to retrieve user SID: %d\n", r
);
1359 sprintfW(keypath
, szInstaller_LocalManaged_fmt
, usersid
);
1362 r
= RegCreateKeyW(HKEY_LOCAL_MACHINE
, keypath
, &key
);
1363 if( r
!= ERROR_SUCCESS
) goto failed
;
1365 r
= RegQueryInfoKeyW(key
, NULL
, NULL
, NULL
, &managed_count
, NULL
, NULL
,
1366 NULL
, NULL
, NULL
, NULL
, NULL
);
1367 if( r
!= ERROR_SUCCESS
) goto failed
;
1369 if (managed_count
&& index
<= machine_count
+ managed_count
)
1371 r
= RegEnumKeyW(key
, index
- machine_count
, szKeyName
, SQUISH_GUID_SIZE
);
1372 if( r
== ERROR_SUCCESS
)
1374 unsquash_guid(szKeyName
, lpguid
);
1377 return ERROR_SUCCESS
;
1383 r
= RegCreateKeyW(HKEY_CURRENT_USER
, szUserProduct
, &key
);
1384 if( r
!= ERROR_SUCCESS
) goto failed
;
1386 r
= RegQueryInfoKeyW(key
, NULL
, NULL
, NULL
, &unmanaged_count
, NULL
, NULL
,
1387 NULL
, NULL
, NULL
, NULL
, NULL
);
1388 if( r
!= ERROR_SUCCESS
) goto failed
;
1390 if (unmanaged_count
&& index
<= machine_count
+ managed_count
+ unmanaged_count
)
1392 r
= RegEnumKeyW(key
, index
- machine_count
- managed_count
, szKeyName
, SQUISH_GUID_SIZE
);
1393 if( r
== ERROR_SUCCESS
)
1395 unsquash_guid(szKeyName
, lpguid
);
1398 return ERROR_SUCCESS
;
1404 return ERROR_NO_MORE_ITEMS
;
1407 UINT WINAPI
MsiEnumFeaturesA(LPCSTR szProduct
, DWORD index
,
1408 LPSTR szFeature
, LPSTR szParent
)
1411 WCHAR szwFeature
[GUID_SIZE
], szwParent
[GUID_SIZE
];
1412 LPWSTR szwProduct
= NULL
;
1414 TRACE("%s %d %p %p\n", debugstr_a(szProduct
), index
, szFeature
, szParent
);
1418 szwProduct
= strdupAtoW( szProduct
);
1420 return ERROR_OUTOFMEMORY
;
1423 r
= MsiEnumFeaturesW(szwProduct
, index
, szwFeature
, szwParent
);
1424 if( r
== ERROR_SUCCESS
)
1426 WideCharToMultiByte(CP_ACP
, 0, szwFeature
, -1,
1427 szFeature
, GUID_SIZE
, NULL
, NULL
);
1428 WideCharToMultiByte(CP_ACP
, 0, szwParent
, -1,
1429 szParent
, GUID_SIZE
, NULL
, NULL
);
1432 msi_free( szwProduct
);
1437 UINT WINAPI
MsiEnumFeaturesW(LPCWSTR szProduct
, DWORD index
,
1438 LPWSTR szFeature
, LPWSTR szParent
)
1440 HKEY hkeyProduct
= 0;
1443 TRACE("%s %d %p %p\n", debugstr_w(szProduct
), index
, szFeature
, szParent
);
1446 return ERROR_INVALID_PARAMETER
;
1448 r
= MSIREG_OpenInstallerFeaturesKey(szProduct
,&hkeyProduct
,FALSE
);
1449 if( r
!= ERROR_SUCCESS
)
1450 return ERROR_NO_MORE_ITEMS
;
1453 r
= RegEnumValueW(hkeyProduct
, index
, szFeature
, &sz
, NULL
, NULL
, NULL
, NULL
);
1454 RegCloseKey(hkeyProduct
);
1459 UINT WINAPI
MsiEnumComponentsA(DWORD index
, LPSTR lpguid
)
1462 WCHAR szwGuid
[GUID_SIZE
];
1464 TRACE("%d %p\n", index
, lpguid
);
1466 r
= MsiEnumComponentsW(index
, szwGuid
);
1467 if( r
== ERROR_SUCCESS
)
1468 WideCharToMultiByte(CP_ACP
, 0, szwGuid
, -1, lpguid
, GUID_SIZE
, NULL
, NULL
);
1473 UINT WINAPI
MsiEnumComponentsW(DWORD index
, LPWSTR lpguid
)
1475 HKEY hkeyComponents
= 0;
1477 WCHAR szKeyName
[SQUISH_GUID_SIZE
];
1479 TRACE("%d %p\n", index
, lpguid
);
1481 r
= RegCreateKeyW(HKEY_LOCAL_MACHINE
, szInstaller_Components
, &hkeyComponents
);
1482 if( r
!= ERROR_SUCCESS
)
1483 return ERROR_NO_MORE_ITEMS
;
1485 r
= RegEnumKeyW(hkeyComponents
, index
, szKeyName
, SQUISH_GUID_SIZE
);
1486 if( r
== ERROR_SUCCESS
)
1487 unsquash_guid(szKeyName
, lpguid
);
1488 RegCloseKey(hkeyComponents
);
1493 UINT WINAPI
MsiEnumClientsA(LPCSTR szComponent
, DWORD index
, LPSTR szProduct
)
1496 WCHAR szwProduct
[GUID_SIZE
];
1497 LPWSTR szwComponent
= NULL
;
1499 TRACE("%s %d %p\n", debugstr_a(szComponent
), index
, szProduct
);
1502 return ERROR_INVALID_PARAMETER
;
1506 szwComponent
= strdupAtoW( szComponent
);
1508 return ERROR_OUTOFMEMORY
;
1511 r
= MsiEnumClientsW(szComponent
?szwComponent
:NULL
, index
, szwProduct
);
1512 if( r
== ERROR_SUCCESS
)
1514 WideCharToMultiByte(CP_ACP
, 0, szwProduct
, -1,
1515 szProduct
, GUID_SIZE
, NULL
, NULL
);
1518 msi_free( szwComponent
);
1523 UINT WINAPI
MsiEnumClientsW(LPCWSTR szComponent
, DWORD index
, LPWSTR szProduct
)
1527 WCHAR szValName
[SQUISH_GUID_SIZE
];
1529 TRACE("%s %d %p\n", debugstr_w(szComponent
), index
, szProduct
);
1531 if (!szComponent
|| !*szComponent
|| !szProduct
)
1532 return ERROR_INVALID_PARAMETER
;
1534 if (MSIREG_OpenUserDataComponentKey(szComponent
, NULL
, &hkeyComp
, FALSE
) != ERROR_SUCCESS
&&
1535 MSIREG_OpenUserDataComponentKey(szComponent
, szLocalSid
, &hkeyComp
, FALSE
) != ERROR_SUCCESS
)
1536 return ERROR_UNKNOWN_COMPONENT
;
1538 /* see if there are any products at all */
1539 sz
= SQUISH_GUID_SIZE
;
1540 r
= RegEnumValueW(hkeyComp
, 0, szValName
, &sz
, NULL
, NULL
, NULL
, NULL
);
1541 if (r
!= ERROR_SUCCESS
)
1543 RegCloseKey(hkeyComp
);
1546 return ERROR_INVALID_PARAMETER
;
1548 return ERROR_UNKNOWN_COMPONENT
;
1551 sz
= SQUISH_GUID_SIZE
;
1552 r
= RegEnumValueW(hkeyComp
, index
, szValName
, &sz
, NULL
, NULL
, NULL
, NULL
);
1553 if( r
== ERROR_SUCCESS
)
1554 unsquash_guid(szValName
, szProduct
);
1556 RegCloseKey(hkeyComp
);
1561 static UINT
MSI_EnumComponentQualifiers( LPCWSTR szComponent
, DWORD iIndex
,
1562 awstring
*lpQualBuf
, LPDWORD pcchQual
,
1563 awstring
*lpAppBuf
, LPDWORD pcchAppBuf
)
1565 DWORD name_sz
, val_sz
, name_max
, val_max
, type
, ofs
;
1566 LPWSTR name
= NULL
, val
= NULL
;
1570 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent
), iIndex
,
1571 lpQualBuf
, pcchQual
, lpAppBuf
, pcchAppBuf
);
1574 return ERROR_INVALID_PARAMETER
;
1576 r
= MSIREG_OpenUserComponentsKey( szComponent
, &key
, FALSE
);
1577 if (r
!= ERROR_SUCCESS
)
1578 return ERROR_UNKNOWN_COMPONENT
;
1580 /* figure out how big the name is we want to return */
1582 r
= ERROR_OUTOFMEMORY
;
1583 name
= msi_alloc( name_max
* sizeof(WCHAR
) );
1588 r
= ERROR_OUTOFMEMORY
;
1589 val
= msi_alloc( val_max
);
1593 /* loop until we allocate enough memory */
1598 r
= RegEnumValueW( key
, iIndex
, name
, &name_sz
,
1599 NULL
, &type
, (LPBYTE
)val
, &val_sz
);
1600 if (r
== ERROR_SUCCESS
)
1602 if (r
!= ERROR_MORE_DATA
)
1605 if (type
!= REG_MULTI_SZ
)
1607 ERR("component data has wrong type (%d)\n", type
);
1611 r
= ERROR_OUTOFMEMORY
;
1612 if ((name_sz
+1) >= name_max
)
1616 name
= msi_alloc( name_max
* sizeof (WCHAR
) );
1621 if (val_sz
> val_max
)
1623 val_max
= val_sz
+ sizeof (WCHAR
);
1625 val
= msi_alloc( val_max
* sizeof (WCHAR
) );
1630 ERR("should be enough data, but isn't %d %d\n", name_sz
, val_sz
);
1635 r
= MsiDecomposeDescriptorW( val
, NULL
, NULL
, NULL
, &ofs
);
1636 if (r
!= ERROR_SUCCESS
)
1639 TRACE("Providing %s and %s\n", debugstr_w(name
), debugstr_w(val
+ofs
));
1641 r
= msi_strcpy_to_awstring( name
, lpQualBuf
, pcchQual
);
1642 r2
= msi_strcpy_to_awstring( val
+ofs
, lpAppBuf
, pcchAppBuf
);
1644 if (r2
!= ERROR_SUCCESS
)
1655 /*************************************************************************
1656 * MsiEnumComponentQualifiersA [MSI.@]
1658 UINT WINAPI
MsiEnumComponentQualifiersA( LPCSTR szComponent
, DWORD iIndex
,
1659 LPSTR lpQualifierBuf
, LPDWORD pcchQualifierBuf
,
1660 LPSTR lpApplicationDataBuf
, LPDWORD pcchApplicationDataBuf
)
1662 awstring qual
, appdata
;
1666 TRACE("%s %08x %p %p %p %p\n", debugstr_a(szComponent
), iIndex
,
1667 lpQualifierBuf
, pcchQualifierBuf
, lpApplicationDataBuf
,
1668 pcchApplicationDataBuf
);
1670 comp
= strdupAtoW( szComponent
);
1671 if (szComponent
&& !comp
)
1672 return ERROR_OUTOFMEMORY
;
1674 qual
.unicode
= FALSE
;
1675 qual
.str
.a
= lpQualifierBuf
;
1677 appdata
.unicode
= FALSE
;
1678 appdata
.str
.a
= lpApplicationDataBuf
;
1680 r
= MSI_EnumComponentQualifiers( comp
, iIndex
,
1681 &qual
, pcchQualifierBuf
, &appdata
, pcchApplicationDataBuf
);
1686 /*************************************************************************
1687 * MsiEnumComponentQualifiersW [MSI.@]
1689 UINT WINAPI
MsiEnumComponentQualifiersW( LPCWSTR szComponent
, DWORD iIndex
,
1690 LPWSTR lpQualifierBuf
, LPDWORD pcchQualifierBuf
,
1691 LPWSTR lpApplicationDataBuf
, LPDWORD pcchApplicationDataBuf
)
1693 awstring qual
, appdata
;
1695 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent
), iIndex
,
1696 lpQualifierBuf
, pcchQualifierBuf
, lpApplicationDataBuf
,
1697 pcchApplicationDataBuf
);
1699 qual
.unicode
= TRUE
;
1700 qual
.str
.w
= lpQualifierBuf
;
1702 appdata
.unicode
= TRUE
;
1703 appdata
.str
.w
= lpApplicationDataBuf
;
1705 return MSI_EnumComponentQualifiers( szComponent
, iIndex
,
1706 &qual
, pcchQualifierBuf
, &appdata
, pcchApplicationDataBuf
);
1709 /*************************************************************************
1710 * MsiEnumRelatedProductsW [MSI.@]
1713 UINT WINAPI
MsiEnumRelatedProductsW(LPCWSTR szUpgradeCode
, DWORD dwReserved
,
1714 DWORD iProductIndex
, LPWSTR lpProductBuf
)
1718 DWORD dwSize
= SQUISH_GUID_SIZE
;
1719 WCHAR szKeyName
[SQUISH_GUID_SIZE
];
1721 TRACE("%s %u %u %p\n", debugstr_w(szUpgradeCode
), dwReserved
,
1722 iProductIndex
, lpProductBuf
);
1724 if (NULL
== szUpgradeCode
)
1725 return ERROR_INVALID_PARAMETER
;
1726 if (NULL
== lpProductBuf
)
1727 return ERROR_INVALID_PARAMETER
;
1729 r
= MSIREG_OpenUpgradeCodesKey(szUpgradeCode
, &hkey
, FALSE
);
1730 if (r
!= ERROR_SUCCESS
)
1731 return ERROR_NO_MORE_ITEMS
;
1733 r
= RegEnumValueW(hkey
, iProductIndex
, szKeyName
, &dwSize
, NULL
, NULL
, NULL
, NULL
);
1734 if( r
== ERROR_SUCCESS
)
1735 unsquash_guid(szKeyName
, lpProductBuf
);
1741 /*************************************************************************
1742 * MsiEnumRelatedProductsA [MSI.@]
1745 UINT WINAPI
MsiEnumRelatedProductsA(LPCSTR szUpgradeCode
, DWORD dwReserved
,
1746 DWORD iProductIndex
, LPSTR lpProductBuf
)
1748 LPWSTR szwUpgradeCode
= NULL
;
1749 WCHAR productW
[GUID_SIZE
];
1752 TRACE("%s %u %u %p\n", debugstr_a(szUpgradeCode
), dwReserved
,
1753 iProductIndex
, lpProductBuf
);
1757 szwUpgradeCode
= strdupAtoW( szUpgradeCode
);
1758 if( !szwUpgradeCode
)
1759 return ERROR_OUTOFMEMORY
;
1762 r
= MsiEnumRelatedProductsW( szwUpgradeCode
, dwReserved
,
1763 iProductIndex
, productW
);
1764 if (r
== ERROR_SUCCESS
)
1766 WideCharToMultiByte( CP_ACP
, 0, productW
, GUID_SIZE
,
1767 lpProductBuf
, GUID_SIZE
, NULL
, NULL
);
1769 msi_free( szwUpgradeCode
);
1773 /***********************************************************************
1774 * MsiEnumPatchesExA [MSI.@]
1776 UINT WINAPI
MsiEnumPatchesExA(LPCSTR szProductCode
, LPCSTR szUserSid
,
1777 DWORD dwContext
, DWORD dwFilter
, DWORD dwIndex
, LPSTR szPatchCode
,
1778 LPSTR szTargetProductCode
, MSIINSTALLCONTEXT
*pdwTargetProductContext
,
1779 LPSTR szTargetUserSid
, LPDWORD pcchTargetUserSid
)
1781 LPWSTR prodcode
= NULL
;
1782 LPWSTR usersid
= NULL
;
1783 LPWSTR targsid
= NULL
;
1784 WCHAR patch
[GUID_SIZE
];
1785 WCHAR targprod
[GUID_SIZE
];
1789 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p, %p)\n",
1790 debugstr_a(szProductCode
), debugstr_a(szUserSid
), dwContext
, dwFilter
,
1791 dwIndex
, szPatchCode
, szTargetProductCode
, pdwTargetProductContext
,
1792 szTargetUserSid
, pcchTargetUserSid
);
1794 if (szTargetUserSid
&& !pcchTargetUserSid
)
1795 return ERROR_INVALID_PARAMETER
;
1797 if (szProductCode
) prodcode
= strdupAtoW(szProductCode
);
1798 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1800 r
= MsiEnumPatchesExW(prodcode
, usersid
, dwContext
, dwFilter
, dwIndex
,
1801 patch
, targprod
, pdwTargetProductContext
,
1803 if (r
!= ERROR_SUCCESS
)
1806 WideCharToMultiByte(CP_ACP
, 0, patch
, -1, szPatchCode
,
1807 GUID_SIZE
, NULL
, NULL
);
1808 WideCharToMultiByte(CP_ACP
, 0, targprod
, -1, szTargetProductCode
,
1809 GUID_SIZE
, NULL
, NULL
);
1811 if (!szTargetUserSid
)
1813 if (pcchTargetUserSid
)
1814 *pcchTargetUserSid
= len
;
1819 targsid
= msi_alloc(++len
* sizeof(WCHAR
));
1822 r
= ERROR_OUTOFMEMORY
;
1826 r
= MsiEnumPatchesExW(prodcode
, usersid
, dwContext
, dwFilter
, dwIndex
,
1827 patch
, targprod
, pdwTargetProductContext
,
1829 if (r
!= ERROR_SUCCESS
|| !szTargetUserSid
)
1832 WideCharToMultiByte(CP_ACP
, 0, targsid
, -1, szTargetUserSid
,
1833 *pcchTargetUserSid
, NULL
, NULL
);
1835 len
= lstrlenW(targsid
);
1836 if (*pcchTargetUserSid
< len
+ 1)
1838 r
= ERROR_MORE_DATA
;
1839 *pcchTargetUserSid
= len
* sizeof(WCHAR
);
1842 *pcchTargetUserSid
= len
;
1852 static UINT
msi_get_patch_state(LPCWSTR prodcode
, LPCWSTR usersid
,
1853 MSIINSTALLCONTEXT context
,
1854 LPWSTR patch
, MSIPATCHSTATE
*state
)
1856 DWORD type
, val
, size
;
1857 HKEY prod
, hkey
= 0;
1860 UINT r
= ERROR_NO_MORE_ITEMS
;
1862 *state
= MSIPATCHSTATE_INVALID
;
1864 r
= MSIREG_OpenUserDataProductKey(prodcode
, context
,
1865 usersid
, &prod
, FALSE
);
1866 if (r
!= ERROR_SUCCESS
)
1867 return ERROR_NO_MORE_ITEMS
;
1869 res
= RegOpenKeyExW(prod
, szPatches
, 0, KEY_READ
, &hkey
);
1870 if (res
!= ERROR_SUCCESS
)
1873 res
= RegOpenKeyExW(hkey
, patch
, 0, KEY_READ
, &udpatch
);
1874 if (res
!= ERROR_SUCCESS
)
1877 size
= sizeof(DWORD
);
1878 res
= RegGetValueW(udpatch
, NULL
, szState
, RRF_RT_DWORD
, &type
, &val
, &size
);
1879 if (res
!= ERROR_SUCCESS
||
1880 val
< MSIPATCHSTATE_APPLIED
|| val
> MSIPATCHSTATE_REGISTERED
)
1882 r
= ERROR_BAD_CONFIGURATION
;
1890 RegCloseKey(udpatch
);
1897 static UINT
msi_check_product_patches(LPCWSTR prodcode
, LPCWSTR usersid
,
1898 MSIINSTALLCONTEXT context
, DWORD filter
, DWORD index
, DWORD
*idx
,
1899 LPWSTR patch
, LPWSTR targetprod
, MSIINSTALLCONTEXT
*targetctx
,
1900 LPWSTR targetsid
, DWORD
*sidsize
, LPWSTR
*transforms
)
1902 MSIPATCHSTATE state
= MSIPATCHSTATE_INVALID
;
1903 LPWSTR ptr
, patches
= NULL
;
1904 HKEY prod
, patchkey
= 0;
1905 HKEY localprod
= 0, localpatch
= 0;
1908 UINT temp
, r
= ERROR_NO_MORE_ITEMS
;
1910 if (MSIREG_OpenProductKey(prodcode
, usersid
, context
,
1911 &prod
, FALSE
) != ERROR_SUCCESS
)
1912 return ERROR_NO_MORE_ITEMS
;
1915 res
= RegGetValueW(prod
, szPatches
, szPatches
, RRF_RT_ANY
, &type
, NULL
,
1917 if (res
!= ERROR_SUCCESS
)
1920 if (type
!= REG_MULTI_SZ
)
1922 r
= ERROR_BAD_CONFIGURATION
;
1926 patches
= msi_alloc(size
);
1929 r
= ERROR_OUTOFMEMORY
;
1933 res
= RegGetValueW(prod
, szPatches
, szPatches
, RRF_RT_ANY
, &type
,
1935 if (res
!= ERROR_SUCCESS
)
1939 for (ptr
= patches
; *ptr
&& r
== ERROR_NO_MORE_ITEMS
; ptr
+= lstrlenW(ptr
) + 1)
1941 if (!unsquash_guid(ptr
, patch
))
1943 r
= ERROR_BAD_CONFIGURATION
;
1948 res
= RegGetValueW(prod
, szPatches
, ptr
, RRF_RT_REG_SZ
,
1949 &type
, NULL
, &size
);
1950 if (res
!= ERROR_SUCCESS
)
1955 *transforms
= msi_alloc(size
);
1958 r
= ERROR_OUTOFMEMORY
;
1962 res
= RegGetValueW(prod
, szPatches
, ptr
, RRF_RT_REG_SZ
,
1963 &type
, *transforms
, &size
);
1964 if (res
!= ERROR_SUCCESS
)
1968 if (context
== MSIINSTALLCONTEXT_USERMANAGED
)
1970 if (!(filter
& MSIPATCHSTATE_APPLIED
))
1972 temp
= msi_get_patch_state(prodcode
, usersid
, context
,
1974 if (temp
== ERROR_BAD_CONFIGURATION
)
1976 r
= ERROR_BAD_CONFIGURATION
;
1980 if (temp
!= ERROR_SUCCESS
|| !(filter
& state
))
1984 else if (context
== MSIINSTALLCONTEXT_USERUNMANAGED
)
1986 if (!(filter
& MSIPATCHSTATE_APPLIED
))
1988 temp
= msi_get_patch_state(prodcode
, usersid
, context
,
1990 if (temp
== ERROR_BAD_CONFIGURATION
)
1992 r
= ERROR_BAD_CONFIGURATION
;
1996 if (temp
!= ERROR_SUCCESS
|| !(filter
& state
))
2001 temp
= MSIREG_OpenUserDataPatchKey(patch
, context
,
2003 RegCloseKey(patchkey
);
2004 if (temp
!= ERROR_SUCCESS
)
2008 else if (context
== MSIINSTALLCONTEXT_MACHINE
)
2012 if (MSIREG_OpenUserDataProductKey(prodcode
, context
, NULL
, &localprod
, FALSE
) == ERROR_SUCCESS
&&
2013 RegOpenKeyExW(localprod
, szPatches
, 0, KEY_READ
, &localpatch
) == ERROR_SUCCESS
&&
2014 RegOpenKeyExW(localpatch
, ptr
, 0, KEY_READ
, &patchkey
) == ERROR_SUCCESS
)
2016 res
= RegGetValueW(patchkey
, NULL
, szState
, RRF_RT_REG_DWORD
,
2017 &type
, &state
, &size
);
2019 if (!(filter
& state
))
2020 res
= ERROR_NO_MORE_ITEMS
;
2022 RegCloseKey(patchkey
);
2025 RegCloseKey(localpatch
);
2026 RegCloseKey(localprod
);
2028 if (res
!= ERROR_SUCCESS
)
2040 lstrcpyW(targetprod
, prodcode
);
2043 *targetctx
= context
;
2047 lstrcpynW(targetsid
, usersid
, *sidsize
);
2048 if (lstrlenW(usersid
) >= *sidsize
)
2049 r
= ERROR_MORE_DATA
;
2054 *sidsize
= lstrlenW(usersid
);
2056 *sidsize
*= sizeof(WCHAR
);
2067 static UINT
msi_enum_patches(LPCWSTR szProductCode
, LPCWSTR szUserSid
,
2068 DWORD dwContext
, DWORD dwFilter
, DWORD dwIndex
, DWORD
*idx
,
2069 LPWSTR szPatchCode
, LPWSTR szTargetProductCode
,
2070 MSIINSTALLCONTEXT
*pdwTargetProductContext
, LPWSTR szTargetUserSid
,
2071 LPDWORD pcchTargetUserSid
, LPWSTR
*szTransforms
)
2073 LPWSTR usersid
= NULL
;
2074 UINT r
= ERROR_INVALID_PARAMETER
;
2078 get_user_sid(&usersid
);
2079 szUserSid
= usersid
;
2082 if (dwContext
& MSIINSTALLCONTEXT_USERMANAGED
)
2084 r
= msi_check_product_patches(szProductCode
, szUserSid
,
2085 MSIINSTALLCONTEXT_USERMANAGED
, dwFilter
,
2086 dwIndex
, idx
, szPatchCode
,
2087 szTargetProductCode
,
2088 pdwTargetProductContext
, szTargetUserSid
,
2089 pcchTargetUserSid
, szTransforms
);
2090 if (r
!= ERROR_NO_MORE_ITEMS
)
2094 if (dwContext
& MSIINSTALLCONTEXT_USERUNMANAGED
)
2096 r
= msi_check_product_patches(szProductCode
, szUserSid
,
2097 MSIINSTALLCONTEXT_USERUNMANAGED
, dwFilter
,
2098 dwIndex
, idx
, szPatchCode
,
2099 szTargetProductCode
,
2100 pdwTargetProductContext
, szTargetUserSid
,
2101 pcchTargetUserSid
, szTransforms
);
2102 if (r
!= ERROR_NO_MORE_ITEMS
)
2106 if (dwContext
& MSIINSTALLCONTEXT_MACHINE
)
2108 r
= msi_check_product_patches(szProductCode
, szUserSid
,
2109 MSIINSTALLCONTEXT_MACHINE
, dwFilter
,
2110 dwIndex
, idx
, szPatchCode
,
2111 szTargetProductCode
,
2112 pdwTargetProductContext
, szTargetUserSid
,
2113 pcchTargetUserSid
, szTransforms
);
2114 if (r
!= ERROR_NO_MORE_ITEMS
)
2123 /***********************************************************************
2124 * MsiEnumPatchesExW [MSI.@]
2126 UINT WINAPI
MsiEnumPatchesExW(LPCWSTR szProductCode
, LPCWSTR szUserSid
,
2127 DWORD dwContext
, DWORD dwFilter
, DWORD dwIndex
, LPWSTR szPatchCode
,
2128 LPWSTR szTargetProductCode
, MSIINSTALLCONTEXT
*pdwTargetProductContext
,
2129 LPWSTR szTargetUserSid
, LPDWORD pcchTargetUserSid
)
2131 WCHAR squished_pc
[GUID_SIZE
];
2135 static DWORD last_index
;
2137 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p, %p)\n",
2138 debugstr_w(szProductCode
), debugstr_w(szUserSid
), dwContext
, dwFilter
,
2139 dwIndex
, szPatchCode
, szTargetProductCode
, pdwTargetProductContext
,
2140 szTargetUserSid
, pcchTargetUserSid
);
2142 if (!szProductCode
|| !squash_guid(szProductCode
, squished_pc
))
2143 return ERROR_INVALID_PARAMETER
;
2145 if (!lstrcmpW(szUserSid
, szLocalSid
))
2146 return ERROR_INVALID_PARAMETER
;
2148 if (dwContext
& MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
2149 return ERROR_INVALID_PARAMETER
;
2151 if (dwContext
<= MSIINSTALLCONTEXT_NONE
||
2152 dwContext
> MSIINSTALLCONTEXT_ALL
)
2153 return ERROR_INVALID_PARAMETER
;
2155 if (dwFilter
<= MSIPATCHSTATE_INVALID
|| dwFilter
> MSIPATCHSTATE_ALL
)
2156 return ERROR_INVALID_PARAMETER
;
2158 if (dwIndex
&& dwIndex
- last_index
!= 1)
2159 return ERROR_INVALID_PARAMETER
;
2164 r
= msi_enum_patches(szProductCode
, szUserSid
, dwContext
, dwFilter
,
2165 dwIndex
, &idx
, szPatchCode
, szTargetProductCode
,
2166 pdwTargetProductContext
, szTargetUserSid
,
2167 pcchTargetUserSid
, NULL
);
2169 if (r
== ERROR_SUCCESS
)
2170 last_index
= dwIndex
;
2177 /***********************************************************************
2178 * MsiEnumPatchesA [MSI.@]
2180 UINT WINAPI
MsiEnumPatchesA(LPCSTR szProduct
, DWORD iPatchIndex
,
2181 LPSTR lpPatchBuf
, LPSTR lpTransformsBuf
, LPDWORD pcchTransformsBuf
)
2183 LPWSTR product
, transforms
;
2184 WCHAR patch
[GUID_SIZE
];
2188 TRACE("(%s %d %p %p %p)\n", debugstr_a(szProduct
), iPatchIndex
,
2189 lpPatchBuf
, lpTransformsBuf
, pcchTransformsBuf
);
2191 if (!szProduct
|| !lpPatchBuf
|| !lpTransformsBuf
|| !pcchTransformsBuf
)
2192 return ERROR_INVALID_PARAMETER
;
2194 product
= strdupAtoW(szProduct
);
2196 return ERROR_OUTOFMEMORY
;
2198 len
= *pcchTransformsBuf
;
2199 transforms
= msi_alloc( len
* sizeof(WCHAR
) );
2202 r
= ERROR_OUTOFMEMORY
;
2206 r
= MsiEnumPatchesW(product
, iPatchIndex
, patch
, transforms
, &len
);
2207 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
2210 WideCharToMultiByte(CP_ACP
, 0, patch
, -1, lpPatchBuf
,
2211 GUID_SIZE
, NULL
, NULL
);
2213 if (!WideCharToMultiByte(CP_ACP
, 0, transforms
, -1, lpTransformsBuf
,
2214 *pcchTransformsBuf
, NULL
, NULL
))
2215 r
= ERROR_MORE_DATA
;
2217 if (r
== ERROR_MORE_DATA
)
2219 lpTransformsBuf
[*pcchTransformsBuf
- 1] = '\0';
2220 *pcchTransformsBuf
= len
* 2;
2223 *pcchTransformsBuf
= strlen( lpTransformsBuf
);
2226 msi_free(transforms
);
2232 /***********************************************************************
2233 * MsiEnumPatchesW [MSI.@]
2235 UINT WINAPI
MsiEnumPatchesW(LPCWSTR szProduct
, DWORD iPatchIndex
,
2236 LPWSTR lpPatchBuf
, LPWSTR lpTransformsBuf
, LPDWORD pcchTransformsBuf
)
2238 WCHAR squished_pc
[GUID_SIZE
];
2239 LPWSTR transforms
= NULL
;
2244 TRACE("(%s %d %p %p %p)\n", debugstr_w(szProduct
), iPatchIndex
,
2245 lpPatchBuf
, lpTransformsBuf
, pcchTransformsBuf
);
2247 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
2248 return ERROR_INVALID_PARAMETER
;
2250 if (!lpPatchBuf
|| !lpTransformsBuf
|| !pcchTransformsBuf
)
2251 return ERROR_INVALID_PARAMETER
;
2253 if (MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
,
2254 &prod
, FALSE
) != ERROR_SUCCESS
&&
2255 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
2256 &prod
, FALSE
) != ERROR_SUCCESS
&&
2257 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
2258 &prod
, FALSE
) != ERROR_SUCCESS
)
2259 return ERROR_UNKNOWN_PRODUCT
;
2263 r
= msi_enum_patches(szProduct
, NULL
, MSIINSTALLCONTEXT_ALL
,
2264 MSIPATCHSTATE_ALL
, iPatchIndex
, &idx
, lpPatchBuf
,
2265 NULL
, NULL
, NULL
, NULL
, &transforms
);
2266 if (r
!= ERROR_SUCCESS
)
2269 lstrcpynW(lpTransformsBuf
, transforms
, *pcchTransformsBuf
);
2270 if (*pcchTransformsBuf
<= lstrlenW(transforms
))
2272 r
= ERROR_MORE_DATA
;
2273 *pcchTransformsBuf
= lstrlenW(transforms
);
2276 *pcchTransformsBuf
= lstrlenW(transforms
);
2279 msi_free(transforms
);
2283 UINT WINAPI
MsiEnumProductsExA( LPCSTR szProductCode
, LPCSTR szUserSid
,
2284 DWORD dwContext
, DWORD dwIndex
, CHAR szInstalledProductCode
[39],
2285 MSIINSTALLCONTEXT
* pdwInstalledContext
, LPSTR szSid
, LPDWORD pcchSid
)
2287 FIXME("%s %s %d %d %p %p %p %p\n", debugstr_a(szProductCode
), debugstr_a(szUserSid
),
2288 dwContext
, dwIndex
, szInstalledProductCode
, pdwInstalledContext
,
2290 return ERROR_NO_MORE_ITEMS
;
2293 UINT WINAPI
MsiEnumProductsExW( LPCWSTR szProductCode
, LPCWSTR szUserSid
,
2294 DWORD dwContext
, DWORD dwIndex
, WCHAR szInstalledProductCode
[39],
2295 MSIINSTALLCONTEXT
* pdwInstalledContext
, LPWSTR szSid
, LPDWORD pcchSid
)
2297 FIXME("%s %s %d %d %p %p %p %p\n", debugstr_w(szProductCode
), debugstr_w(szUserSid
),
2298 dwContext
, dwIndex
, szInstalledProductCode
, pdwInstalledContext
,
2300 return ERROR_NO_MORE_ITEMS
;