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
31 #include "wine/debug.h"
35 #include "wine/unicode.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
43 * This module will be all the helper functions for registry access by the
47 static const WCHAR szUserDataFeatures_fmt
[] = {
48 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
49 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
50 'I','n','s','t','a','l','l','e','r','\\','U','s','e','r','D','a','t','a','\\',
51 '%','s','\\','P','r','o','d','u','c','t','s','\\','%','s','\\','F','e','a','t','u','r','e','s',0};
53 static const WCHAR szUserDataComp_fmt
[] = {
54 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
55 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
56 'I','n','s','t','a','l','l','e','r','\\','U','s','e','r','D','a','t','a','\\',
57 '%','s','\\','C','o','m','p','o','n','e','n','t','s','\\','%','s',0};
59 static const WCHAR szUserDataComponents_fmt
[] = {
60 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
61 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
62 'I','n','s','t','a','l','l','e','r','\\','U','s','e','r','D','a','t','a','\\',
63 '%','s','\\','C','o','m','p','o','n','e','n','t','s',0};
65 static const WCHAR szUserDataProd_fmt
[] = {
66 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
67 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
68 'I','n','s','t','a','l','l','e','r','\\','U','s','e','r','D','a','t','a','\\',
69 '%','s','\\','P','r','o','d','u','c','t','s','\\','%','s',0};
71 static const WCHAR szUserDataProducts_fmt
[] = {
72 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
73 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
74 'I','n','s','t','a','l','l','e','r','\\','U','s','e','r','D','a','t','a','\\',
75 '%','s','\\','P','r','o','d','u','c','t','s',0};
77 static const WCHAR szUserDataPatch_fmt
[] = {
78 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
79 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
80 'I','n','s','t','a','l','l','e','r','\\','U','s','e','r','D','a','t','a','\\',
81 '%','s','\\','P','a','t','c','h','e','s','\\','%','s',0};
83 static const WCHAR szUserDataPatches_fmt
[] = {
84 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
85 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
86 'I','n','s','t','a','l','l','e','r','\\','U','s','e','r','D','a','t','a','\\',
87 '%','s','\\','P','a','t','c','h','e','s',0};
89 static const WCHAR szUserDataProductPatches_fmt
[] = {
90 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
91 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
92 'I','n','s','t','a','l','l','e','r','\\','U','s','e','r','D','a','t','a','\\',
93 '%','s','\\','P','r','o','d','u','c','t','s','\\','%','s','\\','P','a','t','c','h','e','s',0};
95 static const WCHAR szInstallProperties_fmt
[] = {
96 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
97 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
98 'I','n','s','t','a','l','l','e','r','\\','U','s','e','r','D','a','t','a','\\',
99 '%','s','\\','P','r','o','d','u','c','t','s','\\','%','s','\\',
100 'I','n','s','t','a','l','l','P','r','o','p','e','r','t','i','e','s',0};
102 static const WCHAR szInstaller_LocalManagedProd_fmt
[] = {
103 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
104 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
105 'I','n','s','t','a','l','l','e','r','\\','M','a','n','a','g','e','d','\\','%','s','\\',
106 'I','n','s','t','a','l','l','e','r','\\','P','r','o','d','u','c','t','s','\\','%','s',0};
108 static const WCHAR szInstaller_LocalManagedFeat_fmt
[] = {
109 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
110 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
111 'I','n','s','t','a','l','l','e','r','\\','M','a','n','a','g','e','d','\\','%','s','\\',
112 'I','n','s','t','a','l','l','e','r','\\','F','e','a','t','u','r','e','s','\\','%','s',0};
114 static const WCHAR szInstaller_Products
[] = {
115 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
116 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
117 'I','n','s','t','a','l','l','e','r','\\','P','r','o','d','u','c','t','s',0};
119 static const WCHAR szInstaller_Patches
[] = {
120 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
121 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
122 'I','n','s','t','a','l','l','e','r','\\','P','a','t','c','h','e','s',0};
124 static const WCHAR szInstaller_LocalClassesProducts
[] = {
125 'S','o','f','t','w','a','r','e','\\','C','l','a','s','s','e','s','\\',
126 'I','n','s','t','a','l','l','e','r','\\','P','r','o','d','u','c','t','s',0};
128 static const WCHAR szInstaller_LocalClassesFeatures
[] = {
129 'S','o','f','t','w','a','r','e','\\','C','l','a','s','s','e','s','\\',
130 'I','n','s','t','a','l','l','e','r','\\','F','e','a','t','u','r','e','s',0};
132 static const WCHAR szInstaller_LocalClassesProd
[] = {
133 'S','o','f','t','w','a','r','e','\\','C','l','a','s','s','e','s','\\',
134 'I','n','s','t','a','l','l','e','r','\\','P','r','o','d','u','c','t','s','\\',0};
136 static const WCHAR szInstaller_LocalClassesFeat
[] = {
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','\\','F','e','a','t','u','r','e','s','\\',0};
140 static const WCHAR szInstaller_ClassesUpgradeCode
[] = {
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','\\','U','p','g','r','a','d','e','C','o','d','e','s','\\',0};
144 static const WCHAR szInstaller_ClassesUpgradeCodes
[] = {
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','\\','U','p','g','r','a','d','e','C','o','d','e','s',0};
148 static const WCHAR szInstaller_Features
[] = {
149 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
150 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
151 'I','n','s','t','a','l','l','e','r','\\','F','e','a','t','u','r','e','s','\\',0};
153 static const WCHAR szInstaller_UpgradeCodes
[] = {
154 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
155 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
156 'I','n','s','t','a','l','l','e','r','\\','U','p','g','r','a','d','e','C','o','d','e','s','\\',0};
158 static const WCHAR szInstaller_UserUpgradeCodes
[] = {
159 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
160 'I','n','s','t','a','l','l','e','r','\\','U','p','g','r','a','d','e','C','o','d','e','s','\\',0};
162 static const WCHAR szUninstall
[] = {
163 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
164 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
165 'U','n','i','n','s','t','a','l','l','\\',0};
167 static const WCHAR szUninstall_32node
[] = {
168 'S','o','f','t','w','a','r','e','\\','W','o','w','6','4','3','2','N','o','d','e','\\',
169 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
170 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','U','n','i','n','s','t','a','l','l','\\',0};
172 static const WCHAR szUserComponents
[] = {
173 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
174 'I','n','s','t','a','l','l','e','r','\\','C','o','m','p','o','n','e','n','t','s','\\',0};
176 static const WCHAR szInstaller_Components
[] = {
177 'S','o','f','t','w','a','r','e','\\','C','l','a','s','s','e','s','\\',
178 'I','n','s','t','a','l','l','e','r','\\','C','o','m','p','o','n','e','n','t','s','\\',0};
180 static const WCHAR szUserFeatures
[] = {
181 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
182 'I','n','s','t','a','l','l','e','r','\\','F','e','a','t','u','r','e','s','\\',0};
184 static const WCHAR szUserProducts
[] = {
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','\\','P','r','o','d','u','c','t','s','\\',0};
188 static const WCHAR szUserPatches
[] = {
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','\\','P','a','t','c','h','e','s','\\',0};
192 BOOL
unsquash_guid(LPCWSTR in
, LPWSTR out
)
196 if (lstrlenW(in
) != 32)
211 out
[n
++] = in
[17+i
*2];
212 out
[n
++] = in
[16+i
*2];
217 out
[n
++] = in
[17+i
*2];
218 out
[n
++] = in
[16+i
*2];
225 BOOL
squash_guid(LPCWSTR in
, LPWSTR out
)
232 if (FAILED(CLSIDFromString((LPCOLESTR
)in
, &guid
)))
246 out
[17+i
*2] = in
[n
++];
247 out
[16+i
*2] = in
[n
++];
252 out
[17+i
*2] = in
[n
++];
253 out
[16+i
*2] = in
[n
++];
260 /* tables for encoding and decoding base85 */
261 static const unsigned char table_dec85
[0x80] = {
262 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
263 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
264 0xff,0x00,0xff,0xff,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0xff,
265 0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0xff,0xff,0xff,0x16,0xff,0x17,
266 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,
267 0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0xff,0x34,0x35,0x36,
268 0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44,0x45,0x46,
269 0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0xff,0x53,0x54,0xff,
272 static const char table_enc85
[] =
273 "!$%&'()*+,-.0123456789=?@ABCDEFGHIJKLMNO"
274 "PQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwx"
278 * Converts a base85 encoded guid into a GUID pointer
279 * Base85 encoded GUIDs should be 20 characters long.
281 * returns TRUE if successful, FALSE if not
283 BOOL
decode_base85_guid( LPCWSTR str
, GUID
*guid
)
285 DWORD i
, val
= 0, base
= 1, *p
;
291 for( i
=0; i
<20; i
++ )
298 val
+= table_dec85
[str
[i
]] * base
;
301 if( table_dec85
[str
[i
]] == 0xff )
311 * Encodes a base85 guid given a GUID pointer
312 * Caller should provide a 21 character buffer for the encoded string.
314 * returns TRUE if successful, FALSE if not
316 BOOL
encode_base85_guid( GUID
*guid
, LPWSTR str
)
318 unsigned int x
, *p
, i
;
320 p
= (unsigned int*) guid
;
324 *str
++ = table_enc85
[x
%85];
326 *str
++ = table_enc85
[x
%85];
328 *str
++ = table_enc85
[x
%85];
330 *str
++ = table_enc85
[x
%85];
332 *str
++ = table_enc85
[x
%85];
339 DWORD
msi_version_str_to_dword(LPCWSTR p
)
341 DWORD major
, minor
= 0, build
= 0, version
= 0;
352 p
= strchrW(p
+1, '.');
357 return MAKELONG(build
, MAKEWORD(minor
, major
));
360 LONG
msi_reg_set_val_str( HKEY hkey
, LPCWSTR name
, LPCWSTR value
)
363 if (!value
) value
= szEmpty
;
364 len
= (lstrlenW(value
) + 1) * sizeof (WCHAR
);
365 return RegSetValueExW( hkey
, name
, 0, REG_SZ
, (const BYTE
*)value
, len
);
368 LONG
msi_reg_set_val_multi_str( HKEY hkey
, LPCWSTR name
, LPCWSTR value
)
371 while (*p
) p
+= lstrlenW(p
) + 1;
372 return RegSetValueExW( hkey
, name
, 0, REG_MULTI_SZ
,
373 (const BYTE
*)value
, (p
+ 1 - value
) * sizeof(WCHAR
) );
376 LONG
msi_reg_set_val_dword( HKEY hkey
, LPCWSTR name
, DWORD val
)
378 return RegSetValueExW( hkey
, name
, 0, REG_DWORD
, (LPBYTE
)&val
, sizeof (DWORD
) );
381 LONG
msi_reg_set_subkey_val( HKEY hkey
, LPCWSTR path
, LPCWSTR name
, LPCWSTR val
)
386 r
= RegCreateKeyW( hkey
, path
, &hsubkey
);
387 if (r
!= ERROR_SUCCESS
)
389 r
= msi_reg_set_val_str( hsubkey
, name
, val
);
390 RegCloseKey( hsubkey
);
394 LPWSTR
msi_reg_get_val_str( HKEY hkey
, LPCWSTR name
)
400 r
= RegQueryValueExW(hkey
, name
, NULL
, NULL
, NULL
, &len
);
401 if (r
!= ERROR_SUCCESS
)
404 len
+= sizeof (WCHAR
);
405 val
= msi_alloc( len
);
409 RegQueryValueExW(hkey
, name
, NULL
, NULL
, (LPBYTE
) val
, &len
);
413 BOOL
msi_reg_get_val_dword( HKEY hkey
, LPCWSTR name
, DWORD
*val
)
415 DWORD type
, len
= sizeof (DWORD
);
416 LONG r
= RegQueryValueExW(hkey
, name
, NULL
, &type
, (LPBYTE
) val
, &len
);
417 return r
== ERROR_SUCCESS
&& type
== REG_DWORD
;
420 static WCHAR
*get_user_sid(void)
427 if (!OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY
, &token
)) return NULL
;
428 if (!(user
= msi_alloc( size
)))
430 CloseHandle( token
);
433 if (!GetTokenInformation( token
, TokenUser
, user
, size
, &size
))
436 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
|| !(user
= msi_alloc( size
)))
438 CloseHandle( token
);
441 GetTokenInformation( token
, TokenUser
, user
, size
, &size
);
443 CloseHandle( token
);
444 if (!ConvertSidToStringSidW( user
->User
.Sid
, &ret
))
453 UINT
MSIREG_OpenUninstallKey(const WCHAR
*product
, enum platform platform
, HKEY
*key
, BOOL create
)
455 WCHAR keypath
[0x200];
457 TRACE("%s\n", debugstr_w(product
));
459 if (is_64bit
&& platform
== PLATFORM_INTEL
)
461 strcpyW(keypath
, szUninstall_32node
);
462 strcatW(keypath
, product
);
466 strcpyW(keypath
, szUninstall
);
467 strcatW(keypath
, product
);
469 if (create
) return RegCreateKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, key
, NULL
);
470 return RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, KEY_ALL_ACCESS
, key
);
473 UINT
MSIREG_DeleteUninstallKey(const WCHAR
*product
, enum platform platform
)
475 WCHAR keypath
[0x200];
477 TRACE("%s\n", debugstr_w(product
));
479 if (is_64bit
&& platform
== PLATFORM_INTEL
)
481 strcpyW(keypath
, szUninstall_32node
);
482 strcatW(keypath
, product
);
486 strcpyW(keypath
, szUninstall
);
487 strcatW(keypath
, product
);
489 return RegDeleteTreeW(HKEY_LOCAL_MACHINE
, keypath
);
492 UINT
MSIREG_OpenProductKey(LPCWSTR szProduct
, LPCWSTR szUserSid
, MSIINSTALLCONTEXT context
, HKEY
*key
, BOOL create
)
494 LPWSTR usersid
= NULL
;
495 HKEY root
= HKEY_LOCAL_MACHINE
;
496 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
497 WCHAR squished_pc
[GUID_SIZE
], keypath
[MAX_PATH
];
499 if (!squash_guid(szProduct
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
500 TRACE("%s squished %s\n", debugstr_w(szProduct
), debugstr_w(squished_pc
));
502 if (context
== MSIINSTALLCONTEXT_MACHINE
)
504 strcpyW(keypath
, szInstaller_LocalClassesProd
);
505 strcatW(keypath
, squished_pc
);
507 else if (context
== MSIINSTALLCONTEXT_USERUNMANAGED
)
509 root
= HKEY_CURRENT_USER
;
510 strcpyW(keypath
, szUserProducts
);
511 strcatW(keypath
, squished_pc
);
517 if (!(usersid
= get_user_sid()))
519 ERR("Failed to retrieve user SID\n");
520 return ERROR_FUNCTION_FAILED
;
524 sprintfW(keypath
, szInstaller_LocalManagedProd_fmt
, szUserSid
, squished_pc
);
527 if (create
) return RegCreateKeyExW(root
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
528 return RegOpenKeyExW(root
, keypath
, 0, access
, key
);
531 UINT
MSIREG_DeleteUserProductKey(LPCWSTR szProduct
)
533 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
535 if (!squash_guid(szProduct
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
536 TRACE("%s squished %s\n", debugstr_w(szProduct
), debugstr_w(squished_pc
));
538 strcpyW(keypath
, szUserProducts
);
539 strcatW(keypath
, squished_pc
);
540 return RegDeleteTreeW(HKEY_CURRENT_USER
, keypath
);
543 UINT
MSIREG_OpenUserPatchesKey(LPCWSTR szPatch
, HKEY
*key
, BOOL create
)
545 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
547 if (!squash_guid(szPatch
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
548 TRACE("%s squished %s\n", debugstr_w(szPatch
), debugstr_w(squished_pc
));
550 strcpyW(keypath
, szUserPatches
);
551 strcatW(keypath
, squished_pc
);
553 if (create
) return RegCreateKeyW(HKEY_CURRENT_USER
, keypath
, key
);
554 return RegOpenKeyW(HKEY_CURRENT_USER
, keypath
, key
);
557 UINT
MSIREG_OpenFeaturesKey(LPCWSTR szProduct
, LPCWSTR szUserSid
, MSIINSTALLCONTEXT context
,
558 HKEY
*key
, BOOL create
)
560 HKEY root
= HKEY_LOCAL_MACHINE
;
561 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
562 WCHAR squished_pc
[GUID_SIZE
], keypath
[MAX_PATH
], *usersid
= NULL
;
564 if (!squash_guid(szProduct
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
565 TRACE("%s squished %s\n", debugstr_w(szProduct
), debugstr_w(squished_pc
));
567 if (context
== MSIINSTALLCONTEXT_MACHINE
)
569 strcpyW(keypath
, szInstaller_LocalClassesFeat
);
570 strcatW(keypath
, squished_pc
);
572 else if (context
== MSIINSTALLCONTEXT_USERUNMANAGED
)
574 root
= HKEY_CURRENT_USER
;
575 strcpyW(keypath
, szUserFeatures
);
576 strcatW(keypath
, squished_pc
);
582 if (!(usersid
= get_user_sid()))
584 ERR("Failed to retrieve user SID\n");
585 return ERROR_FUNCTION_FAILED
;
589 sprintfW(keypath
, szInstaller_LocalManagedFeat_fmt
, szUserSid
, squished_pc
);
592 if (create
) return RegCreateKeyExW(root
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
593 return RegOpenKeyExW(root
, keypath
, 0, access
, key
);
596 UINT
MSIREG_DeleteUserFeaturesKey(LPCWSTR szProduct
)
598 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
600 if (!squash_guid(szProduct
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
601 TRACE("%s squished %s\n", debugstr_w(szProduct
), debugstr_w(squished_pc
));
603 strcpyW(keypath
, szUserFeatures
);
604 strcatW(keypath
, squished_pc
);
605 return RegDeleteTreeW(HKEY_CURRENT_USER
, keypath
);
608 static UINT
MSIREG_OpenInstallerFeaturesKey(LPCWSTR szProduct
, HKEY
*key
, BOOL create
)
610 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
611 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
613 if (!squash_guid(szProduct
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
614 TRACE("%s squished %s\n", debugstr_w(szProduct
), debugstr_w(squished_pc
));
616 strcpyW(keypath
, szInstaller_Features
);
617 strcatW(keypath
, squished_pc
);
619 if (create
) return RegCreateKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
620 return RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, key
);
623 UINT
MSIREG_OpenUserDataFeaturesKey(LPCWSTR szProduct
, LPCWSTR szUserSid
, MSIINSTALLCONTEXT context
,
624 HKEY
*key
, BOOL create
)
626 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
627 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200], *usersid
= NULL
;
629 if (!squash_guid(szProduct
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
630 TRACE("%s squished %s\n", debugstr_w(szProduct
), debugstr_w(squished_pc
));
632 if (context
== MSIINSTALLCONTEXT_MACHINE
)
634 sprintfW(keypath
, szUserDataFeatures_fmt
, szLocalSid
, squished_pc
);
640 if (!(usersid
= get_user_sid()))
642 ERR("Failed to retrieve user SID\n");
643 return ERROR_FUNCTION_FAILED
;
647 sprintfW(keypath
, szUserDataFeatures_fmt
, szUserSid
, 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];
659 if (!squash_guid(szComponent
, squished_cc
)) return ERROR_FUNCTION_FAILED
;
660 TRACE("%s squished %s\n", debugstr_w(szComponent
), debugstr_w(squished_cc
));
662 strcpyW(keypath
, szUserComponents
);
663 strcatW(keypath
, squished_cc
);
665 if (create
) return RegCreateKeyW(HKEY_CURRENT_USER
, keypath
, key
);
666 ret
= RegOpenKeyW(HKEY_CURRENT_USER
, keypath
, key
);
667 if (ret
!= ERROR_FILE_NOT_FOUND
) return ret
;
669 strcpyW(keypath
, szInstaller_Components
);
670 strcatW(keypath
, squished_cc
);
671 return RegOpenKeyW(HKEY_LOCAL_MACHINE
, keypath
, key
);
674 UINT
MSIREG_OpenUserDataComponentKey(LPCWSTR szComponent
, LPCWSTR szUserSid
, HKEY
*key
, BOOL create
)
676 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
677 WCHAR comp
[GUID_SIZE
], keypath
[0x200];
680 if (!squash_guid(szComponent
, comp
)) return ERROR_FUNCTION_FAILED
;
681 TRACE("%s squished %s\n", debugstr_w(szComponent
), debugstr_w(comp
));
685 if (!(usersid
= get_user_sid()))
687 ERR("Failed to retrieve user SID\n");
688 return ERROR_FUNCTION_FAILED
;
690 sprintfW(keypath
, szUserDataComp_fmt
, usersid
, comp
);
694 sprintfW(keypath
, szUserDataComp_fmt
, szUserSid
, comp
);
696 if (create
) return RegCreateKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
697 return RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, key
);
700 UINT
MSIREG_DeleteUserDataComponentKey(LPCWSTR szComponent
, LPCWSTR szUserSid
)
702 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
703 WCHAR comp
[GUID_SIZE
], keypath
[0x200];
708 if (!squash_guid(szComponent
, comp
)) return ERROR_FUNCTION_FAILED
;
709 TRACE("%s squished %s\n", debugstr_w(szComponent
), debugstr_w(comp
));
713 if (!(usersid
= get_user_sid()))
715 ERR("Failed to retrieve user SID\n");
716 return ERROR_FUNCTION_FAILED
;
718 sprintfW(keypath
, szUserDataComponents_fmt
, usersid
);
722 sprintfW(keypath
, szUserDataComponents_fmt
, szUserSid
);
724 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, &hkey
)) return ERROR_SUCCESS
;
725 r
= RegDeleteTreeW(hkey
, comp
);
730 UINT
MSIREG_OpenUserDataProductKey(LPCWSTR szProduct
, MSIINSTALLCONTEXT dwContext
, LPCWSTR szUserSid
, HKEY
*key
, BOOL create
)
732 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
733 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
736 if (!squash_guid(szProduct
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
737 TRACE("%s squished %s\n", debugstr_w(szProduct
), debugstr_w(squished_pc
));
739 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
740 sprintfW(keypath
, szUserDataProd_fmt
, szLocalSid
, squished_pc
);
742 sprintfW(keypath
, szUserDataProd_fmt
, szUserSid
, squished_pc
);
745 if (!(usersid
= get_user_sid()))
747 ERR("Failed to retrieve user SID\n");
748 return ERROR_FUNCTION_FAILED
;
750 sprintfW(keypath
, szUserDataProd_fmt
, usersid
, squished_pc
);
753 if (create
) return RegCreateKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
754 return RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, key
);
757 UINT
MSIREG_OpenUserDataPatchKey(LPCWSTR szPatch
, MSIINSTALLCONTEXT dwContext
, HKEY
*key
, BOOL create
)
759 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
760 WCHAR squished_patch
[GUID_SIZE
], keypath
[0x200];
763 if (!squash_guid(szPatch
, squished_patch
)) return ERROR_FUNCTION_FAILED
;
764 TRACE("%s squished %s\n", debugstr_w(szPatch
), debugstr_w(squished_patch
));
766 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
767 sprintfW(keypath
, szUserDataPatch_fmt
, szLocalSid
, squished_patch
);
770 if (!(usersid
= get_user_sid()))
772 ERR("Failed to retrieve user SID\n");
773 return ERROR_FUNCTION_FAILED
;
775 sprintfW(keypath
, szUserDataPatch_fmt
, usersid
, squished_patch
);
778 if (create
) return RegCreateKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
779 return RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, key
);
782 UINT
MSIREG_DeleteUserDataPatchKey(LPCWSTR patch
, MSIINSTALLCONTEXT context
)
784 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
785 WCHAR squished_patch
[GUID_SIZE
], keypath
[0x200];
790 if (!squash_guid(patch
, squished_patch
)) return ERROR_FUNCTION_FAILED
;
791 TRACE("%s squished %s\n", debugstr_w(patch
), debugstr_w(squished_patch
));
793 if (context
== MSIINSTALLCONTEXT_MACHINE
)
794 sprintfW(keypath
, szUserDataPatches_fmt
, szLocalSid
);
797 if (!(usersid
= get_user_sid()))
799 ERR("Failed to retrieve user SID\n");
800 return ERROR_FUNCTION_FAILED
;
802 sprintfW(keypath
, szUserDataPatches_fmt
, usersid
);
805 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, &hkey
)) return ERROR_SUCCESS
;
806 r
= RegDeleteTreeW(hkey
, squished_patch
);
811 UINT
MSIREG_OpenUserDataProductPatchesKey(LPCWSTR product
, MSIINSTALLCONTEXT context
, HKEY
*key
, BOOL create
)
813 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
814 WCHAR squished_product
[GUID_SIZE
], keypath
[0x200];
817 if (!squash_guid(product
, squished_product
)) return ERROR_FUNCTION_FAILED
;
818 TRACE("%s squished %s\n", debugstr_w(product
), debugstr_w(squished_product
));
820 if (context
== MSIINSTALLCONTEXT_MACHINE
)
821 sprintfW(keypath
, szUserDataProductPatches_fmt
, szLocalSid
, squished_product
);
824 if (!(usersid
= get_user_sid()))
826 ERR("Failed to retrieve user SID\n");
827 return ERROR_FUNCTION_FAILED
;
829 sprintfW(keypath
, szUserDataProductPatches_fmt
, usersid
, squished_product
);
832 if (create
) return RegCreateKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
833 return RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, key
);
836 UINT
MSIREG_OpenInstallProps(LPCWSTR szProduct
, MSIINSTALLCONTEXT dwContext
, LPCWSTR szUserSid
, HKEY
*key
, BOOL create
)
839 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
840 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
842 if (!squash_guid(szProduct
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
843 TRACE("%s squished %s\n", debugstr_w(szProduct
), debugstr_w(squished_pc
));
845 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
846 sprintfW(keypath
, szInstallProperties_fmt
, szLocalSid
, squished_pc
);
848 sprintfW(keypath
, szInstallProperties_fmt
, szUserSid
, squished_pc
);
851 if (!(usersid
= get_user_sid()))
853 ERR("Failed to retrieve user SID\n");
854 return ERROR_FUNCTION_FAILED
;
856 sprintfW(keypath
, szInstallProperties_fmt
, usersid
, squished_pc
);
859 if (create
) return RegCreateKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
860 return RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, key
);
863 UINT
MSIREG_DeleteUserDataProductKey(LPCWSTR szProduct
)
865 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
866 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
871 if (!squash_guid(szProduct
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
872 TRACE("%s squished %s\n", debugstr_w(szProduct
), debugstr_w(squished_pc
));
874 if (!(usersid
= get_user_sid()))
876 ERR("Failed to retrieve user SID\n");
877 return ERROR_FUNCTION_FAILED
;
879 sprintfW(keypath
, szUserDataProducts_fmt
, usersid
);
882 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, &hkey
)) return ERROR_SUCCESS
;
883 r
= RegDeleteTreeW(hkey
, squished_pc
);
888 UINT
MSIREG_DeleteProductKey(LPCWSTR szProduct
)
890 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
891 WCHAR squished_pc
[GUID_SIZE
];
895 if (!squash_guid(szProduct
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
896 TRACE("%s squished %s\n", debugstr_w(szProduct
), debugstr_w(squished_pc
));
898 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, szInstaller_Products
, 0, access
, &hkey
)) return ERROR_SUCCESS
;
899 r
= RegDeleteTreeW(hkey
, squished_pc
);
904 UINT
MSIREG_OpenPatchesKey(LPCWSTR szPatch
, HKEY
*key
, BOOL create
)
906 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
907 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
909 if (!squash_guid(szPatch
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
910 TRACE("%s squished %s\n", debugstr_w(szPatch
), debugstr_w(squished_pc
));
912 sprintfW(keypath
, szInstaller_Patches
, squished_pc
);
914 if (create
) return RegCreateKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
915 return RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, key
);
918 UINT
MSIREG_OpenUpgradeCodesKey(LPCWSTR szUpgradeCode
, HKEY
*key
, BOOL create
)
920 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
921 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
923 if (!squash_guid(szUpgradeCode
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
924 TRACE("%s squished %s\n", debugstr_w(szUpgradeCode
), debugstr_w(squished_pc
));
926 strcpyW(keypath
, szInstaller_UpgradeCodes
);
927 strcatW(keypath
, squished_pc
);
929 if (create
) return RegCreateKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
930 return RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, key
);
933 UINT
MSIREG_OpenUserUpgradeCodesKey(LPCWSTR szUpgradeCode
, HKEY
* key
, BOOL create
)
935 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
937 if (!squash_guid(szUpgradeCode
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
938 TRACE("%s squished %s\n", debugstr_w(szUpgradeCode
), debugstr_w(squished_pc
));
940 strcpyW(keypath
, szInstaller_UserUpgradeCodes
);
941 strcatW(keypath
, squished_pc
);
943 if (create
) return RegCreateKeyW(HKEY_CURRENT_USER
, keypath
, key
);
944 return RegOpenKeyW(HKEY_CURRENT_USER
, keypath
, key
);
947 UINT
MSIREG_DeleteUserUpgradeCodesKey(LPCWSTR szUpgradeCode
)
949 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
951 if (!squash_guid(szUpgradeCode
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
952 TRACE("%s squished %s\n", debugstr_w(szUpgradeCode
), debugstr_w(squished_pc
));
954 strcpyW(keypath
, szInstaller_UserUpgradeCodes
);
955 strcatW(keypath
, squished_pc
);
956 return RegDeleteTreeW(HKEY_CURRENT_USER
, keypath
);
959 UINT
MSIREG_DeleteLocalClassesProductKey(LPCWSTR szProductCode
)
961 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
962 WCHAR squished_pc
[GUID_SIZE
];
966 if (!squash_guid(szProductCode
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
967 TRACE("%s squished %s\n", debugstr_w(szProductCode
), debugstr_w(squished_pc
));
969 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, szInstaller_LocalClassesProducts
, 0, access
, &hkey
)) return ERROR_SUCCESS
;
970 r
= RegDeleteTreeW(hkey
, squished_pc
);
975 UINT
MSIREG_DeleteLocalClassesFeaturesKey(LPCWSTR szProductCode
)
977 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
978 WCHAR squished_pc
[GUID_SIZE
];
982 if (!squash_guid(szProductCode
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
983 TRACE("%s squished %s\n", debugstr_w(szProductCode
), debugstr_w(squished_pc
));
985 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, szInstaller_LocalClassesFeatures
, 0, access
, &hkey
)) return ERROR_SUCCESS
;
986 r
= RegDeleteTreeW(hkey
, squished_pc
);
991 UINT
MSIREG_OpenClassesUpgradeCodesKey(LPCWSTR szUpgradeCode
, HKEY
*key
, BOOL create
)
993 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
994 WCHAR squished_pc
[GUID_SIZE
], keypath
[0x200];
996 if (!squash_guid(szUpgradeCode
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
997 TRACE("%s squished %s\n", debugstr_w(szUpgradeCode
), debugstr_w(squished_pc
));
999 strcpyW(keypath
, szInstaller_ClassesUpgradeCode
);
1000 strcatW(keypath
, squished_pc
);
1002 if (create
) return RegCreateKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, NULL
, 0, access
, NULL
, key
, NULL
);
1003 return RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keypath
, 0, access
, key
);
1006 UINT
MSIREG_DeleteClassesUpgradeCodesKey(LPCWSTR szUpgradeCode
)
1008 REGSAM access
= KEY_WOW64_64KEY
| KEY_ALL_ACCESS
;
1009 WCHAR squished_pc
[GUID_SIZE
];
1013 if (!squash_guid(szUpgradeCode
, squished_pc
)) return ERROR_FUNCTION_FAILED
;
1014 TRACE("%s squished %s\n", debugstr_w(szUpgradeCode
), debugstr_w(squished_pc
));
1016 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, szInstaller_ClassesUpgradeCodes
, 0, access
, &hkey
)) return ERROR_SUCCESS
;
1017 r
= RegDeleteTreeW(hkey
, squished_pc
);
1022 /*************************************************************************
1023 * MsiDecomposeDescriptorW [MSI.@]
1025 * Decomposes an MSI descriptor into product, feature and component parts.
1026 * An MSI descriptor is a string of the form:
1027 * [base 85 guid] [feature code] '>' [base 85 guid]
1030 * szDescriptor [I] the descriptor to decompose
1031 * szProduct [O] buffer of MAX_FEATURE_CHARS+1 for the product guid
1032 * szFeature [O] buffer of MAX_FEATURE_CHARS+1 for the feature code
1033 * szComponent [O] buffer of MAX_FEATURE_CHARS+1 for the component guid
1034 * pUsed [O] the length of the descriptor
1037 * ERROR_SUCCESS if everything worked correctly
1038 * ERROR_INVALID_PARAMETER if the descriptor was invalid
1041 UINT WINAPI
MsiDecomposeDescriptorW( LPCWSTR szDescriptor
, LPWSTR szProduct
,
1042 LPWSTR szFeature
, LPWSTR szComponent
, LPDWORD pUsed
)
1046 GUID product
, component
;
1048 TRACE("%s %p %p %p %p\n", debugstr_w(szDescriptor
), szProduct
,
1049 szFeature
, szComponent
, pUsed
);
1051 r
= decode_base85_guid( szDescriptor
, &product
);
1053 return ERROR_INVALID_PARAMETER
;
1055 TRACE("product %s\n", debugstr_guid( &product
));
1057 p
= strchrW(&szDescriptor
[20],'>');
1059 return ERROR_INVALID_PARAMETER
;
1061 len
= (p
- &szDescriptor
[20]);
1062 if( len
> MAX_FEATURE_CHARS
)
1063 return ERROR_INVALID_PARAMETER
;
1065 TRACE("feature %s\n", debugstr_wn( &szDescriptor
[20], len
));
1067 r
= decode_base85_guid( p
+1, &component
);
1069 return ERROR_INVALID_PARAMETER
;
1071 TRACE("component %s\n", debugstr_guid( &component
));
1074 StringFromGUID2( &product
, szProduct
, MAX_FEATURE_CHARS
+1 );
1076 StringFromGUID2( &component
, szComponent
, MAX_FEATURE_CHARS
+1 );
1079 memcpy( szFeature
, &szDescriptor
[20], len
*sizeof(WCHAR
) );
1082 len
= ( &p
[21] - szDescriptor
);
1084 TRACE("length = %d\n", len
);
1085 if (pUsed
) *pUsed
= len
;
1087 return ERROR_SUCCESS
;
1090 UINT WINAPI
MsiDecomposeDescriptorA( LPCSTR szDescriptor
, LPSTR szProduct
,
1091 LPSTR szFeature
, LPSTR szComponent
, LPDWORD pUsed
)
1093 WCHAR product
[MAX_FEATURE_CHARS
+1];
1094 WCHAR feature
[MAX_FEATURE_CHARS
+1];
1095 WCHAR component
[MAX_FEATURE_CHARS
+1];
1096 LPWSTR str
= NULL
, p
= NULL
, f
= NULL
, c
= NULL
;
1099 TRACE("%s %p %p %p %p\n", debugstr_a(szDescriptor
), szProduct
,
1100 szFeature
, szComponent
, pUsed
);
1102 str
= strdupAtoW( szDescriptor
);
1103 if( szDescriptor
&& !str
)
1104 return ERROR_OUTOFMEMORY
;
1113 r
= MsiDecomposeDescriptorW( str
, p
, f
, c
, pUsed
);
1115 if (r
== ERROR_SUCCESS
)
1117 WideCharToMultiByte( CP_ACP
, 0, p
, -1,
1118 szProduct
, MAX_FEATURE_CHARS
+1, NULL
, NULL
);
1119 WideCharToMultiByte( CP_ACP
, 0, f
, -1,
1120 szFeature
, MAX_FEATURE_CHARS
+1, NULL
, NULL
);
1121 WideCharToMultiByte( CP_ACP
, 0, c
, -1,
1122 szComponent
, MAX_FEATURE_CHARS
+1, NULL
, NULL
);
1130 UINT WINAPI
MsiEnumProductsA(DWORD index
, LPSTR lpguid
)
1133 WCHAR szwGuid
[GUID_SIZE
];
1135 TRACE("%d %p\n", index
, lpguid
);
1138 return ERROR_INVALID_PARAMETER
;
1139 r
= MsiEnumProductsW(index
, szwGuid
);
1140 if( r
== ERROR_SUCCESS
)
1141 WideCharToMultiByte(CP_ACP
, 0, szwGuid
, -1, lpguid
, GUID_SIZE
, NULL
, NULL
);
1146 UINT WINAPI
MsiEnumProductsW(DWORD index
, LPWSTR lpguid
)
1148 TRACE("%d %p\n", index
, lpguid
);
1151 return ERROR_INVALID_PARAMETER
;
1153 return MsiEnumProductsExW( NULL
, szAllSid
, MSIINSTALLCONTEXT_ALL
, index
, lpguid
,
1157 UINT WINAPI
MsiEnumFeaturesA(LPCSTR szProduct
, DWORD index
,
1158 LPSTR szFeature
, LPSTR szParent
)
1161 WCHAR szwFeature
[GUID_SIZE
], szwParent
[GUID_SIZE
];
1162 LPWSTR szwProduct
= NULL
;
1164 TRACE("%s %d %p %p\n", debugstr_a(szProduct
), index
, szFeature
, szParent
);
1168 szwProduct
= strdupAtoW( szProduct
);
1170 return ERROR_OUTOFMEMORY
;
1173 r
= MsiEnumFeaturesW(szwProduct
, index
, szwFeature
, szwParent
);
1174 if( r
== ERROR_SUCCESS
)
1176 WideCharToMultiByte(CP_ACP
, 0, szwFeature
, -1,
1177 szFeature
, GUID_SIZE
, NULL
, NULL
);
1178 WideCharToMultiByte(CP_ACP
, 0, szwParent
, -1,
1179 szParent
, GUID_SIZE
, NULL
, NULL
);
1182 msi_free( szwProduct
);
1187 UINT WINAPI
MsiEnumFeaturesW(LPCWSTR szProduct
, DWORD index
,
1188 LPWSTR szFeature
, LPWSTR szParent
)
1190 HKEY hkeyProduct
= 0;
1193 TRACE("%s %d %p %p\n", debugstr_w(szProduct
), index
, szFeature
, szParent
);
1196 return ERROR_INVALID_PARAMETER
;
1198 r
= MSIREG_OpenInstallerFeaturesKey(szProduct
,&hkeyProduct
,FALSE
);
1199 if( r
!= ERROR_SUCCESS
)
1200 return ERROR_NO_MORE_ITEMS
;
1203 r
= RegEnumValueW(hkeyProduct
, index
, szFeature
, &sz
, NULL
, NULL
, NULL
, NULL
);
1204 RegCloseKey(hkeyProduct
);
1209 UINT WINAPI
MsiEnumComponentsA(DWORD index
, LPSTR lpguid
)
1212 WCHAR szwGuid
[GUID_SIZE
];
1214 TRACE("%u, %p\n", index
, lpguid
);
1216 if (!lpguid
) return ERROR_INVALID_PARAMETER
;
1218 r
= MsiEnumComponentsW(index
, szwGuid
);
1219 if( r
== ERROR_SUCCESS
)
1220 WideCharToMultiByte(CP_ACP
, 0, szwGuid
, -1, lpguid
, GUID_SIZE
, NULL
, NULL
);
1225 UINT WINAPI
MsiEnumComponentsW(DWORD index
, LPWSTR lpguid
)
1227 TRACE("%u, %p\n", index
, lpguid
);
1229 if (!lpguid
) return ERROR_INVALID_PARAMETER
;
1231 return MsiEnumComponentsExW( szAllSid
, MSIINSTALLCONTEXT_ALL
, index
, lpguid
, NULL
, NULL
, NULL
);
1234 UINT WINAPI
MsiEnumComponentsExA( LPCSTR user_sid
, DWORD ctx
, DWORD index
, CHAR guid
[39],
1235 MSIINSTALLCONTEXT
*installed_ctx
, LPSTR sid
, LPDWORD sid_len
)
1238 WCHAR
*user_sidW
= NULL
, *sidW
= NULL
, guidW
[GUID_SIZE
];
1240 TRACE("%s, %u, %u, %p, %p, %p, %p\n", debugstr_a(user_sid
), ctx
, index
, guid
, installed_ctx
,
1243 if (sid
&& !sid_len
) return ERROR_INVALID_PARAMETER
;
1244 if (user_sid
&& !(user_sidW
= strdupAtoW( user_sid
))) return ERROR_OUTOFMEMORY
;
1245 if (sid
&& !(sidW
= msi_alloc( *sid_len
* sizeof(WCHAR
) )))
1247 msi_free( user_sidW
);
1248 return ERROR_OUTOFMEMORY
;
1250 r
= MsiEnumComponentsExW( user_sidW
, ctx
, index
, guidW
, installed_ctx
, sidW
, sid_len
);
1251 if (r
== ERROR_SUCCESS
)
1253 if (guid
) WideCharToMultiByte( CP_ACP
, 0, guidW
, GUID_SIZE
, guid
, GUID_SIZE
, NULL
, NULL
);
1254 if (sid
) WideCharToMultiByte( CP_ACP
, 0, sidW
, *sid_len
+ 1, sid
, *sid_len
+ 1, NULL
, NULL
);
1256 msi_free( user_sidW
);
1261 static UINT
fetch_machine_component( DWORD ctx
, DWORD index
, DWORD
*idx
, WCHAR guid
[39],
1262 MSIINSTALLCONTEXT
*installed_ctx
, LPWSTR sid
, LPDWORD sid_len
)
1264 static const WCHAR componentsW
[] =
1265 {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
1266 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1267 'I','n','s','t','a','l','l','e','r','\\','U','s','e','r','D','a','t','a','\\',
1268 'S','-','1','-','5','-','1','8','\\','C','o','m','p','o','n','e','n','t','s',0};
1269 UINT r
= ERROR_SUCCESS
;
1270 WCHAR component
[GUID_SIZE
];
1271 DWORD i
= 0, len_component
;
1272 REGSAM access
= KEY_ENUMERATE_SUB_KEYS
| KEY_WOW64_64KEY
;
1273 HKEY key_components
;
1275 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, componentsW
, 0, access
, &key_components
))
1276 return ERROR_NO_MORE_ITEMS
;
1278 len_component
= sizeof(component
)/sizeof(component
[0]);
1279 while (!RegEnumKeyExW( key_components
, i
, component
, &len_component
, NULL
, NULL
, NULL
, NULL
))
1281 if (*idx
== index
) goto found
;
1283 len_component
= sizeof(component
)/sizeof(component
[0]);
1286 RegCloseKey( key_components
);
1287 return ERROR_NO_MORE_ITEMS
;
1295 r
= ERROR_MORE_DATA
;
1303 if (guid
) unsquash_guid( component
, guid
);
1304 if (installed_ctx
) *installed_ctx
= MSIINSTALLCONTEXT_MACHINE
;
1305 RegCloseKey( key_components
);
1309 static UINT
fetch_user_component( const WCHAR
*usersid
, DWORD ctx
, DWORD index
, DWORD
*idx
,
1310 WCHAR guid
[39], MSIINSTALLCONTEXT
*installed_ctx
, LPWSTR sid
,
1313 static const WCHAR userdataW
[] =
1314 {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
1315 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1316 'I','n','s','t','a','l','l','e','r','\\','U','s','e','r','D','a','t','a',0};
1317 static const WCHAR componentsW
[] = {'\\','C','o','m','p','o','n','e','n','t','s',0};
1318 UINT r
= ERROR_SUCCESS
;
1319 WCHAR path
[MAX_PATH
], component
[GUID_SIZE
], user
[128];
1320 DWORD i
= 0, j
= 0, len_component
, len_user
;
1321 REGSAM access
= KEY_ENUMERATE_SUB_KEYS
| KEY_WOW64_64KEY
;
1322 HKEY key_users
, key_components
;
1324 if (ctx
== MSIINSTALLCONTEXT_USERMANAGED
) /* FIXME: where to find these? */
1325 return ERROR_NO_MORE_ITEMS
;
1327 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, userdataW
, 0, access
, &key_users
))
1328 return ERROR_NO_MORE_ITEMS
;
1330 len_user
= sizeof(user
)/sizeof(user
[0]);
1331 while (!RegEnumKeyExW( key_users
, i
, user
, &len_user
, NULL
, NULL
, NULL
, NULL
))
1333 if ((strcmpW( usersid
, szAllSid
) && strcmpW( usersid
, user
)) ||
1334 !strcmpW( szLocalSid
, user
))
1337 len_user
= sizeof(user
)/sizeof(user
[0]);
1340 strcpyW( path
, user
);
1341 strcatW( path
, componentsW
);
1342 if (RegOpenKeyExW( key_users
, path
, 0, access
, &key_components
))
1345 len_user
= sizeof(user
)/sizeof(user
[0]);
1348 len_component
= sizeof(component
)/sizeof(component
[0]);
1349 while (!RegEnumKeyExW( key_components
, j
, component
, &len_component
, NULL
, NULL
, NULL
, NULL
))
1351 if (*idx
== index
) goto found
;
1353 len_component
= sizeof(component
)/sizeof(component
[0]);
1356 RegCloseKey( key_components
);
1357 len_user
= sizeof(user
)/sizeof(user
[0]);
1360 RegCloseKey( key_users
);
1361 return ERROR_NO_MORE_ITEMS
;
1366 if (*sid_len
< len_user
+ 1)
1368 *sid_len
= len_user
+ 1;
1369 r
= ERROR_MORE_DATA
;
1373 *sid_len
= len_user
;
1374 strcpyW( sid
, user
);
1377 if (guid
) unsquash_guid( component
, guid
);
1378 if (installed_ctx
) *installed_ctx
= ctx
;
1379 RegCloseKey( key_components
);
1380 RegCloseKey( key_users
);
1384 static UINT
enum_components( const WCHAR
*usersid
, DWORD ctx
, DWORD index
, DWORD
*idx
, WCHAR guid
[39],
1385 MSIINSTALLCONTEXT
*installed_ctx
, LPWSTR sid
, LPDWORD sid_len
)
1387 UINT r
= ERROR_NO_MORE_ITEMS
;
1392 usersid
= user
= get_user_sid();
1393 if (!user
) return ERROR_FUNCTION_FAILED
;
1395 if (ctx
& MSIINSTALLCONTEXT_USERMANAGED
)
1397 r
= fetch_user_component( usersid
, MSIINSTALLCONTEXT_USERMANAGED
, index
, idx
, guid
,
1398 installed_ctx
, sid
, sid_len
);
1399 if (r
!= ERROR_NO_MORE_ITEMS
) goto done
;
1401 if (ctx
& MSIINSTALLCONTEXT_USERUNMANAGED
)
1403 r
= fetch_user_component( usersid
, MSIINSTALLCONTEXT_USERUNMANAGED
, index
, idx
, guid
,
1404 installed_ctx
, sid
, sid_len
);
1405 if (r
!= ERROR_NO_MORE_ITEMS
) goto done
;
1407 if (ctx
& MSIINSTALLCONTEXT_MACHINE
)
1409 r
= fetch_machine_component( MSIINSTALLCONTEXT_MACHINE
, index
, idx
, guid
, installed_ctx
,
1411 if (r
!= ERROR_NO_MORE_ITEMS
) goto done
;
1419 UINT WINAPI
MsiEnumComponentsExW( LPCWSTR user_sid
, DWORD ctx
, DWORD index
, WCHAR guid
[39],
1420 MSIINSTALLCONTEXT
*installed_ctx
, LPWSTR sid
, LPDWORD sid_len
)
1424 static DWORD last_index
;
1426 TRACE("%s, %u, %u, %p, %p, %p, %p\n", debugstr_w(user_sid
), ctx
, index
, guid
, installed_ctx
,
1429 if ((sid
&& !sid_len
) || !ctx
|| (user_sid
&& ctx
== MSIINSTALLCONTEXT_MACHINE
))
1430 return ERROR_INVALID_PARAMETER
;
1432 if (index
&& index
- last_index
!= 1)
1433 return ERROR_INVALID_PARAMETER
;
1435 if (!index
) last_index
= 0;
1437 r
= enum_components( user_sid
, ctx
, index
, &idx
, guid
, installed_ctx
, sid
, sid_len
);
1438 if (r
== ERROR_SUCCESS
)
1446 UINT WINAPI
MsiEnumClientsA(LPCSTR szComponent
, DWORD index
, LPSTR szProduct
)
1449 WCHAR szwProduct
[GUID_SIZE
];
1450 LPWSTR szwComponent
= NULL
;
1452 TRACE("%s %d %p\n", debugstr_a(szComponent
), index
, szProduct
);
1455 return ERROR_INVALID_PARAMETER
;
1459 szwComponent
= strdupAtoW( szComponent
);
1461 return ERROR_OUTOFMEMORY
;
1464 r
= MsiEnumClientsW(szComponent
?szwComponent
:NULL
, index
, szwProduct
);
1465 if( r
== ERROR_SUCCESS
)
1467 WideCharToMultiByte(CP_ACP
, 0, szwProduct
, -1,
1468 szProduct
, GUID_SIZE
, NULL
, NULL
);
1471 msi_free( szwComponent
);
1476 UINT WINAPI
MsiEnumClientsW(LPCWSTR szComponent
, DWORD index
, LPWSTR szProduct
)
1480 WCHAR szValName
[SQUISH_GUID_SIZE
];
1482 TRACE("%s %d %p\n", debugstr_w(szComponent
), index
, szProduct
);
1484 if (!szComponent
|| !*szComponent
|| !szProduct
)
1485 return ERROR_INVALID_PARAMETER
;
1487 if (MSIREG_OpenUserDataComponentKey(szComponent
, NULL
, &hkeyComp
, FALSE
) != ERROR_SUCCESS
&&
1488 MSIREG_OpenUserDataComponentKey(szComponent
, szLocalSid
, &hkeyComp
, FALSE
) != ERROR_SUCCESS
)
1489 return ERROR_UNKNOWN_COMPONENT
;
1491 /* see if there are any products at all */
1492 sz
= SQUISH_GUID_SIZE
;
1493 r
= RegEnumValueW(hkeyComp
, 0, szValName
, &sz
, NULL
, NULL
, NULL
, NULL
);
1494 if (r
!= ERROR_SUCCESS
)
1496 RegCloseKey(hkeyComp
);
1499 return ERROR_INVALID_PARAMETER
;
1501 return ERROR_UNKNOWN_COMPONENT
;
1504 sz
= SQUISH_GUID_SIZE
;
1505 r
= RegEnumValueW(hkeyComp
, index
, szValName
, &sz
, NULL
, NULL
, NULL
, NULL
);
1506 if( r
== ERROR_SUCCESS
)
1508 unsquash_guid(szValName
, szProduct
);
1509 TRACE("-> %s\n", debugstr_w(szProduct
));
1511 RegCloseKey(hkeyComp
);
1515 UINT WINAPI
MsiEnumClientsExA(LPCSTR component
, LPCSTR usersid
, DWORD ctx
, DWORD index
,
1516 CHAR installed_product
[GUID_SIZE
],
1517 MSIINSTALLCONTEXT
*installed_ctx
, LPSTR sid
, LPDWORD sid_len
)
1519 FIXME("%s, %s, %u, %u, %p, %p, %p, %p\n", debugstr_a(component
), debugstr_a(usersid
),
1520 ctx
, index
, installed_product
, installed_ctx
, sid
, sid_len
);
1521 return ERROR_ACCESS_DENIED
;
1524 UINT WINAPI
MsiEnumClientsExW(LPCWSTR component
, LPCWSTR usersid
, DWORD ctx
, DWORD index
,
1525 WCHAR installed_product
[GUID_SIZE
],
1526 MSIINSTALLCONTEXT
*installed_ctx
, LPWSTR sid
, LPDWORD sid_len
)
1528 FIXME("%s, %s, %u, %u, %p, %p, %p, %p\n", debugstr_w(component
), debugstr_w(usersid
),
1529 ctx
, index
, installed_product
, installed_ctx
, sid
, sid_len
);
1530 return ERROR_ACCESS_DENIED
;
1533 static UINT
MSI_EnumComponentQualifiers( LPCWSTR szComponent
, DWORD iIndex
,
1534 awstring
*lpQualBuf
, LPDWORD pcchQual
,
1535 awstring
*lpAppBuf
, LPDWORD pcchAppBuf
)
1537 DWORD name_sz
, val_sz
, name_max
, val_max
, type
, ofs
;
1538 LPWSTR name
= NULL
, val
= NULL
;
1542 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent
), iIndex
,
1543 lpQualBuf
, pcchQual
, lpAppBuf
, pcchAppBuf
);
1546 return ERROR_INVALID_PARAMETER
;
1548 r
= MSIREG_OpenUserComponentsKey( szComponent
, &key
, FALSE
);
1549 if (r
!= ERROR_SUCCESS
)
1550 return ERROR_UNKNOWN_COMPONENT
;
1552 /* figure out how big the name is we want to return */
1554 r
= ERROR_OUTOFMEMORY
;
1555 name
= msi_alloc( name_max
* sizeof(WCHAR
) );
1560 r
= ERROR_OUTOFMEMORY
;
1561 val
= msi_alloc( val_max
);
1565 /* loop until we allocate enough memory */
1570 r
= RegEnumValueW( key
, iIndex
, name
, &name_sz
,
1571 NULL
, &type
, (LPBYTE
)val
, &val_sz
);
1572 if (r
== ERROR_SUCCESS
)
1574 if (r
!= ERROR_MORE_DATA
)
1577 if (type
!= REG_MULTI_SZ
)
1579 ERR("component data has wrong type (%d)\n", type
);
1583 r
= ERROR_OUTOFMEMORY
;
1584 if (name_sz
+ 1 >= name_max
)
1588 name
= msi_alloc( name_max
* sizeof (WCHAR
) );
1593 if (val_sz
> val_max
)
1595 val_max
= val_sz
+ sizeof (WCHAR
);
1597 val
= msi_alloc( val_max
* sizeof (WCHAR
) );
1602 ERR("should be enough data, but isn't %d %d\n", name_sz
, val_sz
);
1607 r
= MsiDecomposeDescriptorW( val
, NULL
, NULL
, NULL
, &ofs
);
1608 if (r
!= ERROR_SUCCESS
)
1611 TRACE("Providing %s and %s\n", debugstr_w(name
), debugstr_w(val
+ofs
));
1613 r
= msi_strcpy_to_awstring( name
, -1, lpQualBuf
, pcchQual
);
1614 r2
= msi_strcpy_to_awstring( val
+ofs
, -1, lpAppBuf
, pcchAppBuf
);
1616 if (r2
!= ERROR_SUCCESS
)
1626 /*************************************************************************
1627 * MsiEnumComponentQualifiersA [MSI.@]
1629 UINT WINAPI
MsiEnumComponentQualifiersA( LPCSTR szComponent
, DWORD iIndex
,
1630 LPSTR lpQualifierBuf
, LPDWORD pcchQualifierBuf
,
1631 LPSTR lpApplicationDataBuf
, LPDWORD pcchApplicationDataBuf
)
1633 awstring qual
, appdata
;
1637 TRACE("%s %08x %p %p %p %p\n", debugstr_a(szComponent
), iIndex
,
1638 lpQualifierBuf
, pcchQualifierBuf
, lpApplicationDataBuf
,
1639 pcchApplicationDataBuf
);
1641 comp
= strdupAtoW( szComponent
);
1642 if (szComponent
&& !comp
)
1643 return ERROR_OUTOFMEMORY
;
1645 qual
.unicode
= FALSE
;
1646 qual
.str
.a
= lpQualifierBuf
;
1648 appdata
.unicode
= FALSE
;
1649 appdata
.str
.a
= lpApplicationDataBuf
;
1651 r
= MSI_EnumComponentQualifiers( comp
, iIndex
,
1652 &qual
, pcchQualifierBuf
, &appdata
, pcchApplicationDataBuf
);
1657 /*************************************************************************
1658 * MsiEnumComponentQualifiersW [MSI.@]
1660 UINT WINAPI
MsiEnumComponentQualifiersW( LPCWSTR szComponent
, DWORD iIndex
,
1661 LPWSTR lpQualifierBuf
, LPDWORD pcchQualifierBuf
,
1662 LPWSTR lpApplicationDataBuf
, LPDWORD pcchApplicationDataBuf
)
1664 awstring qual
, appdata
;
1666 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent
), iIndex
,
1667 lpQualifierBuf
, pcchQualifierBuf
, lpApplicationDataBuf
,
1668 pcchApplicationDataBuf
);
1670 qual
.unicode
= TRUE
;
1671 qual
.str
.w
= lpQualifierBuf
;
1673 appdata
.unicode
= TRUE
;
1674 appdata
.str
.w
= lpApplicationDataBuf
;
1676 return MSI_EnumComponentQualifiers( szComponent
, iIndex
,
1677 &qual
, pcchQualifierBuf
, &appdata
, pcchApplicationDataBuf
);
1680 /*************************************************************************
1681 * MsiEnumRelatedProductsW [MSI.@]
1684 UINT WINAPI
MsiEnumRelatedProductsW(LPCWSTR szUpgradeCode
, DWORD dwReserved
,
1685 DWORD iProductIndex
, LPWSTR lpProductBuf
)
1689 DWORD dwSize
= SQUISH_GUID_SIZE
;
1690 WCHAR szKeyName
[SQUISH_GUID_SIZE
];
1692 TRACE("%s %u %u %p\n", debugstr_w(szUpgradeCode
), dwReserved
,
1693 iProductIndex
, lpProductBuf
);
1695 if (NULL
== szUpgradeCode
)
1696 return ERROR_INVALID_PARAMETER
;
1697 if (NULL
== lpProductBuf
)
1698 return ERROR_INVALID_PARAMETER
;
1700 r
= MSIREG_OpenUpgradeCodesKey(szUpgradeCode
, &hkey
, FALSE
);
1701 if (r
!= ERROR_SUCCESS
)
1702 return ERROR_NO_MORE_ITEMS
;
1704 r
= RegEnumValueW(hkey
, iProductIndex
, szKeyName
, &dwSize
, NULL
, NULL
, NULL
, NULL
);
1705 if( r
== ERROR_SUCCESS
)
1706 unsquash_guid(szKeyName
, lpProductBuf
);
1712 /*************************************************************************
1713 * MsiEnumRelatedProductsA [MSI.@]
1716 UINT WINAPI
MsiEnumRelatedProductsA(LPCSTR szUpgradeCode
, DWORD dwReserved
,
1717 DWORD iProductIndex
, LPSTR lpProductBuf
)
1719 LPWSTR szwUpgradeCode
= NULL
;
1720 WCHAR productW
[GUID_SIZE
];
1723 TRACE("%s %u %u %p\n", debugstr_a(szUpgradeCode
), dwReserved
,
1724 iProductIndex
, lpProductBuf
);
1728 szwUpgradeCode
= strdupAtoW( szUpgradeCode
);
1729 if( !szwUpgradeCode
)
1730 return ERROR_OUTOFMEMORY
;
1733 r
= MsiEnumRelatedProductsW( szwUpgradeCode
, dwReserved
,
1734 iProductIndex
, productW
);
1735 if (r
== ERROR_SUCCESS
)
1737 WideCharToMultiByte( CP_ACP
, 0, productW
, GUID_SIZE
,
1738 lpProductBuf
, GUID_SIZE
, NULL
, NULL
);
1740 msi_free( szwUpgradeCode
);
1744 /***********************************************************************
1745 * MsiEnumPatchesExA [MSI.@]
1747 UINT WINAPI
MsiEnumPatchesExA(LPCSTR szProductCode
, LPCSTR szUserSid
,
1748 DWORD dwContext
, DWORD dwFilter
, DWORD dwIndex
, LPSTR szPatchCode
,
1749 LPSTR szTargetProductCode
, MSIINSTALLCONTEXT
*pdwTargetProductContext
,
1750 LPSTR szTargetUserSid
, LPDWORD pcchTargetUserSid
)
1752 LPWSTR prodcode
= NULL
;
1753 LPWSTR usersid
= NULL
;
1754 LPWSTR targsid
= NULL
;
1755 WCHAR patch
[GUID_SIZE
];
1756 WCHAR targprod
[GUID_SIZE
];
1760 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p, %p)\n",
1761 debugstr_a(szProductCode
), debugstr_a(szUserSid
), dwContext
, dwFilter
,
1762 dwIndex
, szPatchCode
, szTargetProductCode
, pdwTargetProductContext
,
1763 szTargetUserSid
, pcchTargetUserSid
);
1765 if (szTargetUserSid
&& !pcchTargetUserSid
)
1766 return ERROR_INVALID_PARAMETER
;
1768 if (szProductCode
) prodcode
= strdupAtoW(szProductCode
);
1769 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1771 r
= MsiEnumPatchesExW(prodcode
, usersid
, dwContext
, dwFilter
, dwIndex
,
1772 patch
, targprod
, pdwTargetProductContext
,
1774 if (r
!= ERROR_SUCCESS
)
1777 WideCharToMultiByte(CP_ACP
, 0, patch
, -1, szPatchCode
,
1778 GUID_SIZE
, NULL
, NULL
);
1779 WideCharToMultiByte(CP_ACP
, 0, targprod
, -1, szTargetProductCode
,
1780 GUID_SIZE
, NULL
, NULL
);
1782 if (!szTargetUserSid
)
1784 if (pcchTargetUserSid
)
1785 *pcchTargetUserSid
= len
;
1790 targsid
= msi_alloc(++len
* sizeof(WCHAR
));
1793 r
= ERROR_OUTOFMEMORY
;
1797 r
= MsiEnumPatchesExW(prodcode
, usersid
, dwContext
, dwFilter
, dwIndex
,
1798 patch
, targprod
, pdwTargetProductContext
,
1800 if (r
!= ERROR_SUCCESS
|| !szTargetUserSid
)
1803 WideCharToMultiByte(CP_ACP
, 0, targsid
, -1, szTargetUserSid
,
1804 *pcchTargetUserSid
, NULL
, NULL
);
1806 len
= lstrlenW(targsid
);
1807 if (*pcchTargetUserSid
< len
+ 1)
1809 r
= ERROR_MORE_DATA
;
1810 *pcchTargetUserSid
= len
* sizeof(WCHAR
);
1813 *pcchTargetUserSid
= len
;
1823 static UINT
msi_get_patch_state(LPCWSTR prodcode
, LPCWSTR usersid
,
1824 MSIINSTALLCONTEXT context
,
1825 LPWSTR patch
, MSIPATCHSTATE
*state
)
1827 DWORD type
, val
, size
;
1828 HKEY prod
, hkey
= 0;
1831 UINT r
= ERROR_NO_MORE_ITEMS
;
1833 *state
= MSIPATCHSTATE_INVALID
;
1835 r
= MSIREG_OpenUserDataProductKey(prodcode
, context
,
1836 usersid
, &prod
, FALSE
);
1837 if (r
!= ERROR_SUCCESS
)
1838 return ERROR_NO_MORE_ITEMS
;
1840 res
= RegOpenKeyExW(prod
, szPatches
, 0, KEY_READ
, &hkey
);
1841 if (res
!= ERROR_SUCCESS
)
1844 res
= RegOpenKeyExW(hkey
, patch
, 0, KEY_READ
, &udpatch
);
1845 if (res
!= ERROR_SUCCESS
)
1848 size
= sizeof(DWORD
);
1849 res
= RegGetValueW(udpatch
, NULL
, szState
, RRF_RT_DWORD
, &type
, &val
, &size
);
1850 if (res
!= ERROR_SUCCESS
||
1851 val
< MSIPATCHSTATE_APPLIED
|| val
> MSIPATCHSTATE_REGISTERED
)
1853 r
= ERROR_BAD_CONFIGURATION
;
1861 RegCloseKey(udpatch
);
1868 static UINT
msi_check_product_patches(LPCWSTR prodcode
, LPCWSTR usersid
,
1869 MSIINSTALLCONTEXT context
, DWORD filter
, DWORD index
, DWORD
*idx
,
1870 LPWSTR patch
, LPWSTR targetprod
, MSIINSTALLCONTEXT
*targetctx
,
1871 LPWSTR targetsid
, DWORD
*sidsize
, LPWSTR
*transforms
)
1873 MSIPATCHSTATE state
= MSIPATCHSTATE_INVALID
;
1874 LPWSTR ptr
, patches
= NULL
;
1875 HKEY prod
, patchkey
= 0;
1876 HKEY localprod
= 0, localpatch
= 0;
1879 UINT temp
, r
= ERROR_NO_MORE_ITEMS
;
1881 if (MSIREG_OpenProductKey(prodcode
, usersid
, context
,
1882 &prod
, FALSE
) != ERROR_SUCCESS
)
1883 return ERROR_NO_MORE_ITEMS
;
1886 res
= RegGetValueW(prod
, szPatches
, szPatches
, RRF_RT_ANY
, &type
, NULL
,
1888 if (res
!= ERROR_SUCCESS
)
1891 if (type
!= REG_MULTI_SZ
)
1893 r
= ERROR_BAD_CONFIGURATION
;
1897 patches
= msi_alloc(size
);
1900 r
= ERROR_OUTOFMEMORY
;
1904 res
= RegGetValueW(prod
, szPatches
, szPatches
, RRF_RT_ANY
, &type
,
1906 if (res
!= ERROR_SUCCESS
)
1909 for (ptr
= patches
; *ptr
&& r
== ERROR_NO_MORE_ITEMS
; ptr
+= lstrlenW(ptr
) + 1)
1911 if (!unsquash_guid(ptr
, patch
))
1913 r
= ERROR_BAD_CONFIGURATION
;
1918 res
= RegGetValueW(prod
, szPatches
, ptr
, RRF_RT_REG_SZ
,
1919 &type
, NULL
, &size
);
1920 if (res
!= ERROR_SUCCESS
)
1925 *transforms
= msi_alloc(size
);
1928 r
= ERROR_OUTOFMEMORY
;
1932 res
= RegGetValueW(prod
, szPatches
, ptr
, RRF_RT_REG_SZ
,
1933 &type
, *transforms
, &size
);
1934 if (res
!= ERROR_SUCCESS
)
1938 if (context
== MSIINSTALLCONTEXT_USERMANAGED
)
1940 if (!(filter
& MSIPATCHSTATE_APPLIED
))
1942 temp
= msi_get_patch_state(prodcode
, usersid
, context
,
1944 if (temp
== ERROR_BAD_CONFIGURATION
)
1946 r
= ERROR_BAD_CONFIGURATION
;
1950 if (temp
!= ERROR_SUCCESS
|| !(filter
& state
))
1954 else if (context
== MSIINSTALLCONTEXT_USERUNMANAGED
)
1956 if (!(filter
& MSIPATCHSTATE_APPLIED
))
1958 temp
= msi_get_patch_state(prodcode
, usersid
, context
,
1960 if (temp
== ERROR_BAD_CONFIGURATION
)
1962 r
= ERROR_BAD_CONFIGURATION
;
1966 if (temp
!= ERROR_SUCCESS
|| !(filter
& state
))
1971 temp
= MSIREG_OpenUserDataPatchKey(patch
, context
,
1973 RegCloseKey(patchkey
);
1974 if (temp
!= ERROR_SUCCESS
)
1978 else if (context
== MSIINSTALLCONTEXT_MACHINE
)
1982 if (MSIREG_OpenUserDataProductKey(prodcode
, context
, NULL
, &localprod
, FALSE
) == ERROR_SUCCESS
&&
1983 RegOpenKeyExW(localprod
, szPatches
, 0, KEY_READ
, &localpatch
) == ERROR_SUCCESS
&&
1984 RegOpenKeyExW(localpatch
, ptr
, 0, KEY_READ
, &patchkey
) == ERROR_SUCCESS
)
1986 res
= RegGetValueW(patchkey
, NULL
, szState
, RRF_RT_REG_DWORD
,
1987 &type
, &state
, &size
);
1989 if (!(filter
& state
))
1990 res
= ERROR_NO_MORE_ITEMS
;
1992 RegCloseKey(patchkey
);
1995 RegCloseKey(localpatch
);
1996 RegCloseKey(localprod
);
1998 if (res
!= ERROR_SUCCESS
)
2010 lstrcpyW(targetprod
, prodcode
);
2013 *targetctx
= context
;
2017 lstrcpynW(targetsid
, usersid
, *sidsize
);
2018 if (lstrlenW(usersid
) >= *sidsize
)
2019 r
= ERROR_MORE_DATA
;
2024 *sidsize
= lstrlenW(usersid
);
2026 *sidsize
*= sizeof(WCHAR
);
2037 static UINT
msi_enum_patches(LPCWSTR szProductCode
, LPCWSTR szUserSid
,
2038 DWORD dwContext
, DWORD dwFilter
, DWORD dwIndex
, DWORD
*idx
,
2039 LPWSTR szPatchCode
, LPWSTR szTargetProductCode
,
2040 MSIINSTALLCONTEXT
*pdwTargetProductContext
, LPWSTR szTargetUserSid
,
2041 LPDWORD pcchTargetUserSid
, LPWSTR
*szTransforms
)
2043 LPWSTR usersid
= NULL
;
2044 UINT r
= ERROR_INVALID_PARAMETER
;
2048 szUserSid
= usersid
= get_user_sid();
2049 if (!usersid
) return ERROR_FUNCTION_FAILED
;
2052 if (dwContext
& MSIINSTALLCONTEXT_USERMANAGED
)
2054 r
= msi_check_product_patches(szProductCode
, szUserSid
,
2055 MSIINSTALLCONTEXT_USERMANAGED
, dwFilter
,
2056 dwIndex
, idx
, szPatchCode
,
2057 szTargetProductCode
,
2058 pdwTargetProductContext
, szTargetUserSid
,
2059 pcchTargetUserSid
, szTransforms
);
2060 if (r
!= ERROR_NO_MORE_ITEMS
)
2064 if (dwContext
& MSIINSTALLCONTEXT_USERUNMANAGED
)
2066 r
= msi_check_product_patches(szProductCode
, szUserSid
,
2067 MSIINSTALLCONTEXT_USERUNMANAGED
, dwFilter
,
2068 dwIndex
, idx
, szPatchCode
,
2069 szTargetProductCode
,
2070 pdwTargetProductContext
, szTargetUserSid
,
2071 pcchTargetUserSid
, szTransforms
);
2072 if (r
!= ERROR_NO_MORE_ITEMS
)
2076 if (dwContext
& MSIINSTALLCONTEXT_MACHINE
)
2078 r
= msi_check_product_patches(szProductCode
, szUserSid
,
2079 MSIINSTALLCONTEXT_MACHINE
, dwFilter
,
2080 dwIndex
, idx
, szPatchCode
,
2081 szTargetProductCode
,
2082 pdwTargetProductContext
, szTargetUserSid
,
2083 pcchTargetUserSid
, szTransforms
);
2084 if (r
!= ERROR_NO_MORE_ITEMS
)
2093 /***********************************************************************
2094 * MsiEnumPatchesExW [MSI.@]
2096 UINT WINAPI
MsiEnumPatchesExW(LPCWSTR szProductCode
, LPCWSTR szUserSid
,
2097 DWORD dwContext
, DWORD dwFilter
, DWORD dwIndex
, LPWSTR szPatchCode
,
2098 LPWSTR szTargetProductCode
, MSIINSTALLCONTEXT
*pdwTargetProductContext
,
2099 LPWSTR szTargetUserSid
, LPDWORD pcchTargetUserSid
)
2101 WCHAR squished_pc
[GUID_SIZE
];
2105 static DWORD last_index
;
2107 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p, %p)\n",
2108 debugstr_w(szProductCode
), debugstr_w(szUserSid
), dwContext
, dwFilter
,
2109 dwIndex
, szPatchCode
, szTargetProductCode
, pdwTargetProductContext
,
2110 szTargetUserSid
, pcchTargetUserSid
);
2112 if (!szProductCode
|| !squash_guid(szProductCode
, squished_pc
))
2113 return ERROR_INVALID_PARAMETER
;
2115 if (szUserSid
&& !strcmpW( szUserSid
, szLocalSid
))
2116 return ERROR_INVALID_PARAMETER
;
2118 if (dwContext
& MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
2119 return ERROR_INVALID_PARAMETER
;
2121 if (dwContext
<= MSIINSTALLCONTEXT_NONE
||
2122 dwContext
> MSIINSTALLCONTEXT_ALL
)
2123 return ERROR_INVALID_PARAMETER
;
2125 if (dwFilter
<= MSIPATCHSTATE_INVALID
|| dwFilter
> MSIPATCHSTATE_ALL
)
2126 return ERROR_INVALID_PARAMETER
;
2128 if (dwIndex
&& dwIndex
- last_index
!= 1)
2129 return ERROR_INVALID_PARAMETER
;
2134 r
= msi_enum_patches(szProductCode
, szUserSid
, dwContext
, dwFilter
,
2135 dwIndex
, &idx
, szPatchCode
, szTargetProductCode
,
2136 pdwTargetProductContext
, szTargetUserSid
,
2137 pcchTargetUserSid
, NULL
);
2139 if (r
== ERROR_SUCCESS
)
2140 last_index
= dwIndex
;
2147 /***********************************************************************
2148 * MsiEnumPatchesA [MSI.@]
2150 UINT WINAPI
MsiEnumPatchesA(LPCSTR szProduct
, DWORD iPatchIndex
,
2151 LPSTR lpPatchBuf
, LPSTR lpTransformsBuf
, LPDWORD pcchTransformsBuf
)
2153 LPWSTR product
, transforms
;
2154 WCHAR patch
[GUID_SIZE
];
2158 TRACE("(%s %d %p %p %p)\n", debugstr_a(szProduct
), iPatchIndex
,
2159 lpPatchBuf
, lpTransformsBuf
, pcchTransformsBuf
);
2161 if (!szProduct
|| !lpPatchBuf
|| !lpTransformsBuf
|| !pcchTransformsBuf
)
2162 return ERROR_INVALID_PARAMETER
;
2164 product
= strdupAtoW(szProduct
);
2166 return ERROR_OUTOFMEMORY
;
2168 len
= *pcchTransformsBuf
;
2169 transforms
= msi_alloc( len
* sizeof(WCHAR
) );
2172 r
= ERROR_OUTOFMEMORY
;
2176 r
= MsiEnumPatchesW(product
, iPatchIndex
, patch
, transforms
, &len
);
2177 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
2180 WideCharToMultiByte(CP_ACP
, 0, patch
, -1, lpPatchBuf
,
2181 GUID_SIZE
, NULL
, NULL
);
2183 if (!WideCharToMultiByte(CP_ACP
, 0, transforms
, -1, lpTransformsBuf
,
2184 *pcchTransformsBuf
, NULL
, NULL
))
2185 r
= ERROR_MORE_DATA
;
2187 if (r
== ERROR_MORE_DATA
)
2189 lpTransformsBuf
[*pcchTransformsBuf
- 1] = '\0';
2190 *pcchTransformsBuf
= len
* 2;
2193 *pcchTransformsBuf
= strlen( lpTransformsBuf
);
2196 msi_free(transforms
);
2202 /***********************************************************************
2203 * MsiEnumPatchesW [MSI.@]
2205 UINT WINAPI
MsiEnumPatchesW(LPCWSTR szProduct
, DWORD iPatchIndex
,
2206 LPWSTR lpPatchBuf
, LPWSTR lpTransformsBuf
, LPDWORD pcchTransformsBuf
)
2208 WCHAR squished_pc
[GUID_SIZE
];
2209 LPWSTR transforms
= NULL
;
2214 TRACE("(%s %d %p %p %p)\n", debugstr_w(szProduct
), iPatchIndex
,
2215 lpPatchBuf
, lpTransformsBuf
, pcchTransformsBuf
);
2217 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
2218 return ERROR_INVALID_PARAMETER
;
2220 if (!lpPatchBuf
|| !lpTransformsBuf
|| !pcchTransformsBuf
)
2221 return ERROR_INVALID_PARAMETER
;
2223 if (MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
,
2224 &prod
, FALSE
) != ERROR_SUCCESS
&&
2225 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
2226 &prod
, FALSE
) != ERROR_SUCCESS
&&
2227 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
2228 &prod
, FALSE
) != ERROR_SUCCESS
)
2229 return ERROR_UNKNOWN_PRODUCT
;
2233 r
= msi_enum_patches(szProduct
, NULL
, MSIINSTALLCONTEXT_ALL
,
2234 MSIPATCHSTATE_ALL
, iPatchIndex
, &idx
, lpPatchBuf
,
2235 NULL
, NULL
, NULL
, NULL
, &transforms
);
2236 if (r
!= ERROR_SUCCESS
)
2239 lstrcpynW(lpTransformsBuf
, transforms
, *pcchTransformsBuf
);
2240 if (*pcchTransformsBuf
<= lstrlenW(transforms
))
2242 r
= ERROR_MORE_DATA
;
2243 *pcchTransformsBuf
= lstrlenW(transforms
);
2246 *pcchTransformsBuf
= lstrlenW(transforms
);
2249 msi_free(transforms
);
2253 UINT WINAPI
MsiEnumProductsExA( LPCSTR product
, LPCSTR usersid
, DWORD ctx
, DWORD index
,
2254 CHAR installed_product
[GUID_SIZE
],
2255 MSIINSTALLCONTEXT
*installed_ctx
, LPSTR sid
, LPDWORD sid_len
)
2258 WCHAR installed_productW
[GUID_SIZE
], *productW
= NULL
, *usersidW
= NULL
, *sidW
= NULL
;
2260 TRACE("%s, %s, %u, %u, %p, %p, %p, %p\n", debugstr_a(product
), debugstr_a(usersid
),
2261 ctx
, index
, installed_product
, installed_ctx
, sid
, sid_len
);
2263 if (sid
&& !sid_len
) return ERROR_INVALID_PARAMETER
;
2264 if (product
&& !(productW
= strdupAtoW( product
))) return ERROR_OUTOFMEMORY
;
2265 if (usersid
&& !(usersidW
= strdupAtoW( usersid
)))
2267 msi_free( productW
);
2268 return ERROR_OUTOFMEMORY
;
2270 if (sid
&& !(sidW
= msi_alloc( *sid_len
* sizeof(WCHAR
) )))
2272 msi_free( usersidW
);
2273 msi_free( productW
);
2274 return ERROR_OUTOFMEMORY
;
2276 r
= MsiEnumProductsExW( productW
, usersidW
, ctx
, index
, installed_productW
,
2277 installed_ctx
, sidW
, sid_len
);
2278 if (r
== ERROR_SUCCESS
)
2280 if (installed_product
) WideCharToMultiByte( CP_ACP
, 0, installed_productW
, GUID_SIZE
,
2281 installed_product
, GUID_SIZE
, NULL
, NULL
);
2282 if (sid
) WideCharToMultiByte( CP_ACP
, 0, sidW
, *sid_len
+ 1, sid
, *sid_len
+ 1, NULL
, NULL
);
2284 msi_free( productW
);
2285 msi_free( usersidW
);
2290 static UINT
fetch_machine_product( const WCHAR
*match
, DWORD index
, DWORD
*idx
,
2291 WCHAR installed_product
[GUID_SIZE
],
2292 MSIINSTALLCONTEXT
*installed_ctx
, WCHAR
*sid
, DWORD
*sid_len
)
2294 static const WCHAR productsW
[] =
2295 {'S','o','f','t','w','a','r','e','\\','C','l','a','s','s','e','s','\\',
2296 'I','n','s','t','a','l','l','e','r','\\','P','r','o','d','u','c','t','s',0};
2298 WCHAR product
[GUID_SIZE
];
2300 REGSAM access
= KEY_ENUMERATE_SUB_KEYS
| KEY_WOW64_64KEY
;
2303 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, productsW
, 0, access
, &key
))
2304 return ERROR_NO_MORE_ITEMS
;
2306 len
= sizeof(product
)/sizeof(product
[0]);
2307 while (!RegEnumKeyExW( key
, i
, product
, &len
, NULL
, NULL
, NULL
, NULL
))
2309 if (match
&& strcmpW( match
, product
))
2312 len
= sizeof(product
)/sizeof(product
[0]);
2315 if (*idx
== index
) goto found
;
2317 len
= sizeof(product
)/sizeof(product
[0]);
2321 return ERROR_NO_MORE_ITEMS
;
2324 if (sid_len
&& *sid_len
< 1)
2327 r
= ERROR_MORE_DATA
;
2331 if (installed_product
) unsquash_guid( product
, installed_product
);
2332 if (installed_ctx
) *installed_ctx
= MSIINSTALLCONTEXT_MACHINE
;
2344 static UINT
fetch_user_product( const WCHAR
*match
, const WCHAR
*usersid
, DWORD ctx
, DWORD index
,
2345 DWORD
*idx
, WCHAR installed_product
[GUID_SIZE
],
2346 MSIINSTALLCONTEXT
*installed_ctx
, WCHAR
*sid
, DWORD
*sid_len
)
2348 static const WCHAR managedW
[] =
2349 {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
2350 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s',
2351 'i','o','n','\\','I','n','s','t','a','l','l','e','r','\\','M','a','n','a','g','e','d',0};
2352 static const WCHAR managed_productsW
[] =
2353 {'\\','I','n','s','t','a','l','l','e','r','\\','P','r','o','d','u','c','t','s',0};
2354 static const WCHAR unmanaged_productsW
[] =
2355 {'\\','S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
2356 'I','n','s','t','a','l','l','e','r','\\','P','r','o','d','u','c','t','s',0};
2358 const WCHAR
*subkey
;
2359 WCHAR path
[MAX_PATH
], product
[GUID_SIZE
], user
[128];
2360 DWORD i
= 0, j
= 0, len_product
, len_user
;
2361 REGSAM access
= KEY_ENUMERATE_SUB_KEYS
| KEY_WOW64_64KEY
;
2362 HKEY key_users
, key_products
;
2364 if (ctx
== MSIINSTALLCONTEXT_USERMANAGED
)
2366 subkey
= managed_productsW
;
2367 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, managedW
, 0, access
, &key_users
))
2368 return ERROR_NO_MORE_ITEMS
;
2370 else if (ctx
== MSIINSTALLCONTEXT_USERUNMANAGED
)
2372 subkey
= unmanaged_productsW
;
2373 if (RegOpenKeyExW( HKEY_USERS
, NULL
, 0, access
, &key_users
))
2374 return ERROR_NO_MORE_ITEMS
;
2376 else return ERROR_INVALID_PARAMETER
;
2378 len_user
= sizeof(user
)/sizeof(user
[0]);
2379 while (!RegEnumKeyExW( key_users
, i
, user
, &len_user
, NULL
, NULL
, NULL
, NULL
))
2381 if (strcmpW( usersid
, user
) && strcmpW( usersid
, szAllSid
))
2384 len_user
= sizeof(user
)/sizeof(user
[0]);
2387 strcpyW( path
, user
);
2388 strcatW( path
, subkey
);
2389 if (RegOpenKeyExW( key_users
, path
, 0, access
, &key_products
))
2392 len_user
= sizeof(user
)/sizeof(user
[0]);
2395 len_product
= sizeof(product
)/sizeof(product
[0]);
2396 while (!RegEnumKeyExW( key_products
, j
, product
, &len_product
, NULL
, NULL
, NULL
, NULL
))
2398 if (match
&& strcmpW( match
, product
))
2401 len_product
= sizeof(product
)/sizeof(product
[0]);
2404 if (*idx
== index
) goto found
;
2406 len_product
= sizeof(product
)/sizeof(product
[0]);
2409 RegCloseKey( key_products
);
2410 len_user
= sizeof(user
)/sizeof(user
[0]);
2413 RegCloseKey( key_users
);
2414 return ERROR_NO_MORE_ITEMS
;
2417 if (sid_len
&& *sid_len
<= len_user
)
2419 *sid_len
= len_user
;
2420 r
= ERROR_MORE_DATA
;
2424 if (installed_product
) unsquash_guid( product
, installed_product
);
2425 if (installed_ctx
) *installed_ctx
= ctx
;
2428 strcpyW( sid
, user
);
2429 *sid_len
= len_user
;
2433 RegCloseKey( key_products
);
2434 RegCloseKey( key_users
);
2438 static UINT
enum_products( const WCHAR
*product
, const WCHAR
*usersid
, DWORD ctx
, DWORD index
,
2439 DWORD
*idx
, WCHAR installed_product
[GUID_SIZE
],
2440 MSIINSTALLCONTEXT
*installed_ctx
, WCHAR
*sid
, DWORD
*sid_len
)
2442 UINT r
= ERROR_NO_MORE_ITEMS
;
2447 usersid
= user
= get_user_sid();
2448 if (!user
) return ERROR_FUNCTION_FAILED
;
2450 if (ctx
& MSIINSTALLCONTEXT_MACHINE
)
2452 r
= fetch_machine_product( product
, index
, idx
, installed_product
, installed_ctx
,
2454 if (r
!= ERROR_NO_MORE_ITEMS
) goto done
;
2456 if (ctx
& MSIINSTALLCONTEXT_USERUNMANAGED
)
2458 r
= fetch_user_product( product
, usersid
, MSIINSTALLCONTEXT_USERUNMANAGED
, index
,
2459 idx
, installed_product
, installed_ctx
, sid
, sid_len
);
2460 if (r
!= ERROR_NO_MORE_ITEMS
) goto done
;
2462 if (ctx
& MSIINSTALLCONTEXT_USERMANAGED
)
2464 r
= fetch_user_product( product
, usersid
, MSIINSTALLCONTEXT_USERMANAGED
, index
,
2465 idx
, installed_product
, installed_ctx
, sid
, sid_len
);
2466 if (r
!= ERROR_NO_MORE_ITEMS
) goto done
;
2474 UINT WINAPI
MsiEnumProductsExW( LPCWSTR product
, LPCWSTR usersid
, DWORD ctx
, DWORD index
,
2475 WCHAR installed_product
[GUID_SIZE
],
2476 MSIINSTALLCONTEXT
*installed_ctx
, LPWSTR sid
, LPDWORD sid_len
)
2480 static DWORD last_index
;
2482 TRACE("%s, %s, %u, %u, %p, %p, %p, %p\n", debugstr_w(product
), debugstr_w(usersid
),
2483 ctx
, index
, installed_product
, installed_ctx
, sid
, sid_len
);
2485 if ((sid
&& !sid_len
) || !ctx
|| (usersid
&& ctx
== MSIINSTALLCONTEXT_MACHINE
))
2486 return ERROR_INVALID_PARAMETER
;
2488 if (index
&& index
- last_index
!= 1)
2489 return ERROR_INVALID_PARAMETER
;
2491 if (!index
) last_index
= 0;
2493 r
= enum_products( product
, usersid
, ctx
, index
, &idx
, installed_product
, installed_ctx
,
2495 if (r
== ERROR_SUCCESS
)