msiexec: Add a fixme for administrative installs.
[wine.git] / programs / msiexec / msiexec.c
blob1b688a54225c63cc0264e5e37f9025a1adb964e7
1 /*
2 * msiexec.exe implementation
4 * Copyright 2004 Vincent BĂ©ron
5 * Copyright 2005 Mike McCormack
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
22 #define WIN32_LEAN_AND_MEAN
24 #include <windows.h>
25 #include <msi.h>
26 #include <winsvc.h>
27 #include <objbase.h>
28 #include <stdio.h>
30 #include "wine/debug.h"
31 #include "wine/unicode.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(msiexec);
35 typedef HRESULT (WINAPI *DLLREGISTERSERVER)(void);
36 typedef HRESULT (WINAPI *DLLUNREGISTERSERVER)(void);
38 DWORD DoService(void);
40 struct string_list
42 struct string_list *next;
43 WCHAR str[1];
46 static const WCHAR ActionAdmin[] = {
47 'A','C','T','I','O','N','=','A','D','M','I','N',0 };
48 static const WCHAR RemoveAll[] = {
49 'R','E','M','O','V','E','=','A','L','L',0 };
51 static const WCHAR InstallRunOnce[] = {
52 'S','o','f','t','w','a','r','e','\\',
53 'M','i','c','r','o','s','o','f','t','\\',
54 'W','i','n','d','o','w','s','\\',
55 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
56 'I','n','s','t','a','l','l','e','r','\\',
57 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
59 static void ShowUsage(int ExitCode)
61 WCHAR msiexec_version[40];
62 WCHAR filename[MAX_PATH];
63 LPWSTR msi_res;
64 LPWSTR msiexec_help;
65 HMODULE hmsi = GetModuleHandleA("msi.dll");
66 DWORD len;
67 DWORD res;
69 /* MsiGetFileVersion need the full path */
70 *filename = 0;
71 res = GetModuleFileNameW(hmsi, filename, sizeof(filename) / sizeof(filename[0]));
72 if (!res)
73 WINE_ERR("GetModuleFileName failed: %d\n", GetLastError());
75 len = sizeof(msiexec_version) / sizeof(msiexec_version[0]);
76 *msiexec_version = 0;
77 res = MsiGetFileVersionW(filename, msiexec_version, &len, NULL, NULL);
78 if (res)
79 WINE_ERR("MsiGetFileVersion failed with %d\n", res);
81 /* Return the length of the resource.
82 No typo: The LPWSTR parameter must be a LPWSTR * for this mode */
83 len = LoadStringW(hmsi, 10, (LPWSTR) &msi_res, 0);
85 msi_res = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
86 msiexec_help = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) + sizeof(msiexec_version));
87 if (msi_res && msiexec_help) {
88 *msi_res = 0;
89 LoadStringW(hmsi, 10, msi_res, len + 1);
91 sprintfW(msiexec_help, msi_res, msiexec_version);
92 MsiMessageBoxW(0, msiexec_help, NULL, 0, GetUserDefaultLangID(), 0);
94 HeapFree(GetProcessHeap(), 0, msi_res);
95 HeapFree(GetProcessHeap(), 0, msiexec_help);
96 ExitProcess(ExitCode);
99 static BOOL IsProductCode(LPWSTR str)
101 GUID ProductCode;
103 if(lstrlenW(str) != 38)
104 return FALSE;
105 return ( (CLSIDFromString(str, &ProductCode) == NOERROR) );
109 static VOID StringListAppend(struct string_list **list, LPCWSTR str)
111 struct string_list *entry;
113 entry = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(struct string_list, str[lstrlenW(str) + 1]));
114 if(!entry)
116 WINE_ERR("Out of memory!\n");
117 ExitProcess(1);
119 lstrcpyW(entry->str, str);
120 entry->next = NULL;
123 * Ignoring o(n^2) time complexity to add n strings for simplicity,
124 * add the string to the end of the list to preserve the order.
126 while( *list )
127 list = &(*list)->next;
128 *list = entry;
131 static LPWSTR build_properties(struct string_list *property_list)
133 struct string_list *list;
134 LPWSTR ret, p, value;
135 DWORD len;
136 BOOL needs_quote;
138 if(!property_list)
139 return NULL;
141 /* count the space we need */
142 len = 1;
143 for(list = property_list; list; list = list->next)
144 len += lstrlenW(list->str) + 3;
146 ret = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
148 /* add a space before each string, and quote the value */
149 p = ret;
150 for(list = property_list; list; list = list->next)
152 value = strchrW(list->str,'=');
153 if(!value)
154 continue;
155 len = value - list->str;
156 *p++ = ' ';
157 memcpy(p, list->str, len * sizeof(WCHAR));
158 p += len;
159 *p++ = '=';
161 /* check if the value contains spaces and maybe quote it */
162 value++;
163 needs_quote = strchrW(value,' ') ? 1 : 0;
164 if(needs_quote)
165 *p++ = '"';
166 len = lstrlenW(value);
167 memcpy(p, value, len * sizeof(WCHAR));
168 p += len;
169 if(needs_quote)
170 *p++ = '"';
172 *p = 0;
174 WINE_TRACE("properties -> %s\n", wine_dbgstr_w(ret) );
176 return ret;
179 static LPWSTR build_transforms(struct string_list *transform_list)
181 struct string_list *list;
182 LPWSTR ret, p;
183 DWORD len;
185 /* count the space we need */
186 len = 1;
187 for(list = transform_list; list; list = list->next)
188 len += lstrlenW(list->str) + 1;
190 ret = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
192 /* add all the transforms with a semicolon between each one */
193 p = ret;
194 for(list = transform_list; list; list = list->next)
196 len = lstrlenW(list->str);
197 lstrcpynW(p, list->str, len );
198 p += len;
199 if(list->next)
200 *p++ = ';';
202 *p = 0;
204 return ret;
207 static DWORD msi_atou(LPCWSTR str)
209 DWORD ret = 0;
210 while(*str >= '0' && *str <= '9')
212 ret *= 10;
213 ret += (*str - '0');
214 str++;
216 return ret;
219 static LPWSTR msi_strdup(LPCWSTR str)
221 DWORD len = lstrlenW(str)+1;
222 LPWSTR ret = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*len);
223 lstrcpyW(ret, str);
224 return ret;
227 /* str1 is the same as str2, ignoring case */
228 static BOOL msi_strequal(LPCWSTR str1, LPCSTR str2)
230 DWORD len, ret;
231 LPWSTR strW;
233 len = MultiByteToWideChar( CP_ACP, 0, str2, -1, NULL, 0);
234 if( !len )
235 return FALSE;
236 if( lstrlenW(str1) != (len-1) )
237 return FALSE;
238 strW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*len);
239 MultiByteToWideChar( CP_ACP, 0, str2, -1, strW, len);
240 ret = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, str1, len, strW, len);
241 HeapFree(GetProcessHeap(), 0, strW);
242 return (ret == CSTR_EQUAL);
245 /* prefix is hyphen or dash, and str1 is the same as str2, ignoring case */
246 static BOOL msi_option_equal(LPCWSTR str1, LPCSTR str2)
248 if (str1[0] != '/' && str1[0] != '-')
249 return FALSE;
251 /* skip over the hyphen or slash */
252 return msi_strequal(str1 + 1, str2);
255 /* str2 is at the beginning of str1, ignoring case */
256 static BOOL msi_strprefix(LPCWSTR str1, LPCSTR str2)
258 DWORD len, ret;
259 LPWSTR strW;
261 len = MultiByteToWideChar( CP_ACP, 0, str2, -1, NULL, 0);
262 if( !len )
263 return FALSE;
264 if( lstrlenW(str1) < (len-1) )
265 return FALSE;
266 strW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*len);
267 MultiByteToWideChar( CP_ACP, 0, str2, -1, strW, len);
268 ret = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, str1, len-1, strW, len-1);
269 HeapFree(GetProcessHeap(), 0, strW);
270 return (ret == CSTR_EQUAL);
273 /* prefix is hyphen or dash, and str2 is at the beginning of str1, ignoring case */
274 static BOOL msi_option_prefix(LPCWSTR str1, LPCSTR str2)
276 if (str1[0] != '/' && str1[0] != '-')
277 return FALSE;
279 /* skip over the hyphen or slash */
280 return msi_strprefix(str1 + 1, str2);
283 static VOID *LoadProc(LPCWSTR DllName, LPCSTR ProcName, HMODULE* DllHandle)
285 VOID* (*proc)(void);
287 *DllHandle = LoadLibraryExW(DllName, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
288 if(!*DllHandle)
290 fprintf(stderr, "Unable to load dll %s\n", wine_dbgstr_w(DllName));
291 ExitProcess(1);
293 proc = (VOID *) GetProcAddress(*DllHandle, ProcName);
294 if(!proc)
296 fprintf(stderr, "Dll %s does not implement function %s\n",
297 wine_dbgstr_w(DllName), ProcName);
298 FreeLibrary(*DllHandle);
299 ExitProcess(1);
302 return proc;
305 static DWORD DoDllRegisterServer(LPCWSTR DllName)
307 HRESULT hr;
308 DLLREGISTERSERVER pfDllRegisterServer = NULL;
309 HMODULE DllHandle = NULL;
311 pfDllRegisterServer = LoadProc(DllName, "DllRegisterServer", &DllHandle);
313 hr = pfDllRegisterServer();
314 if(FAILED(hr))
316 fprintf(stderr, "Failed to register dll %s\n", wine_dbgstr_w(DllName));
317 return 1;
319 printf("Successfully registered dll %s\n", wine_dbgstr_w(DllName));
320 if(DllHandle)
321 FreeLibrary(DllHandle);
322 return 0;
325 static DWORD DoDllUnregisterServer(LPCWSTR DllName)
327 HRESULT hr;
328 DLLUNREGISTERSERVER pfDllUnregisterServer = NULL;
329 HMODULE DllHandle = NULL;
331 pfDllUnregisterServer = LoadProc(DllName, "DllUnregisterServer", &DllHandle);
333 hr = pfDllUnregisterServer();
334 if(FAILED(hr))
336 fprintf(stderr, "Failed to unregister dll %s\n", wine_dbgstr_w(DllName));
337 return 1;
339 printf("Successfully unregistered dll %s\n", wine_dbgstr_w(DllName));
340 if(DllHandle)
341 FreeLibrary(DllHandle);
342 return 0;
345 static DWORD DoRegServer(void)
347 static const WCHAR msiserverW[] = {'M','S','I','S','e','r','v','e','r',0};
348 static const WCHAR msiexecW[] = {'\\','m','s','i','e','x','e','c',' ','/','V',0};
349 SC_HANDLE scm, service;
350 WCHAR path[MAX_PATH+12];
351 DWORD len, ret = 0;
353 if (!(scm = OpenSCManagerW(NULL, SERVICES_ACTIVE_DATABASEW, SC_MANAGER_CREATE_SERVICE)))
355 fprintf(stderr, "Failed to open the service control manager.\n");
356 return 1;
358 len = GetSystemDirectoryW(path, MAX_PATH);
359 lstrcpyW(path + len, msiexecW);
360 if ((service = CreateServiceW(scm, msiserverW, msiserverW, GENERIC_ALL,
361 SERVICE_WIN32_SHARE_PROCESS, SERVICE_DEMAND_START,
362 SERVICE_ERROR_NORMAL, path, NULL, NULL, NULL, NULL, NULL)))
364 CloseServiceHandle(service);
366 else if (GetLastError() != ERROR_SERVICE_EXISTS)
368 fprintf(stderr, "Failed to create MSI service\n");
369 ret = 1;
371 CloseServiceHandle(scm);
372 return ret;
375 static DWORD DoUnregServer(void)
377 static const WCHAR msiserverW[] = {'M','S','I','S','e','r','v','e','r',0};
378 SC_HANDLE scm, service;
379 DWORD ret = 0;
381 if (!(scm = OpenSCManagerW(NULL, SERVICES_ACTIVE_DATABASEW, SC_MANAGER_CONNECT)))
383 fprintf(stderr, "Failed to open service control manager\n");
384 return 1;
386 if ((service = OpenServiceW(scm, msiserverW, DELETE)))
388 if (!DeleteService(service))
390 fprintf(stderr, "Failed to delete MSI service\n");
391 ret = 1;
393 CloseServiceHandle(service);
395 else if (GetLastError() != ERROR_SERVICE_DOES_NOT_EXIST)
397 fprintf(stderr, "Failed to open MSI service\n");
398 ret = 1;
400 CloseServiceHandle(scm);
401 return ret;
404 static INT DoEmbedding( LPWSTR key )
406 printf("Remote custom actions are not supported yet\n");
407 return 1;
411 * state machine to break up the command line properly
414 enum chomp_state
416 cs_whitespace,
417 cs_token,
418 cs_quote
421 static int chomp( WCHAR *str )
423 enum chomp_state state = cs_token;
424 WCHAR *p, *out;
425 int count = 1, ignore;
427 for( p = str, out = str; *p; p++ )
429 ignore = 1;
430 switch( state )
432 case cs_whitespace:
433 switch( *p )
435 case ' ':
436 break;
437 case '"':
438 state = cs_quote;
439 count++;
440 break;
441 default:
442 count++;
443 ignore = 0;
444 state = cs_token;
446 break;
448 case cs_token:
449 switch( *p )
451 case '"':
452 state = cs_quote;
453 break;
454 case ' ':
455 state = cs_whitespace;
456 *out++ = 0;
457 break;
458 default:
459 ignore = 0;
461 break;
463 case cs_quote:
464 switch( *p )
466 case '"':
467 state = cs_token;
468 break;
469 default:
470 ignore = 0;
472 break;
474 if( !ignore )
475 *out++ = *p;
478 *out = 0;
480 return count;
483 static void process_args( WCHAR *cmdline, int *pargc, WCHAR ***pargv )
485 WCHAR **argv, *p = msi_strdup(cmdline);
486 int i, n;
488 n = chomp( p );
489 argv = HeapAlloc(GetProcessHeap(), 0, sizeof (WCHAR*)*(n+1));
490 for( i=0; i<n; i++ )
492 argv[i] = p;
493 p += lstrlenW(p) + 1;
495 argv[i] = NULL;
497 *pargc = n;
498 *pargv = argv;
501 static BOOL process_args_from_reg( const WCHAR *ident, int *pargc, WCHAR ***pargv )
503 LONG r;
504 HKEY hkey;
505 DWORD sz = 0, type = 0;
506 WCHAR *buf;
507 BOOL ret = FALSE;
509 r = RegOpenKeyW(HKEY_LOCAL_MACHINE, InstallRunOnce, &hkey);
510 if(r != ERROR_SUCCESS)
511 return FALSE;
512 r = RegQueryValueExW(hkey, ident, 0, &type, 0, &sz);
513 if(r == ERROR_SUCCESS && type == REG_SZ)
515 int len = lstrlenW( *pargv[0] );
516 if (!(buf = HeapAlloc( GetProcessHeap(), 0, sz + (len + 1) * sizeof(WCHAR) )))
518 RegCloseKey( hkey );
519 return FALSE;
521 memcpy( buf, *pargv[0], len * sizeof(WCHAR) );
522 buf[len++] = ' ';
523 r = RegQueryValueExW(hkey, ident, 0, &type, (LPBYTE)(buf + len), &sz);
524 if( r == ERROR_SUCCESS )
526 process_args(buf, pargc, pargv);
527 ret = TRUE;
529 HeapFree(GetProcessHeap(), 0, buf);
531 RegCloseKey(hkey);
532 return ret;
535 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
537 int i;
538 BOOL FunctionInstall = FALSE;
539 BOOL FunctionInstallAdmin = FALSE;
540 BOOL FunctionRepair = FALSE;
541 BOOL FunctionAdvertise = FALSE;
542 BOOL FunctionPatch = FALSE;
543 BOOL FunctionDllRegisterServer = FALSE;
544 BOOL FunctionDllUnregisterServer = FALSE;
545 BOOL FunctionRegServer = FALSE;
546 BOOL FunctionUnregServer = FALSE;
547 BOOL FunctionServer = FALSE;
548 BOOL FunctionUnknown = FALSE;
550 LPWSTR PackageName = NULL;
551 LPWSTR Properties = NULL;
552 struct string_list *property_list = NULL;
554 DWORD RepairMode = 0;
556 DWORD_PTR AdvertiseMode = 0;
557 struct string_list *transform_list = NULL;
558 LANGID Language = 0;
560 DWORD LogMode = 0;
561 LPWSTR LogFileName = NULL;
562 DWORD LogAttributes = 0;
564 LPWSTR PatchFileName = NULL;
565 INSTALLTYPE InstallType = INSTALLTYPE_DEFAULT;
567 INSTALLUILEVEL InstallUILevel = INSTALLUILEVEL_FULL;
569 LPWSTR DllName = NULL;
570 DWORD ReturnCode;
571 int argc;
572 LPWSTR *argvW = NULL;
574 /* parse the command line */
575 process_args( GetCommandLineW(), &argc, &argvW );
578 * If the args begin with /@ IDENT then we need to load the real
579 * command line out of the RunOnceEntries key in the registry.
580 * We do that before starting to process the real commandline,
581 * then overwrite the commandline again.
583 if(argc>1 && msi_option_equal(argvW[1], "@"))
585 if(!process_args_from_reg( argvW[2], &argc, &argvW ))
586 return 1;
589 if (argc == 3 && msi_option_equal(argvW[1], "Embedding"))
590 return DoEmbedding( argvW[2] );
592 for(i = 1; i < argc; i++)
594 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
596 if (msi_option_equal(argvW[i], "regserver"))
598 FunctionRegServer = TRUE;
600 else if (msi_option_equal(argvW[i], "unregserver") || msi_option_equal(argvW[i], "unregister")
601 || msi_option_equal(argvW[i], "unreg"))
603 FunctionUnregServer = TRUE;
605 else if(msi_option_prefix(argvW[i], "i") || msi_option_prefix(argvW[i], "package"))
607 LPWSTR argvWi = argvW[i];
608 int argLen = (msi_option_prefix(argvW[i], "i") ? 2 : 8);
609 FunctionInstall = TRUE;
610 if(lstrlenW(argvW[i]) > argLen)
611 argvWi += argLen;
612 else
614 i++;
615 if(i >= argc)
616 ShowUsage(1);
617 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
618 argvWi = argvW[i];
620 PackageName = argvWi;
622 else if(msi_option_equal(argvW[i], "a"))
624 FunctionInstall = TRUE;
625 FunctionInstallAdmin = TRUE;
626 InstallType = INSTALLTYPE_NETWORK_IMAGE;
627 i++;
628 if(i >= argc)
629 ShowUsage(1);
630 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
631 PackageName = argvW[i];
632 StringListAppend(&property_list, ActionAdmin);
633 WINE_FIXME("Administrative installs are not currently supported\n");
635 else if(msi_option_prefix(argvW[i], "f"))
637 int j;
638 int len = lstrlenW(argvW[i]);
639 FunctionRepair = TRUE;
640 for(j = 2; j < len; j++)
642 switch(argvW[i][j])
644 case 'P':
645 case 'p':
646 RepairMode |= REINSTALLMODE_FILEMISSING;
647 break;
648 case 'O':
649 case 'o':
650 RepairMode |= REINSTALLMODE_FILEOLDERVERSION;
651 break;
652 case 'E':
653 case 'e':
654 RepairMode |= REINSTALLMODE_FILEEQUALVERSION;
655 break;
656 case 'D':
657 case 'd':
658 RepairMode |= REINSTALLMODE_FILEEXACT;
659 break;
660 case 'C':
661 case 'c':
662 RepairMode |= REINSTALLMODE_FILEVERIFY;
663 break;
664 case 'A':
665 case 'a':
666 RepairMode |= REINSTALLMODE_FILEREPLACE;
667 break;
668 case 'U':
669 case 'u':
670 RepairMode |= REINSTALLMODE_USERDATA;
671 break;
672 case 'M':
673 case 'm':
674 RepairMode |= REINSTALLMODE_MACHINEDATA;
675 break;
676 case 'S':
677 case 's':
678 RepairMode |= REINSTALLMODE_SHORTCUT;
679 break;
680 case 'V':
681 case 'v':
682 RepairMode |= REINSTALLMODE_PACKAGE;
683 break;
684 default:
685 fprintf(stderr, "Unknown option \"%c\" in Repair mode\n", argvW[i][j]);
686 break;
689 if(len == 2)
691 RepairMode = REINSTALLMODE_FILEMISSING |
692 REINSTALLMODE_FILEEQUALVERSION |
693 REINSTALLMODE_FILEVERIFY |
694 REINSTALLMODE_MACHINEDATA |
695 REINSTALLMODE_SHORTCUT;
697 i++;
698 if(i >= argc)
699 ShowUsage(1);
700 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
701 PackageName = argvW[i];
703 else if(msi_option_prefix(argvW[i], "x") || msi_option_equal(argvW[i], "uninstall"))
705 FunctionInstall = TRUE;
706 if(msi_option_prefix(argvW[i], "x")) PackageName = argvW[i]+2;
707 if(!PackageName || !PackageName[0])
709 i++;
710 if (i >= argc)
711 ShowUsage(1);
712 PackageName = argvW[i];
714 WINE_TRACE("PackageName = %s\n", wine_dbgstr_w(PackageName));
715 StringListAppend(&property_list, RemoveAll);
717 else if(msi_option_prefix(argvW[i], "j"))
719 int j;
720 int len = lstrlenW(argvW[i]);
721 FunctionAdvertise = TRUE;
722 for(j = 2; j < len; j++)
724 switch(argvW[i][j])
726 case 'U':
727 case 'u':
728 AdvertiseMode = ADVERTISEFLAGS_USERASSIGN;
729 break;
730 case 'M':
731 case 'm':
732 AdvertiseMode = ADVERTISEFLAGS_MACHINEASSIGN;
733 break;
734 default:
735 fprintf(stderr, "Unknown option \"%c\" in Advertise mode\n", argvW[i][j]);
736 break;
739 i++;
740 if(i >= argc)
741 ShowUsage(1);
742 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
743 PackageName = argvW[i];
745 else if(msi_strequal(argvW[i], "u"))
747 FunctionAdvertise = TRUE;
748 AdvertiseMode = ADVERTISEFLAGS_USERASSIGN;
749 i++;
750 if(i >= argc)
751 ShowUsage(1);
752 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
753 PackageName = argvW[i];
755 else if(msi_strequal(argvW[i], "m"))
757 FunctionAdvertise = TRUE;
758 AdvertiseMode = ADVERTISEFLAGS_MACHINEASSIGN;
759 i++;
760 if(i >= argc)
761 ShowUsage(1);
762 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
763 PackageName = argvW[i];
765 else if(msi_option_equal(argvW[i], "t"))
767 i++;
768 if(i >= argc)
769 ShowUsage(1);
770 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
771 StringListAppend(&transform_list, argvW[i]);
773 else if(msi_option_equal(argvW[i], "g"))
775 i++;
776 if(i >= argc)
777 ShowUsage(1);
778 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
779 Language = msi_atou(argvW[i]);
781 else if(msi_option_prefix(argvW[i], "l"))
783 int j;
784 int len = lstrlenW(argvW[i]);
785 for(j = 2; j < len; j++)
787 switch(argvW[i][j])
789 case 'I':
790 case 'i':
791 LogMode |= INSTALLLOGMODE_INFO;
792 break;
793 case 'W':
794 case 'w':
795 LogMode |= INSTALLLOGMODE_WARNING;
796 break;
797 case 'E':
798 case 'e':
799 LogMode |= INSTALLLOGMODE_ERROR;
800 break;
801 case 'A':
802 case 'a':
803 LogMode |= INSTALLLOGMODE_ACTIONSTART;
804 break;
805 case 'R':
806 case 'r':
807 LogMode |= INSTALLLOGMODE_ACTIONDATA;
808 break;
809 case 'U':
810 case 'u':
811 LogMode |= INSTALLLOGMODE_USER;
812 break;
813 case 'C':
814 case 'c':
815 LogMode |= INSTALLLOGMODE_COMMONDATA;
816 break;
817 case 'M':
818 case 'm':
819 LogMode |= INSTALLLOGMODE_FATALEXIT;
820 break;
821 case 'O':
822 case 'o':
823 LogMode |= INSTALLLOGMODE_OUTOFDISKSPACE;
824 break;
825 case 'P':
826 case 'p':
827 LogMode |= INSTALLLOGMODE_PROPERTYDUMP;
828 break;
829 case 'V':
830 case 'v':
831 LogMode |= INSTALLLOGMODE_VERBOSE;
832 break;
833 case '*':
834 LogMode = INSTALLLOGMODE_FATALEXIT |
835 INSTALLLOGMODE_ERROR |
836 INSTALLLOGMODE_WARNING |
837 INSTALLLOGMODE_USER |
838 INSTALLLOGMODE_INFO |
839 INSTALLLOGMODE_RESOLVESOURCE |
840 INSTALLLOGMODE_OUTOFDISKSPACE |
841 INSTALLLOGMODE_ACTIONSTART |
842 INSTALLLOGMODE_ACTIONDATA |
843 INSTALLLOGMODE_COMMONDATA |
844 INSTALLLOGMODE_PROPERTYDUMP |
845 INSTALLLOGMODE_PROGRESS |
846 INSTALLLOGMODE_INITIALIZE |
847 INSTALLLOGMODE_TERMINATE |
848 INSTALLLOGMODE_SHOWDIALOG;
849 break;
850 case '+':
851 LogAttributes |= INSTALLLOGATTRIBUTES_APPEND;
852 break;
853 case '!':
854 LogAttributes |= INSTALLLOGATTRIBUTES_FLUSHEACHLINE;
855 break;
856 default:
857 break;
860 i++;
861 if(i >= argc)
862 ShowUsage(1);
863 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
864 LogFileName = argvW[i];
865 if(MsiEnableLogW(LogMode, LogFileName, LogAttributes) != ERROR_SUCCESS)
867 fprintf(stderr, "Logging in %s (0x%08x, %u) failed\n",
868 wine_dbgstr_w(LogFileName), LogMode, LogAttributes);
869 ExitProcess(1);
872 else if(msi_option_equal(argvW[i], "p"))
874 FunctionPatch = TRUE;
875 i++;
876 if(i >= argc)
877 ShowUsage(1);
878 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
879 PatchFileName = argvW[i];
881 else if(msi_option_prefix(argvW[i], "q"))
883 if(lstrlenW(argvW[i]) == 2 || msi_strequal(argvW[i]+2, "n") ||
884 msi_strequal(argvW[i] + 2, "uiet"))
886 InstallUILevel = INSTALLUILEVEL_NONE;
888 else if(msi_strequal(argvW[i]+2, "b"))
890 InstallUILevel = INSTALLUILEVEL_BASIC;
892 else if(msi_strequal(argvW[i]+2, "r"))
894 InstallUILevel = INSTALLUILEVEL_REDUCED;
896 else if(msi_strequal(argvW[i]+2, "f"))
898 InstallUILevel = INSTALLUILEVEL_FULL|INSTALLUILEVEL_ENDDIALOG;
900 else if(msi_strequal(argvW[i]+2, "n+"))
902 InstallUILevel = INSTALLUILEVEL_NONE|INSTALLUILEVEL_ENDDIALOG;
904 else if(msi_strequal(argvW[i]+2, "b+"))
906 InstallUILevel = INSTALLUILEVEL_BASIC|INSTALLUILEVEL_ENDDIALOG;
908 else if(msi_strequal(argvW[i]+2, "b-"))
910 InstallUILevel = INSTALLUILEVEL_BASIC|INSTALLUILEVEL_PROGRESSONLY;
912 else if(msi_strequal(argvW[i]+2, "b+!"))
914 InstallUILevel = INSTALLUILEVEL_BASIC|INSTALLUILEVEL_ENDDIALOG;
915 WINE_FIXME("Unknown modifier: !\n");
917 else if(msi_strequal(argvW[i]+2, "b!"))
919 InstallUILevel = INSTALLUILEVEL_BASIC;
920 WINE_FIXME("Unknown modifier: !\n");
922 else
924 fprintf(stderr, "Unknown option \"%s\" for UI level\n",
925 wine_dbgstr_w(argvW[i]+2));
928 else if(msi_option_equal(argvW[i], "y"))
930 FunctionDllRegisterServer = TRUE;
931 i++;
932 if(i >= argc)
933 ShowUsage(1);
934 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
935 DllName = argvW[i];
937 else if(msi_option_equal(argvW[i], "z"))
939 FunctionDllUnregisterServer = TRUE;
940 i++;
941 if(i >= argc)
942 ShowUsage(1);
943 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
944 DllName = argvW[i];
946 else if(msi_option_equal(argvW[i], "help") || msi_option_equal(argvW[i], "?"))
948 ShowUsage(0);
950 else if(msi_option_equal(argvW[i], "m"))
952 FunctionUnknown = TRUE;
953 WINE_FIXME("Unknown parameter /m\n");
955 else if(msi_option_equal(argvW[i], "D"))
957 FunctionUnknown = TRUE;
958 WINE_FIXME("Unknown parameter /D\n");
960 else if (msi_option_equal(argvW[i], "V"))
962 FunctionServer = TRUE;
964 else
965 StringListAppend(&property_list, argvW[i]);
968 /* start the GUI */
969 MsiSetInternalUI(InstallUILevel, NULL);
971 Properties = build_properties( property_list );
973 if(FunctionInstallAdmin && FunctionPatch)
974 FunctionInstall = FALSE;
976 ReturnCode = 1;
977 if(FunctionInstall)
979 if(IsProductCode(PackageName))
980 ReturnCode = MsiConfigureProductExW(PackageName, 0, INSTALLSTATE_DEFAULT, Properties);
981 else
982 ReturnCode = MsiInstallProductW(PackageName, Properties);
984 else if(FunctionRepair)
986 if(IsProductCode(PackageName))
987 WINE_FIXME("Product code treatment not implemented yet\n");
988 else
989 ReturnCode = MsiReinstallProductW(PackageName, RepairMode);
991 else if(FunctionAdvertise)
993 LPWSTR Transforms = build_transforms( property_list );
994 ReturnCode = MsiAdvertiseProductW(PackageName, (LPWSTR) AdvertiseMode, Transforms, Language);
996 else if(FunctionPatch)
998 ReturnCode = MsiApplyPatchW(PatchFileName, PackageName, InstallType, Properties);
1000 else if(FunctionDllRegisterServer)
1002 ReturnCode = DoDllRegisterServer(DllName);
1004 else if(FunctionDllUnregisterServer)
1006 ReturnCode = DoDllUnregisterServer(DllName);
1008 else if (FunctionRegServer)
1010 ReturnCode = DoRegServer();
1012 else if (FunctionUnregServer)
1014 ReturnCode = DoUnregServer();
1016 else if (FunctionServer)
1018 ReturnCode = DoService();
1020 else if (FunctionUnknown)
1022 WINE_FIXME( "Unknown function, ignoring\n" );
1024 else
1025 ShowUsage(1);
1027 return ReturnCode;