msiexec: Add handling for msiexec's regserver option.
[wine] / programs / msiexec / msiexec.c
1 /*
2  * msiexec.exe implementation
3  *
4  * Copyright 2004 Vincent Béron
5  * Copyright 2005 Mike McCormack
6  *
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.
11  *
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.
16  *
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
20  */
21
22 #define WIN32_LEAN_AND_MEAN
23
24 #include <windows.h>
25 #include <msi.h>
26 #include <objbase.h>
27 #include <stdio.h>
28 #include <shellapi.h>
29
30 #include "wine/debug.h"
31 #include "wine/unicode.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(msiexec);
34
35 typedef HRESULT (WINAPI *DLLREGISTERSERVER)(void);
36 typedef HRESULT (WINAPI *DLLUNREGISTERSERVER)(void);
37
38 struct string_list
39 {
40         struct string_list *next;
41         WCHAR str[1];
42 };
43
44 static const char UsageStr[] =
45 "Usage:\n"
46 "  Install a product:\n"
47 "    msiexec {package|productcode} [property]\n"
48 "    msiexec /i {package|productcode} [property]\n"
49 "    msiexec /a package [property]\n"
50 "  Repair an installation:\n"
51 "    msiexec /f[p|o|e|d|c|a|u|m|s|v] {package|productcode}\n"
52 "  Uninstall a product:\n"
53 "    msiexec /x {package|productcode} [property]\n"
54 "  Advertise a product:\n"
55 "    msiexec /j[u|m] package [/t transform] [/g languageid]\n"
56 "    msiexec {u|m} package [/t transform] [/g languageid]\n"
57 "  Apply a patch:\n"
58 "    msiexec /p patchpackage [property]\n"
59 "    msiexec /p patchpackage /a package [property]\n"
60 "  Modifiers for above operations:\n"
61 "    msiexec /l[*][i|w|e|a|r|u|c|m|o|p|v|][+|!] logfile\n"
62 "    msiexec /q{|n|b|r|f|n+|b+|b-}\n"
63 "  Register a module:\n"
64 "    msiexec /y module\n"
65 "  Unregister a module:\n"
66 "    msiexec /z module\n"
67 "  Display usage and copyright:\n"
68 "    msiexec {/h|/?}\n"
69 "NOTE: Product code on commandline unimplemented as of yet\n"
70 "\n"
71 "Copyright 2004 Vincent Béron\n";
72
73 static const WCHAR ActionAdmin[] = {
74    'A','C','T','I','O','N','=','A','D','M','I','N',0 };
75 static const WCHAR RemoveAll[] = {
76    'R','E','M','O','V','E','=','A','L','L',0 };
77
78 static const WCHAR InstallRunOnce[] = {
79    'S','o','f','t','w','a','r','e','\\',
80    'M','i','c','r','o','s','o','f','t','\\',
81    'W','i','n','d','o','w','s','\\',
82    'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
83    'I','n','s','t','a','l','l','e','r','\\',
84    'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
85
86 static void ShowUsage(int ExitCode)
87 {
88         printf(UsageStr);
89         ExitProcess(ExitCode);
90 }
91
92 static BOOL IsProductCode(LPWSTR str)
93 {
94         GUID ProductCode;
95
96         if(lstrlenW(str) != 38)
97                 return FALSE;
98         return ( (CLSIDFromString(str, &ProductCode) == NOERROR) );
99
100 }
101
102 static VOID StringListAppend(struct string_list **list, LPCWSTR str)
103 {
104         struct string_list *entry;
105         DWORD size;
106
107         size = sizeof *entry + lstrlenW(str) * sizeof (WCHAR);
108         entry = HeapAlloc(GetProcessHeap(), 0, size);
109         if(!entry)
110         {
111                 WINE_ERR("Out of memory!\n");
112                 ExitProcess(1);
113         }
114         lstrcpyW(entry->str, str);
115         entry->next = NULL;
116
117         /*
118          * Ignoring o(n^2) time complexity to add n strings for simplicity,
119          *  add the string to the end of the list to preserve the order.
120          */
121         while( *list )
122                 list = &(*list)->next;
123         *list = entry;
124 }
125
126 static LPWSTR build_properties(struct string_list *property_list)
127 {
128         struct string_list *list;
129         LPWSTR ret, p, value;
130         DWORD len;
131         BOOL needs_quote;
132
133         if(!property_list)
134                 return NULL;
135
136         /* count the space we need */
137         len = 1;
138         for(list = property_list; list; list = list->next)
139                 len += lstrlenW(list->str) + 3;
140
141         ret = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
142
143         /* add a space before each string, and quote the value */
144         p = ret;
145         for(list = property_list; list; list = list->next)
146         {
147                 value = strchrW(list->str,'=');
148                 if(!value)
149                         continue;
150                 len = value - list->str;
151                 *p++ = ' ';
152                 memcpy(p, list->str, len * sizeof(WCHAR));
153                 p += len;
154                 *p++ = '=';
155
156                 /* check if the value contains spaces and maybe quote it */
157                 value++;
158                 needs_quote = strchrW(value,' ') ? 1 : 0;
159                 if(needs_quote)
160                         *p++ = '"';
161                 len = lstrlenW(value);
162                 memcpy(p, value, len * sizeof(WCHAR));
163                 p += len;
164                 if(needs_quote)
165                         *p++ = '"';
166         }
167         *p = 0;
168
169         WINE_TRACE("properties -> %s\n", wine_dbgstr_w(ret) );
170
171         return ret;
172 }
173
174 static LPWSTR build_transforms(struct string_list *transform_list)
175 {
176         struct string_list *list;
177         LPWSTR ret, p;
178         DWORD len;
179
180         /* count the space we need */
181         len = 1;
182         for(list = transform_list; list; list = list->next)
183                 len += lstrlenW(list->str) + 1;
184
185         ret = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
186
187         /* add all the transforms with a semicolon between each one */
188         p = ret;
189         for(list = transform_list; list; list = list->next)
190         {
191                 len = lstrlenW(list->str);
192                 lstrcpynW(p, list->str, len );
193                 p += len;
194                 if(list->next)
195                         *p++ = ';';
196         }
197         *p = 0;
198
199         return ret;
200 }
201
202 static DWORD msi_atou(LPCWSTR str)
203 {
204         DWORD ret = 0;
205         while(*str >= '0' && *str <= '9')
206         {
207                 ret *= 10;
208                 ret += (*str - '0');
209                 str++;
210         }
211         return 0;
212 }
213
214 /* str1 is the same as str2, ignoring case */
215 static BOOL msi_strequal(LPCWSTR str1, LPCSTR str2)
216 {
217         DWORD len, ret;
218         LPWSTR strW;
219
220         len = MultiByteToWideChar( CP_ACP, 0, str2, -1, NULL, 0);
221         if( !len )
222                 return FALSE;
223         if( lstrlenW(str1) != (len-1) )
224                 return FALSE;
225         strW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*len);
226         MultiByteToWideChar( CP_ACP, 0, str2, -1, strW, len);
227         ret = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, str1, len, strW, len);
228         HeapFree(GetProcessHeap(), 0, strW);
229         return (ret == CSTR_EQUAL);
230 }
231
232 /* prefix is hyphen or dash, and str1 is the same as str2, ignoring case */
233 static BOOL msi_option_equal(LPCWSTR str1, LPCSTR str2)
234 {
235     if (str1[0] != '/' && str1[0] != '-')
236         return FALSE;
237
238     /* skip over the hyphen or slash */
239     return msi_strequal(str1 + 1, str2);
240 }
241
242 /* str2 is at the beginning of str1, ignoring case */
243 static BOOL msi_strprefix(LPCWSTR str1, LPCSTR str2)
244 {
245         DWORD len, ret;
246         LPWSTR strW;
247
248         len = MultiByteToWideChar( CP_ACP, 0, str2, -1, NULL, 0);
249         if( !len )
250                 return FALSE;
251         if( lstrlenW(str1) < (len-1) )
252                 return FALSE;
253         strW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*len);
254         MultiByteToWideChar( CP_ACP, 0, str2, -1, strW, len);
255         ret = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, str1, len-1, strW, len-1);
256         HeapFree(GetProcessHeap(), 0, strW);
257         return (ret == CSTR_EQUAL);
258 }
259
260 /* prefix is hyphen or dash, and str2 is at the beginning of str1, ignoring case */
261 static BOOL msi_option_prefix(LPCWSTR str1, LPCSTR str2)
262 {
263     if (str1[0] != '/' && str1[0] != '-')
264         return FALSE;
265
266     /* skip over the hyphen or slash */
267     return msi_strprefix(str1 + 1, str2);
268 }
269
270 static VOID *LoadProc(LPCWSTR DllName, LPCSTR ProcName, HMODULE* DllHandle)
271 {
272         VOID* (*proc)(void);
273
274         *DllHandle = LoadLibraryExW(DllName, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
275         if(!*DllHandle)
276         {
277                 fprintf(stderr, "Unable to load dll %s\n", wine_dbgstr_w(DllName));
278                 ExitProcess(1);
279         }
280         proc = (VOID *) GetProcAddress(*DllHandle, ProcName);
281         if(!proc)
282         {
283                 fprintf(stderr, "Dll %s does not implement function %s\n",
284                         wine_dbgstr_w(DllName), ProcName);
285                 FreeLibrary(*DllHandle);
286                 ExitProcess(1);
287         }
288
289         return proc;
290 }
291
292 static DWORD DoDllRegisterServer(LPCWSTR DllName)
293 {
294         HRESULT hr;
295         DLLREGISTERSERVER pfDllRegisterServer = NULL;
296         HMODULE DllHandle = NULL;
297
298         pfDllRegisterServer = LoadProc(DllName, "DllRegisterServer", &DllHandle);
299
300         hr = pfDllRegisterServer();
301         if(FAILED(hr))
302         {
303                 fprintf(stderr, "Failed to register dll %s\n", wine_dbgstr_w(DllName));
304                 return 1;
305         }
306         printf("Successfully registered dll %s\n", wine_dbgstr_w(DllName));
307         if(DllHandle)
308                 FreeLibrary(DllHandle);
309         return 0;
310 }
311
312 static DWORD DoDllUnregisterServer(LPCWSTR DllName)
313 {
314         HRESULT hr;
315         DLLUNREGISTERSERVER pfDllUnregisterServer = NULL;
316         HMODULE DllHandle = NULL;
317
318         pfDllUnregisterServer = LoadProc(DllName, "DllUnregisterServer", &DllHandle);
319
320         hr = pfDllUnregisterServer();
321         if(FAILED(hr))
322         {
323                 fprintf(stderr, "Failed to unregister dll %s\n", wine_dbgstr_w(DllName));
324                 return 1;
325         }
326         printf("Successfully unregistered dll %s\n", wine_dbgstr_w(DllName));
327         if(DllHandle)
328                 FreeLibrary(DllHandle);
329         return 0;
330 }
331
332 static DWORD DoRegServer(void)
333 {
334     SC_HANDLE scm, service;
335     CHAR path[MAX_PATH+12];
336
337     scm = OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_CREATE_SERVICE);
338     if (!scm)
339     {
340         fprintf(stderr, "Failed to open the service control manager.\n");
341         return 1;
342     }
343
344     GetSystemDirectory(path, MAX_PATH);
345     lstrcatA(path, "\\msiexec.exe");
346
347     service = CreateServiceA(scm, "MSIServer", "MSIServer", GENERIC_ALL,
348                              SERVICE_WIN32_SHARE_PROCESS, SERVICE_DEMAND_START,
349                              SERVICE_ERROR_NORMAL, path, NULL, NULL,
350                              NULL, NULL, NULL);
351     if (!service)
352     {
353         fprintf(stderr, "Failed to create MSI service\n");
354         CloseServiceHandle(scm);
355         return 1;
356     }
357
358      CloseServiceHandle(scm);
359      CloseServiceHandle(service);
360      return 0;
361 }
362
363 static BOOL process_args_from_reg( LPWSTR ident, int *pargc, WCHAR ***pargv )
364 {
365         LONG r;
366         HKEY hkey = 0, hkeyArgs = 0;
367         DWORD sz = 0, type = 0;
368         LPWSTR buf = NULL;
369         BOOL ret = FALSE;
370
371         r = RegOpenKeyW(HKEY_LOCAL_MACHINE, InstallRunOnce, &hkey);
372         if(r != ERROR_SUCCESS)
373                 return FALSE;
374         r = RegQueryValueExW(hkey, ident, 0, &type, 0, &sz);
375         if(r == ERROR_SUCCESS && type == REG_SZ)
376         {
377                 buf = HeapAlloc(GetProcessHeap(), 0, sz);
378                 r = RegQueryValueExW(hkey, ident, 0, &type, (LPBYTE)buf, &sz);
379                 if( r == ERROR_SUCCESS )
380                 {
381                         *pargv = CommandLineToArgvW(buf, pargc);
382                         ret = TRUE;
383                 }
384         }
385         RegCloseKey(hkeyArgs);
386         return ret;
387 }
388
389 int main(int argc, char **argv)
390 {
391         int i;
392         BOOL FunctionInstall = FALSE;
393         BOOL FunctionInstallAdmin = FALSE;
394         BOOL FunctionRepair = FALSE;
395         BOOL FunctionAdvertise = FALSE;
396         BOOL FunctionPatch = FALSE;
397         BOOL FunctionDllRegisterServer = FALSE;
398         BOOL FunctionDllUnregisterServer = FALSE;
399         BOOL FunctionRegServer = FALSE;
400         BOOL FunctionUnregServer = FALSE;
401         BOOL FunctionUnknown = FALSE;
402
403         LPWSTR PackageName = NULL;
404         LPWSTR Properties = NULL;
405         struct string_list *property_list = NULL;
406
407         DWORD RepairMode = 0;
408
409         DWORD_PTR AdvertiseMode = 0;
410         struct string_list *transform_list = NULL;
411         LANGID Language = 0;
412
413         DWORD LogMode = 0;
414         LPWSTR LogFileName = NULL;
415         DWORD LogAttributes = 0;
416
417         LPWSTR PatchFileName = NULL;
418         INSTALLTYPE InstallType = INSTALLTYPE_DEFAULT;
419
420         INSTALLUILEVEL InstallUILevel = INSTALLUILEVEL_FULL;
421
422         LPWSTR DllName = NULL;
423         DWORD ReturnCode;
424         LPWSTR *argvW = NULL;
425
426         /* overwrite the command line */
427         argvW = CommandLineToArgvW( GetCommandLineW(), &argc );
428
429         /*
430          * If the args begin with /@ IDENT then we need to load the real
431          * command line out of the RunOnceEntries key in the registry.
432          *  We do that before starting to process the real commandline,
433          * then overwrite the commandline again.
434          */
435         if(argc>1 && msi_option_equal(argvW[1], "@"))
436         {
437                 if(!process_args_from_reg( argvW[2], &argc, &argvW ))
438                         return 1;
439         }
440
441         for(i = 1; i < argc; i++)
442         {
443                 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
444
445                 if (msi_option_equal(argvW[i], "regserver"))
446                 {
447                         FunctionRegServer = TRUE;
448                 }
449                 else if (msi_option_equal(argvW[i], "unregserver") || msi_option_equal(argvW[i], "unregister"))
450                 {
451                         FunctionUnregServer = TRUE;
452                 }
453                 else if(msi_option_prefix(argvW[i], "i"))
454                 {
455                         LPWSTR argvWi = argvW[i];
456                         FunctionInstall = TRUE;
457                         if(lstrlenW(argvWi) > 2)
458                                 argvWi += 2;
459                         else
460                         {
461                                 i++;
462                                 if(i >= argc)
463                                         ShowUsage(1);
464                                 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
465                                 argvWi = argvW[i];
466                         }
467                         PackageName = argvWi;
468                 }
469                 else if(msi_option_equal(argvW[i], "a"))
470                 {
471                         FunctionInstall = TRUE;
472                         FunctionInstallAdmin = TRUE;
473                         InstallType = INSTALLTYPE_NETWORK_IMAGE;
474                         i++;
475                         if(i >= argc)
476                                 ShowUsage(1);
477                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
478                         PackageName = argvW[i];
479                         StringListAppend(&property_list, ActionAdmin);
480                 }
481                 else if(msi_option_prefix(argvW[i], "f"))
482                 {
483                         int j;
484                         int len = lstrlenW(argvW[i]);
485                         FunctionRepair = TRUE;
486                         for(j = 2; j < len; j++)
487                         {
488                                 switch(argvW[i][j])
489                                 {
490                                         case 'P':
491                                         case 'p':
492                                                 RepairMode |= REINSTALLMODE_FILEMISSING;
493                                                 break;
494                                         case 'O':
495                                         case 'o':
496                                                 RepairMode |= REINSTALLMODE_FILEOLDERVERSION;
497                                                 break;
498                                         case 'E':
499                                         case 'e':
500                                                 RepairMode |= REINSTALLMODE_FILEEQUALVERSION;
501                                                 break;
502                                         case 'D':
503                                         case 'd':
504                                                 RepairMode |= REINSTALLMODE_FILEEXACT;
505                                                 break;
506                                         case 'C':
507                                         case 'c':
508                                                 RepairMode |= REINSTALLMODE_FILEVERIFY;
509                                                 break;
510                                         case 'A':
511                                         case 'a':
512                                                 RepairMode |= REINSTALLMODE_FILEREPLACE;
513                                                 break;
514                                         case 'U':
515                                         case 'u':
516                                                 RepairMode |= REINSTALLMODE_USERDATA;
517                                                 break;
518                                         case 'M':
519                                         case 'm':
520                                                 RepairMode |= REINSTALLMODE_MACHINEDATA;
521                                                 break;
522                                         case 'S':
523                                         case 's':
524                                                 RepairMode |= REINSTALLMODE_SHORTCUT;
525                                                 break;
526                                         case 'V':
527                                         case 'v':
528                                                 RepairMode |= REINSTALLMODE_PACKAGE;
529                                                 break;
530                                         default:
531                                                 fprintf(stderr, "Unknown option \"%c\" in Repair mode\n", argvW[i][j]);
532                                                 break;
533                                 }
534                         }
535                         if(len == 2)
536                         {
537                                 RepairMode = REINSTALLMODE_FILEMISSING |
538                                         REINSTALLMODE_FILEEQUALVERSION |
539                                         REINSTALLMODE_FILEVERIFY |
540                                         REINSTALLMODE_MACHINEDATA |
541                                         REINSTALLMODE_SHORTCUT;
542                         }
543                         i++;
544                         if(i >= argc)
545                                 ShowUsage(1);
546                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
547                         PackageName = argvW[i];
548                 }
549                 else if(msi_option_equal(argvW[i], "x"))
550                 {
551                         FunctionInstall = TRUE;
552                         i++;
553                         if(i >= argc)
554                                 ShowUsage(1);
555                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
556                         PackageName = argvW[i];
557                         StringListAppend(&property_list, RemoveAll);
558                 }
559                 else if(msi_option_prefix(argvW[i], "j"))
560                 {
561                         int j;
562                         int len = lstrlenW(argvW[i]);
563                         FunctionAdvertise = TRUE;
564                         for(j = 2; j < len; j++)
565                         {
566                                 switch(argvW[i][j])
567                                 {
568                                         case 'U':
569                                         case 'u':
570                                                 AdvertiseMode = ADVERTISEFLAGS_USERASSIGN;
571                                                 break;
572                                         case 'M':
573                                         case 'm':
574                                                 AdvertiseMode = ADVERTISEFLAGS_MACHINEASSIGN;
575                                                 break;
576                                         default:
577                                                 fprintf(stderr, "Unknown option \"%c\" in Advertise mode\n", argvW[i][j]);
578                                                 break;
579                                 }
580                         }
581                         i++;
582                         if(i >= argc)
583                                 ShowUsage(1);
584                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
585                         PackageName = argvW[i];
586                 }
587                 else if(msi_strequal(argvW[i], "u"))
588                 {
589                         FunctionAdvertise = TRUE;
590                         AdvertiseMode = ADVERTISEFLAGS_USERASSIGN;
591                         i++;
592                         if(i >= argc)
593                                 ShowUsage(1);
594                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
595                         PackageName = argvW[i];
596                 }
597                 else if(msi_strequal(argvW[i], "m"))
598                 {
599                         FunctionAdvertise = TRUE;
600                         AdvertiseMode = ADVERTISEFLAGS_MACHINEASSIGN;
601                         i++;
602                         if(i >= argc)
603                                 ShowUsage(1);
604                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
605                         PackageName = argvW[i];
606                 }
607                 else if(msi_option_equal(argvW[i], "t"))
608                 {
609                         i++;
610                         if(i >= argc)
611                                 ShowUsage(1);
612                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
613                         StringListAppend(&transform_list, argvW[i]);
614                 }
615                 else if(msi_option_equal(argvW[i], "g"))
616                 {
617                         i++;
618                         if(i >= argc)
619                                 ShowUsage(1);
620                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
621                         Language = msi_atou(argvW[i]);
622                 }
623                 else if(msi_option_prefix(argvW[i], "l"))
624                 {
625                         int j;
626                         int len = lstrlenW(argvW[i]);
627                         for(j = 2; j < len; j++)
628                         {
629                                 switch(argvW[i][j])
630                                 {
631                                         case 'I':
632                                         case 'i':
633                                                 LogMode |= INSTALLLOGMODE_INFO;
634                                                 break;
635                                         case 'W':
636                                         case 'w':
637                                                 LogMode |= INSTALLLOGMODE_WARNING;
638                                                 break;
639                                         case 'E':
640                                         case 'e':
641                                                 LogMode |= INSTALLLOGMODE_ERROR;
642                                                 break;
643                                         case 'A':
644                                         case 'a':
645                                                 LogMode |= INSTALLLOGMODE_ACTIONSTART;
646                                                 break;
647                                         case 'R':
648                                         case 'r':
649                                                 LogMode |= INSTALLLOGMODE_ACTIONDATA;
650                                                 break;
651                                         case 'U':
652                                         case 'u':
653                                                 LogMode |= INSTALLLOGMODE_USER;
654                                                 break;
655                                         case 'C':
656                                         case 'c':
657                                                 LogMode |= INSTALLLOGMODE_COMMONDATA;
658                                                 break;
659                                         case 'M':
660                                         case 'm':
661                                                 LogMode |= INSTALLLOGMODE_FATALEXIT;
662                                                 break;
663                                         case 'O':
664                                         case 'o':
665                                                 LogMode |= INSTALLLOGMODE_OUTOFDISKSPACE;
666                                                 break;
667                                         case 'P':
668                                         case 'p':
669                                                 LogMode |= INSTALLLOGMODE_PROPERTYDUMP;
670                                                 break;
671                                         case 'V':
672                                         case 'v':
673                                                 LogMode |= INSTALLLOGMODE_VERBOSE;
674                                                 break;
675                                         case '*':
676                                                 LogMode = INSTALLLOGMODE_FATALEXIT |
677                                                         INSTALLLOGMODE_ERROR |
678                                                         INSTALLLOGMODE_WARNING |
679                                                         INSTALLLOGMODE_USER |
680                                                         INSTALLLOGMODE_INFO |
681                                                         INSTALLLOGMODE_RESOLVESOURCE |
682                                                         INSTALLLOGMODE_OUTOFDISKSPACE |
683                                                         INSTALLLOGMODE_ACTIONSTART |
684                                                         INSTALLLOGMODE_ACTIONDATA |
685                                                         INSTALLLOGMODE_COMMONDATA |
686                                                         INSTALLLOGMODE_PROPERTYDUMP |
687                                                         INSTALLLOGMODE_PROGRESS |
688                                                         INSTALLLOGMODE_INITIALIZE |
689                                                         INSTALLLOGMODE_TERMINATE |
690                                                         INSTALLLOGMODE_SHOWDIALOG;
691                                                 break;
692                                         case '+':
693                                                 LogAttributes |= INSTALLLOGATTRIBUTES_APPEND;
694                                                 break;
695                                         case '!':
696                                                 LogAttributes |= INSTALLLOGATTRIBUTES_FLUSHEACHLINE;
697                                                 break;
698                                         default:
699                                                 break;
700                                 }
701                         }
702                         i++;
703                         if(i >= argc)
704                                 ShowUsage(1);
705                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
706                         LogFileName = argvW[i];
707                         if(MsiEnableLogW(LogMode, LogFileName, LogAttributes) != ERROR_SUCCESS)
708                         {
709                                 fprintf(stderr, "Logging in %s (0x%08lx, %lu) failed\n",
710                                          wine_dbgstr_w(LogFileName), LogMode, LogAttributes);
711                                 ExitProcess(1);
712                         }
713                 }
714                 else if(msi_option_equal(argvW[i], "p"))
715                 {
716                         FunctionPatch = TRUE;
717                         i++;
718                         if(i >= argc)
719                                 ShowUsage(1);
720                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
721                         PatchFileName = argvW[i];
722                 }
723                 else if(msi_option_prefix(argvW[i], "q"))
724                 {
725                         if(lstrlenW(argvW[i]) == 2 || msi_strequal(argvW[i]+2, "n"))
726                         {
727                                 InstallUILevel = INSTALLUILEVEL_NONE;
728                         }
729                         else if(msi_strequal(argvW[i]+2, "b"))
730                         {
731                                 InstallUILevel = INSTALLUILEVEL_BASIC;
732                         }
733                         else if(msi_strequal(argvW[i]+2, "r"))
734                         {
735                                 InstallUILevel = INSTALLUILEVEL_REDUCED;
736                         }
737                         else if(msi_strequal(argvW[i]+2, "f"))
738                         {
739                                 InstallUILevel = INSTALLUILEVEL_FULL|INSTALLUILEVEL_ENDDIALOG;
740                         }
741                         else if(msi_strequal(argvW[i]+2, "n+"))
742                         {
743                                 InstallUILevel = INSTALLUILEVEL_NONE|INSTALLUILEVEL_ENDDIALOG;
744                         }
745                         else if(msi_strequal(argvW[i]+2, "b+"))
746                         {
747                                 InstallUILevel = INSTALLUILEVEL_BASIC|INSTALLUILEVEL_ENDDIALOG;
748                         }
749                         else if(msi_strequal(argvW[i]+2, "b-"))
750                         {
751                                 InstallUILevel = INSTALLUILEVEL_BASIC|INSTALLUILEVEL_PROGRESSONLY;
752                         }
753                         else if(msi_strequal(argvW[i]+2, "b+!"))
754                         {
755                                 InstallUILevel = INSTALLUILEVEL_BASIC|INSTALLUILEVEL_ENDDIALOG;
756                                 WINE_FIXME("Unknown modifier: !\n");
757                         }
758                         else
759                         {
760                                 fprintf(stderr, "Unknown option \"%s\" for UI level\n",
761                                          wine_dbgstr_w(argvW[i]+2));
762                         }
763                 }
764                 else if(msi_option_equal(argvW[i], "y"))
765                 {
766                         FunctionDllRegisterServer = TRUE;
767                         i++;
768                         if(i >= argc)
769                                 ShowUsage(1);
770                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
771                         DllName = argvW[i];
772                 }
773                 else if(msi_option_equal(argvW[i], "z"))
774                 {
775                         FunctionDllUnregisterServer = TRUE;
776                         i++;
777                         if(i >= argc)
778                                 ShowUsage(1);
779                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
780                         DllName = argvW[i];
781                 }
782                 else if(msi_option_equal(argvW[i], "h") || msi_option_equal(argvW[i], "?"))
783                 {
784                         ShowUsage(0);
785                 }
786                 else if(msi_option_equal(argvW[i], "m"))
787                 {
788                         FunctionUnknown = TRUE;
789                         WINE_FIXME("Unknown parameter /m\n");
790                 }
791                 else if(msi_option_equal(argvW[i], "D"))
792                 {
793                         FunctionUnknown = TRUE;
794                         WINE_FIXME("Unknown parameter /D\n");
795                 }
796                 else
797                         StringListAppend(&property_list, argvW[i]);
798         }
799
800         /* start the GUI */
801         MsiSetInternalUI(InstallUILevel, NULL);
802
803         Properties = build_properties( property_list );
804
805         if(FunctionInstallAdmin && FunctionPatch)
806                 FunctionInstall = FALSE;
807
808         ReturnCode = 1;
809         if(FunctionInstall)
810         {
811                 if(IsProductCode(PackageName))
812                         ReturnCode = MsiConfigureProductExW(PackageName, 0, INSTALLSTATE_DEFAULT, Properties);
813                 else
814                         ReturnCode = MsiInstallProductW(PackageName, Properties);
815         }
816         else if(FunctionRepair)
817         {
818                 if(IsProductCode(PackageName))
819                         WINE_FIXME("Product code treatment not implemented yet\n");
820                 else
821                         ReturnCode = MsiReinstallProductW(PackageName, RepairMode);
822         }
823         else if(FunctionAdvertise)
824         {
825                 LPWSTR Transforms = build_transforms( property_list );
826                 ReturnCode = MsiAdvertiseProductW(PackageName, (LPWSTR) AdvertiseMode, Transforms, Language);
827         }
828         else if(FunctionPatch)
829         {
830                 ReturnCode = MsiApplyPatchW(PatchFileName, PackageName, InstallType, Properties);
831         }
832         else if(FunctionDllRegisterServer)
833         {
834                 ReturnCode = DoDllRegisterServer(DllName);
835         }
836         else if(FunctionDllUnregisterServer)
837         {
838                 ReturnCode = DoDllUnregisterServer(DllName);
839         }
840         else if (FunctionRegServer)
841         {
842                 ReturnCode = DoRegServer();
843         }
844         else if (FunctionUnregServer)
845         {
846                 WINE_FIXME( "/unregserver not implemented yet, ignoring\n" );
847         }
848         else if (FunctionUnknown)
849         {
850                 WINE_FIXME( "Unknown function, ignoring\n" );
851         }
852         else
853                 ShowUsage(1);
854
855         return ReturnCode;
856 }