msiexec.c 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090
  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. #define WIN32_LEAN_AND_MEAN
  22. #include <windows.h>
  23. #include <commctrl.h>
  24. #include <msi.h>
  25. #include <winsvc.h>
  26. #include <objbase.h>
  27. #include <stdio.h>
  28. #include "wine/debug.h"
  29. #include "wine/heap.h"
  30. #include "initguid.h"
  31. DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
  32. WINE_DEFAULT_DEBUG_CHANNEL(msiexec);
  33. typedef HRESULT (WINAPI *DLLREGISTERSERVER)(void);
  34. typedef HRESULT (WINAPI *DLLUNREGISTERSERVER)(void);
  35. DWORD DoService(void);
  36. struct string_list
  37. {
  38. struct string_list *next;
  39. WCHAR str[1];
  40. };
  41. static void ShowUsage(int ExitCode)
  42. {
  43. WCHAR msiexec_version[40];
  44. WCHAR filename[MAX_PATH];
  45. LPWSTR msi_res;
  46. LPWSTR msiexec_help;
  47. HMODULE hmsi = GetModuleHandleA("msi.dll");
  48. DWORD len;
  49. DWORD res;
  50. /* MsiGetFileVersion need the full path */
  51. *filename = 0;
  52. res = GetModuleFileNameW(hmsi, filename, ARRAY_SIZE(filename));
  53. if (!res)
  54. WINE_ERR("GetModuleFileName failed: %d\n", GetLastError());
  55. len = ARRAY_SIZE(msiexec_version);
  56. *msiexec_version = 0;
  57. res = MsiGetFileVersionW(filename, msiexec_version, &len, NULL, NULL);
  58. if (res)
  59. WINE_ERR("MsiGetFileVersion failed with %d\n", res);
  60. /* Return the length of the resource.
  61. No typo: The LPWSTR parameter must be a LPWSTR * for this mode */
  62. len = LoadStringW(hmsi, 10, (LPWSTR) &msi_res, 0);
  63. msi_res = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
  64. msiexec_help = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) + sizeof(msiexec_version));
  65. if (msi_res && msiexec_help) {
  66. *msi_res = 0;
  67. LoadStringW(hmsi, 10, msi_res, len + 1);
  68. swprintf(msiexec_help, len + 1 + ARRAY_SIZE(msiexec_version), msi_res, msiexec_version);
  69. MsiMessageBoxW(0, msiexec_help, NULL, 0, GetUserDefaultLangID(), 0);
  70. }
  71. HeapFree(GetProcessHeap(), 0, msi_res);
  72. HeapFree(GetProcessHeap(), 0, msiexec_help);
  73. ExitProcess(ExitCode);
  74. }
  75. static BOOL IsProductCode(LPWSTR str)
  76. {
  77. GUID ProductCode;
  78. if(lstrlenW(str) != 38)
  79. return FALSE;
  80. return ( (CLSIDFromString(str, &ProductCode) == NOERROR) );
  81. }
  82. static VOID StringListAppend(struct string_list **list, LPCWSTR str)
  83. {
  84. struct string_list *entry;
  85. entry = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(struct string_list, str[lstrlenW(str) + 1]));
  86. if(!entry)
  87. {
  88. WINE_ERR("Out of memory!\n");
  89. ExitProcess(1);
  90. }
  91. lstrcpyW(entry->str, str);
  92. entry->next = NULL;
  93. /*
  94. * Ignoring o(n^2) time complexity to add n strings for simplicity,
  95. * add the string to the end of the list to preserve the order.
  96. */
  97. while( *list )
  98. list = &(*list)->next;
  99. *list = entry;
  100. }
  101. static LPWSTR build_properties(struct string_list *property_list)
  102. {
  103. struct string_list *list;
  104. LPWSTR ret, p, value;
  105. DWORD len;
  106. BOOL needs_quote;
  107. if(!property_list)
  108. return NULL;
  109. /* count the space we need */
  110. len = 1;
  111. for(list = property_list; list; list = list->next)
  112. len += lstrlenW(list->str) + 3;
  113. ret = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
  114. /* add a space before each string, and quote the value */
  115. p = ret;
  116. for(list = property_list; list; list = list->next)
  117. {
  118. value = wcschr(list->str,'=');
  119. if(!value)
  120. continue;
  121. len = value - list->str;
  122. *p++ = ' ';
  123. memcpy(p, list->str, len * sizeof(WCHAR));
  124. p += len;
  125. *p++ = '=';
  126. /* check if the value contains spaces and maybe quote it */
  127. value++;
  128. needs_quote = wcschr(value,' ') ? 1 : 0;
  129. if(needs_quote)
  130. *p++ = '"';
  131. len = lstrlenW(value);
  132. memcpy(p, value, len * sizeof(WCHAR));
  133. p += len;
  134. if(needs_quote)
  135. *p++ = '"';
  136. }
  137. *p = 0;
  138. WINE_TRACE("properties -> %s\n", wine_dbgstr_w(ret) );
  139. return ret;
  140. }
  141. static LPWSTR build_transforms(struct string_list *transform_list)
  142. {
  143. struct string_list *list;
  144. LPWSTR ret, p;
  145. DWORD len;
  146. /* count the space we need */
  147. len = 1;
  148. for(list = transform_list; list; list = list->next)
  149. len += lstrlenW(list->str) + 1;
  150. ret = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
  151. /* add all the transforms with a semicolon between each one */
  152. p = ret;
  153. for(list = transform_list; list; list = list->next)
  154. {
  155. len = lstrlenW(list->str);
  156. lstrcpynW(p, list->str, len );
  157. p += len;
  158. if(list->next)
  159. *p++ = ';';
  160. }
  161. *p = 0;
  162. return ret;
  163. }
  164. static DWORD msi_atou(LPCWSTR str)
  165. {
  166. DWORD ret = 0;
  167. while(*str >= '0' && *str <= '9')
  168. {
  169. ret *= 10;
  170. ret += (*str - '0');
  171. str++;
  172. }
  173. return ret;
  174. }
  175. /* str1 is the same as str2, ignoring case */
  176. static BOOL msi_strequal(LPCWSTR str1, LPCSTR str2)
  177. {
  178. DWORD len, ret;
  179. LPWSTR strW;
  180. len = MultiByteToWideChar( CP_ACP, 0, str2, -1, NULL, 0);
  181. if( !len )
  182. return FALSE;
  183. if( lstrlenW(str1) != (len-1) )
  184. return FALSE;
  185. strW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*len);
  186. MultiByteToWideChar( CP_ACP, 0, str2, -1, strW, len);
  187. ret = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, str1, len, strW, len);
  188. HeapFree(GetProcessHeap(), 0, strW);
  189. return (ret == CSTR_EQUAL);
  190. }
  191. /* prefix is hyphen or dash, and str1 is the same as str2, ignoring case */
  192. static BOOL msi_option_equal(LPCWSTR str1, LPCSTR str2)
  193. {
  194. if (str1[0] != '/' && str1[0] != '-')
  195. return FALSE;
  196. /* skip over the hyphen or slash */
  197. return msi_strequal(str1 + 1, str2);
  198. }
  199. /* str2 is at the beginning of str1, ignoring case */
  200. static BOOL msi_strprefix(LPCWSTR str1, LPCSTR str2)
  201. {
  202. DWORD len, ret;
  203. LPWSTR strW;
  204. len = MultiByteToWideChar( CP_ACP, 0, str2, -1, NULL, 0);
  205. if( !len )
  206. return FALSE;
  207. if( lstrlenW(str1) < (len-1) )
  208. return FALSE;
  209. strW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*len);
  210. MultiByteToWideChar( CP_ACP, 0, str2, -1, strW, len);
  211. ret = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, str1, len-1, strW, len-1);
  212. HeapFree(GetProcessHeap(), 0, strW);
  213. return (ret == CSTR_EQUAL);
  214. }
  215. /* prefix is hyphen or dash, and str2 is at the beginning of str1, ignoring case */
  216. static BOOL msi_option_prefix(LPCWSTR str1, LPCSTR str2)
  217. {
  218. if (str1[0] != '/' && str1[0] != '-')
  219. return FALSE;
  220. /* skip over the hyphen or slash */
  221. return msi_strprefix(str1 + 1, str2);
  222. }
  223. static VOID *LoadProc(LPCWSTR DllName, LPCSTR ProcName, HMODULE* DllHandle)
  224. {
  225. VOID* (*proc)(void);
  226. *DllHandle = LoadLibraryExW(DllName, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
  227. if(!*DllHandle)
  228. {
  229. fprintf(stderr, "Unable to load dll %s\n", wine_dbgstr_w(DllName));
  230. ExitProcess(1);
  231. }
  232. proc = (VOID *) GetProcAddress(*DllHandle, ProcName);
  233. if(!proc)
  234. {
  235. fprintf(stderr, "Dll %s does not implement function %s\n",
  236. wine_dbgstr_w(DllName), ProcName);
  237. FreeLibrary(*DllHandle);
  238. ExitProcess(1);
  239. }
  240. return proc;
  241. }
  242. static DWORD DoDllRegisterServer(LPCWSTR DllName)
  243. {
  244. HRESULT hr;
  245. DLLREGISTERSERVER pfDllRegisterServer = NULL;
  246. HMODULE DllHandle = NULL;
  247. pfDllRegisterServer = LoadProc(DllName, "DllRegisterServer", &DllHandle);
  248. hr = pfDllRegisterServer();
  249. if(FAILED(hr))
  250. {
  251. fprintf(stderr, "Failed to register dll %s\n", wine_dbgstr_w(DllName));
  252. return 1;
  253. }
  254. printf("Successfully registered dll %s\n", wine_dbgstr_w(DllName));
  255. if(DllHandle)
  256. FreeLibrary(DllHandle);
  257. return 0;
  258. }
  259. static DWORD DoDllUnregisterServer(LPCWSTR DllName)
  260. {
  261. HRESULT hr;
  262. DLLUNREGISTERSERVER pfDllUnregisterServer = NULL;
  263. HMODULE DllHandle = NULL;
  264. pfDllUnregisterServer = LoadProc(DllName, "DllUnregisterServer", &DllHandle);
  265. hr = pfDllUnregisterServer();
  266. if(FAILED(hr))
  267. {
  268. fprintf(stderr, "Failed to unregister dll %s\n", wine_dbgstr_w(DllName));
  269. return 1;
  270. }
  271. printf("Successfully unregistered dll %s\n", wine_dbgstr_w(DllName));
  272. if(DllHandle)
  273. FreeLibrary(DllHandle);
  274. return 0;
  275. }
  276. static DWORD DoRegServer(void)
  277. {
  278. SC_HANDLE scm, service;
  279. WCHAR path[MAX_PATH+12];
  280. DWORD len, ret = 0;
  281. if (!(scm = OpenSCManagerW(NULL, SERVICES_ACTIVE_DATABASEW, SC_MANAGER_CREATE_SERVICE)))
  282. {
  283. fprintf(stderr, "Failed to open the service control manager.\n");
  284. return 1;
  285. }
  286. len = GetSystemDirectoryW(path, MAX_PATH);
  287. lstrcpyW(path + len, L"\\msiexec /V");
  288. if ((service = CreateServiceW(scm, L"MSIServer", L"MSIServer", GENERIC_ALL,
  289. SERVICE_WIN32_SHARE_PROCESS, SERVICE_DEMAND_START,
  290. SERVICE_ERROR_NORMAL, path, NULL, NULL, NULL, NULL, NULL)))
  291. {
  292. CloseServiceHandle(service);
  293. }
  294. else if (GetLastError() != ERROR_SERVICE_EXISTS)
  295. {
  296. fprintf(stderr, "Failed to create MSI service\n");
  297. ret = 1;
  298. }
  299. CloseServiceHandle(scm);
  300. return ret;
  301. }
  302. static DWORD DoUnregServer(void)
  303. {
  304. SC_HANDLE scm, service;
  305. DWORD ret = 0;
  306. if (!(scm = OpenSCManagerW(NULL, SERVICES_ACTIVE_DATABASEW, SC_MANAGER_CONNECT)))
  307. {
  308. fprintf(stderr, "Failed to open service control manager\n");
  309. return 1;
  310. }
  311. if ((service = OpenServiceW(scm, L"MSIServer", DELETE)))
  312. {
  313. if (!DeleteService(service))
  314. {
  315. fprintf(stderr, "Failed to delete MSI service\n");
  316. ret = 1;
  317. }
  318. CloseServiceHandle(service);
  319. }
  320. else if (GetLastError() != ERROR_SERVICE_DOES_NOT_EXIST)
  321. {
  322. fprintf(stderr, "Failed to open MSI service\n");
  323. ret = 1;
  324. }
  325. CloseServiceHandle(scm);
  326. return ret;
  327. }
  328. extern UINT CDECL __wine_msi_call_dll_function(DWORD client_pid, const GUID *guid);
  329. static DWORD client_pid;
  330. static DWORD CALLBACK custom_action_thread(void *arg)
  331. {
  332. GUID guid = *(GUID *)arg;
  333. heap_free(arg);
  334. return __wine_msi_call_dll_function(client_pid, &guid);
  335. }
  336. static int custom_action_server(const WCHAR *arg)
  337. {
  338. GUID guid, *thread_guid;
  339. DWORD64 thread64;
  340. WCHAR buffer[24];
  341. HANDLE thread;
  342. HANDLE pipe;
  343. DWORD size;
  344. TRACE("%s\n", debugstr_w(arg));
  345. if (!(client_pid = wcstol(arg, NULL, 10)))
  346. {
  347. ERR("Invalid parameter %s\n", debugstr_w(arg));
  348. return 1;
  349. }
  350. swprintf(buffer, ARRAY_SIZE(buffer), L"\\\\.\\pipe\\msica_%x_%d", client_pid, sizeof(void *) * 8);
  351. pipe = CreateFileW(buffer, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
  352. if (pipe == INVALID_HANDLE_VALUE)
  353. {
  354. ERR("Failed to create custom action server pipe: %u\n", GetLastError());
  355. return GetLastError();
  356. }
  357. /* We need this to unmarshal streams, and some apps expect it to be present. */
  358. CoInitializeEx(NULL, COINIT_MULTITHREADED);
  359. while (ReadFile(pipe, &guid, sizeof(guid), &size, NULL) && size == sizeof(guid))
  360. {
  361. if (IsEqualGUID(&guid, &GUID_NULL))
  362. {
  363. /* package closed; time to shut down */
  364. CoUninitialize();
  365. return 0;
  366. }
  367. thread_guid = heap_alloc(sizeof(GUID));
  368. memcpy(thread_guid, &guid, sizeof(GUID));
  369. thread = CreateThread(NULL, 0, custom_action_thread, thread_guid, 0, NULL);
  370. /* give the thread handle to the client to wait on, since we might have
  371. * to run a nested action and can't block during this one */
  372. thread64 = (DWORD_PTR)thread;
  373. if (!WriteFile(pipe, &thread64, sizeof(thread64), &size, NULL) || size != sizeof(thread64))
  374. {
  375. ERR("Failed to write to custom action server pipe: %u\n", GetLastError());
  376. CoUninitialize();
  377. return GetLastError();
  378. }
  379. }
  380. ERR("Failed to read from custom action server pipe: %u\n", GetLastError());
  381. CoUninitialize();
  382. return GetLastError();
  383. }
  384. /*
  385. * state machine to break up the command line properly
  386. */
  387. enum chomp_state
  388. {
  389. CS_WHITESPACE,
  390. CS_TOKEN,
  391. CS_QUOTE
  392. };
  393. static int chomp( const WCHAR *in, WCHAR *out )
  394. {
  395. enum chomp_state state = CS_TOKEN;
  396. const WCHAR *p;
  397. int count = 1;
  398. BOOL ignore;
  399. for (p = in; *p; p++)
  400. {
  401. ignore = TRUE;
  402. switch (state)
  403. {
  404. case CS_WHITESPACE:
  405. switch (*p)
  406. {
  407. case ' ':
  408. break;
  409. case '"':
  410. state = CS_QUOTE;
  411. count++;
  412. break;
  413. default:
  414. count++;
  415. ignore = FALSE;
  416. state = CS_TOKEN;
  417. }
  418. break;
  419. case CS_TOKEN:
  420. switch (*p)
  421. {
  422. case '"':
  423. state = CS_QUOTE;
  424. break;
  425. case ' ':
  426. state = CS_WHITESPACE;
  427. if (out) *out++ = 0;
  428. break;
  429. default:
  430. if (p > in && p[-1] == '"')
  431. {
  432. if (out) *out++ = 0;
  433. count++;
  434. }
  435. ignore = FALSE;
  436. }
  437. break;
  438. case CS_QUOTE:
  439. switch (*p)
  440. {
  441. case '"':
  442. state = CS_TOKEN;
  443. break;
  444. default:
  445. ignore = FALSE;
  446. }
  447. break;
  448. }
  449. if (!ignore && out) *out++ = *p;
  450. }
  451. if (out) *out = 0;
  452. return count;
  453. }
  454. static void process_args( WCHAR *cmdline, int *pargc, WCHAR ***pargv )
  455. {
  456. WCHAR **argv, *p;
  457. int i, count;
  458. *pargc = 0;
  459. *pargv = NULL;
  460. count = chomp( cmdline, NULL );
  461. if (!(p = HeapAlloc( GetProcessHeap(), 0, (lstrlenW(cmdline) + count + 1) * sizeof(WCHAR) )))
  462. return;
  463. count = chomp( cmdline, p );
  464. if (!(argv = HeapAlloc( GetProcessHeap(), 0, (count + 1) * sizeof(WCHAR *) )))
  465. {
  466. HeapFree( GetProcessHeap(), 0, p );
  467. return;
  468. }
  469. for (i = 0; i < count; i++)
  470. {
  471. argv[i] = p;
  472. p += lstrlenW( p ) + 1;
  473. }
  474. argv[i] = NULL;
  475. *pargc = count;
  476. *pargv = argv;
  477. }
  478. static BOOL process_args_from_reg( const WCHAR *ident, int *pargc, WCHAR ***pargv )
  479. {
  480. LONG r;
  481. HKEY hkey;
  482. DWORD sz = 0, type = 0;
  483. WCHAR *buf;
  484. BOOL ret = FALSE;
  485. r = RegOpenKeyW(HKEY_LOCAL_MACHINE,
  486. L"Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\RunOnceEntries", &hkey);
  487. if(r != ERROR_SUCCESS)
  488. return FALSE;
  489. r = RegQueryValueExW(hkey, ident, 0, &type, 0, &sz);
  490. if(r == ERROR_SUCCESS && type == REG_SZ)
  491. {
  492. int len = lstrlenW( *pargv[0] );
  493. if (!(buf = HeapAlloc( GetProcessHeap(), 0, sz + (len + 1) * sizeof(WCHAR) )))
  494. {
  495. RegCloseKey( hkey );
  496. return FALSE;
  497. }
  498. memcpy( buf, *pargv[0], len * sizeof(WCHAR) );
  499. buf[len++] = ' ';
  500. r = RegQueryValueExW(hkey, ident, 0, &type, (LPBYTE)(buf + len), &sz);
  501. if( r == ERROR_SUCCESS )
  502. {
  503. process_args(buf, pargc, pargv);
  504. ret = TRUE;
  505. }
  506. HeapFree(GetProcessHeap(), 0, buf);
  507. }
  508. RegCloseKey(hkey);
  509. return ret;
  510. }
  511. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  512. {
  513. int i;
  514. BOOL FunctionInstall = FALSE;
  515. BOOL FunctionInstallAdmin = FALSE;
  516. BOOL FunctionRepair = FALSE;
  517. BOOL FunctionAdvertise = FALSE;
  518. BOOL FunctionPatch = FALSE;
  519. BOOL FunctionDllRegisterServer = FALSE;
  520. BOOL FunctionDllUnregisterServer = FALSE;
  521. BOOL FunctionRegServer = FALSE;
  522. BOOL FunctionUnregServer = FALSE;
  523. BOOL FunctionServer = FALSE;
  524. BOOL FunctionUnknown = FALSE;
  525. LPWSTR PackageName = NULL;
  526. LPWSTR Properties = NULL;
  527. struct string_list *property_list = NULL;
  528. DWORD RepairMode = 0;
  529. DWORD_PTR AdvertiseMode = 0;
  530. struct string_list *transform_list = NULL;
  531. LANGID Language = 0;
  532. DWORD LogMode = 0;
  533. LPWSTR LogFileName = NULL;
  534. DWORD LogAttributes = 0;
  535. LPWSTR PatchFileName = NULL;
  536. INSTALLTYPE InstallType = INSTALLTYPE_DEFAULT;
  537. INSTALLUILEVEL InstallUILevel = INSTALLUILEVEL_FULL;
  538. LPWSTR DllName = NULL;
  539. DWORD ReturnCode;
  540. int argc;
  541. LPWSTR *argvW = NULL;
  542. InitCommonControls();
  543. /* parse the command line */
  544. process_args( GetCommandLineW(), &argc, &argvW );
  545. /*
  546. * If the args begin with /@ IDENT then we need to load the real
  547. * command line out of the RunOnceEntries key in the registry.
  548. * We do that before starting to process the real commandline,
  549. * then overwrite the commandline again.
  550. */
  551. if(argc>1 && msi_option_equal(argvW[1], "@"))
  552. {
  553. if(!process_args_from_reg( argvW[2], &argc, &argvW ))
  554. return 1;
  555. }
  556. if (argc == 3 && msi_option_equal(argvW[1], "Embedding"))
  557. return custom_action_server(argvW[2]);
  558. for(i = 1; i < argc; i++)
  559. {
  560. WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
  561. if (msi_option_equal(argvW[i], "regserver"))
  562. {
  563. FunctionRegServer = TRUE;
  564. }
  565. else if (msi_option_equal(argvW[i], "unregserver") || msi_option_equal(argvW[i], "unregister")
  566. || msi_option_equal(argvW[i], "unreg"))
  567. {
  568. FunctionUnregServer = TRUE;
  569. }
  570. else if(msi_option_prefix(argvW[i], "i") || msi_option_prefix(argvW[i], "package"))
  571. {
  572. LPWSTR argvWi = argvW[i];
  573. int argLen = (msi_option_prefix(argvW[i], "i") ? 2 : 8);
  574. FunctionInstall = TRUE;
  575. if(lstrlenW(argvW[i]) > argLen)
  576. argvWi += argLen;
  577. else
  578. {
  579. i++;
  580. if(i >= argc)
  581. ShowUsage(1);
  582. WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
  583. argvWi = argvW[i];
  584. }
  585. PackageName = argvWi;
  586. }
  587. else if(msi_option_equal(argvW[i], "a"))
  588. {
  589. FunctionInstall = TRUE;
  590. FunctionInstallAdmin = TRUE;
  591. InstallType = INSTALLTYPE_NETWORK_IMAGE;
  592. i++;
  593. if(i >= argc)
  594. ShowUsage(1);
  595. WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
  596. PackageName = argvW[i];
  597. StringListAppend(&property_list, L"ACTION=ADMIN");
  598. WINE_FIXME("Administrative installs are not currently supported\n");
  599. }
  600. else if(msi_option_prefix(argvW[i], "f"))
  601. {
  602. int j;
  603. int len = lstrlenW(argvW[i]);
  604. FunctionRepair = TRUE;
  605. for(j = 2; j < len; j++)
  606. {
  607. switch(argvW[i][j])
  608. {
  609. case 'P':
  610. case 'p':
  611. RepairMode |= REINSTALLMODE_FILEMISSING;
  612. break;
  613. case 'O':
  614. case 'o':
  615. RepairMode |= REINSTALLMODE_FILEOLDERVERSION;
  616. break;
  617. case 'E':
  618. case 'e':
  619. RepairMode |= REINSTALLMODE_FILEEQUALVERSION;
  620. break;
  621. case 'D':
  622. case 'd':
  623. RepairMode |= REINSTALLMODE_FILEEXACT;
  624. break;
  625. case 'C':
  626. case 'c':
  627. RepairMode |= REINSTALLMODE_FILEVERIFY;
  628. break;
  629. case 'A':
  630. case 'a':
  631. RepairMode |= REINSTALLMODE_FILEREPLACE;
  632. break;
  633. case 'U':
  634. case 'u':
  635. RepairMode |= REINSTALLMODE_USERDATA;
  636. break;
  637. case 'M':
  638. case 'm':
  639. RepairMode |= REINSTALLMODE_MACHINEDATA;
  640. break;
  641. case 'S':
  642. case 's':
  643. RepairMode |= REINSTALLMODE_SHORTCUT;
  644. break;
  645. case 'V':
  646. case 'v':
  647. RepairMode |= REINSTALLMODE_PACKAGE;
  648. break;
  649. default:
  650. fprintf(stderr, "Unknown option \"%c\" in Repair mode\n", argvW[i][j]);
  651. break;
  652. }
  653. }
  654. if(len == 2)
  655. {
  656. RepairMode = REINSTALLMODE_FILEMISSING |
  657. REINSTALLMODE_FILEEQUALVERSION |
  658. REINSTALLMODE_FILEVERIFY |
  659. REINSTALLMODE_MACHINEDATA |
  660. REINSTALLMODE_SHORTCUT;
  661. }
  662. i++;
  663. if(i >= argc)
  664. ShowUsage(1);
  665. WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
  666. PackageName = argvW[i];
  667. }
  668. else if(msi_option_prefix(argvW[i], "x") || msi_option_equal(argvW[i], "uninstall"))
  669. {
  670. FunctionInstall = TRUE;
  671. if(msi_option_prefix(argvW[i], "x")) PackageName = argvW[i]+2;
  672. if(!PackageName || !PackageName[0])
  673. {
  674. i++;
  675. if (i >= argc)
  676. ShowUsage(1);
  677. PackageName = argvW[i];
  678. }
  679. WINE_TRACE("PackageName = %s\n", wine_dbgstr_w(PackageName));
  680. StringListAppend(&property_list, L"REMOVE=ALL");
  681. }
  682. else if(msi_option_prefix(argvW[i], "j"))
  683. {
  684. int j;
  685. int len = lstrlenW(argvW[i]);
  686. FunctionAdvertise = TRUE;
  687. for(j = 2; j < len; j++)
  688. {
  689. switch(argvW[i][j])
  690. {
  691. case 'U':
  692. case 'u':
  693. AdvertiseMode = ADVERTISEFLAGS_USERASSIGN;
  694. break;
  695. case 'M':
  696. case 'm':
  697. AdvertiseMode = ADVERTISEFLAGS_MACHINEASSIGN;
  698. break;
  699. default:
  700. fprintf(stderr, "Unknown option \"%c\" in Advertise mode\n", argvW[i][j]);
  701. break;
  702. }
  703. }
  704. i++;
  705. if(i >= argc)
  706. ShowUsage(1);
  707. WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
  708. PackageName = argvW[i];
  709. }
  710. else if(msi_strequal(argvW[i], "u"))
  711. {
  712. FunctionAdvertise = TRUE;
  713. AdvertiseMode = ADVERTISEFLAGS_USERASSIGN;
  714. i++;
  715. if(i >= argc)
  716. ShowUsage(1);
  717. WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
  718. PackageName = argvW[i];
  719. }
  720. else if(msi_strequal(argvW[i], "m"))
  721. {
  722. FunctionAdvertise = TRUE;
  723. AdvertiseMode = ADVERTISEFLAGS_MACHINEASSIGN;
  724. i++;
  725. if(i >= argc)
  726. ShowUsage(1);
  727. WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
  728. PackageName = argvW[i];
  729. }
  730. else if(msi_option_equal(argvW[i], "t"))
  731. {
  732. i++;
  733. if(i >= argc)
  734. ShowUsage(1);
  735. WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
  736. StringListAppend(&transform_list, argvW[i]);
  737. }
  738. else if(msi_option_equal(argvW[i], "g"))
  739. {
  740. i++;
  741. if(i >= argc)
  742. ShowUsage(1);
  743. WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
  744. Language = msi_atou(argvW[i]);
  745. }
  746. else if(msi_option_prefix(argvW[i], "l"))
  747. {
  748. int j;
  749. int len = lstrlenW(argvW[i]);
  750. for(j = 2; j < len; j++)
  751. {
  752. switch(argvW[i][j])
  753. {
  754. case 'I':
  755. case 'i':
  756. LogMode |= INSTALLLOGMODE_INFO;
  757. break;
  758. case 'W':
  759. case 'w':
  760. LogMode |= INSTALLLOGMODE_WARNING;
  761. break;
  762. case 'E':
  763. case 'e':
  764. LogMode |= INSTALLLOGMODE_ERROR;
  765. break;
  766. case 'A':
  767. case 'a':
  768. LogMode |= INSTALLLOGMODE_ACTIONSTART;
  769. break;
  770. case 'R':
  771. case 'r':
  772. LogMode |= INSTALLLOGMODE_ACTIONDATA;
  773. break;
  774. case 'U':
  775. case 'u':
  776. LogMode |= INSTALLLOGMODE_USER;
  777. break;
  778. case 'C':
  779. case 'c':
  780. LogMode |= INSTALLLOGMODE_COMMONDATA;
  781. break;
  782. case 'M':
  783. case 'm':
  784. LogMode |= INSTALLLOGMODE_FATALEXIT;
  785. break;
  786. case 'O':
  787. case 'o':
  788. LogMode |= INSTALLLOGMODE_OUTOFDISKSPACE;
  789. break;
  790. case 'P':
  791. case 'p':
  792. LogMode |= INSTALLLOGMODE_PROPERTYDUMP;
  793. break;
  794. case 'V':
  795. case 'v':
  796. LogMode |= INSTALLLOGMODE_VERBOSE;
  797. break;
  798. case '*':
  799. LogMode = INSTALLLOGMODE_FATALEXIT |
  800. INSTALLLOGMODE_ERROR |
  801. INSTALLLOGMODE_WARNING |
  802. INSTALLLOGMODE_USER |
  803. INSTALLLOGMODE_INFO |
  804. INSTALLLOGMODE_RESOLVESOURCE |
  805. INSTALLLOGMODE_OUTOFDISKSPACE |
  806. INSTALLLOGMODE_ACTIONSTART |
  807. INSTALLLOGMODE_ACTIONDATA |
  808. INSTALLLOGMODE_COMMONDATA |
  809. INSTALLLOGMODE_PROPERTYDUMP |
  810. INSTALLLOGMODE_PROGRESS |
  811. INSTALLLOGMODE_INITIALIZE |
  812. INSTALLLOGMODE_TERMINATE |
  813. INSTALLLOGMODE_SHOWDIALOG;
  814. break;
  815. case '+':
  816. LogAttributes |= INSTALLLOGATTRIBUTES_APPEND;
  817. break;
  818. case '!':
  819. LogAttributes |= INSTALLLOGATTRIBUTES_FLUSHEACHLINE;
  820. break;
  821. default:
  822. break;
  823. }
  824. }
  825. i++;
  826. if(i >= argc)
  827. ShowUsage(1);
  828. WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
  829. LogFileName = argvW[i];
  830. if(MsiEnableLogW(LogMode, LogFileName, LogAttributes) != ERROR_SUCCESS)
  831. {
  832. fprintf(stderr, "Logging in %s (0x%08x, %u) failed\n",
  833. wine_dbgstr_w(LogFileName), LogMode, LogAttributes);
  834. ExitProcess(1);
  835. }
  836. }
  837. else if(msi_option_equal(argvW[i], "p") || msi_option_equal(argvW[i], "update"))
  838. {
  839. FunctionPatch = TRUE;
  840. i++;
  841. if(i >= argc)
  842. ShowUsage(1);
  843. WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
  844. PatchFileName = argvW[i];
  845. }
  846. else if(msi_option_prefix(argvW[i], "q"))
  847. {
  848. if(lstrlenW(argvW[i]) == 2 || msi_strequal(argvW[i]+2, "n") ||
  849. msi_strequal(argvW[i] + 2, "uiet"))
  850. {
  851. InstallUILevel = INSTALLUILEVEL_NONE;
  852. }
  853. else if(msi_strequal(argvW[i]+2, "r"))
  854. {
  855. InstallUILevel = INSTALLUILEVEL_REDUCED;
  856. }
  857. else if(msi_strequal(argvW[i]+2, "f"))
  858. {
  859. InstallUILevel = INSTALLUILEVEL_FULL|INSTALLUILEVEL_ENDDIALOG;
  860. }
  861. else if(msi_strequal(argvW[i]+2, "n+"))
  862. {
  863. InstallUILevel = INSTALLUILEVEL_NONE|INSTALLUILEVEL_ENDDIALOG;
  864. }
  865. else if(msi_strprefix(argvW[i]+2, "b"))
  866. {
  867. const WCHAR *ptr = argvW[i] + 3;
  868. InstallUILevel = INSTALLUILEVEL_BASIC;
  869. while (*ptr)
  870. {
  871. if (msi_strprefix(ptr, "+"))
  872. InstallUILevel |= INSTALLUILEVEL_ENDDIALOG;
  873. if (msi_strprefix(ptr, "-"))
  874. InstallUILevel |= INSTALLUILEVEL_PROGRESSONLY;
  875. if (msi_strprefix(ptr, "!"))
  876. {
  877. WINE_FIXME("Unhandled modifier: !\n");
  878. InstallUILevel |= INSTALLUILEVEL_HIDECANCEL;
  879. }
  880. ptr++;
  881. }
  882. }
  883. else
  884. {
  885. fprintf(stderr, "Unknown option \"%s\" for UI level\n",
  886. wine_dbgstr_w(argvW[i]+2));
  887. }
  888. }
  889. else if(msi_option_equal(argvW[i], "passive"))
  890. {
  891. InstallUILevel = INSTALLUILEVEL_BASIC|INSTALLUILEVEL_PROGRESSONLY|INSTALLUILEVEL_HIDECANCEL;
  892. StringListAppend(&property_list, L"REBOOTPROMPT=\"S\"");
  893. }
  894. else if(msi_option_equal(argvW[i], "y"))
  895. {
  896. FunctionDllRegisterServer = TRUE;
  897. i++;
  898. if(i >= argc)
  899. ShowUsage(1);
  900. WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
  901. DllName = argvW[i];
  902. }
  903. else if(msi_option_equal(argvW[i], "z"))
  904. {
  905. FunctionDllUnregisterServer = TRUE;
  906. i++;
  907. if(i >= argc)
  908. ShowUsage(1);
  909. WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
  910. DllName = argvW[i];
  911. }
  912. else if(msi_option_equal(argvW[i], "help") || msi_option_equal(argvW[i], "?"))
  913. {
  914. ShowUsage(0);
  915. }
  916. else if(msi_option_equal(argvW[i], "m"))
  917. {
  918. FunctionUnknown = TRUE;
  919. WINE_FIXME("Unknown parameter /m\n");
  920. }
  921. else if(msi_option_equal(argvW[i], "D"))
  922. {
  923. FunctionUnknown = TRUE;
  924. WINE_FIXME("Unknown parameter /D\n");
  925. }
  926. else if (msi_option_equal(argvW[i], "V"))
  927. {
  928. FunctionServer = TRUE;
  929. }
  930. else
  931. StringListAppend(&property_list, argvW[i]);
  932. }
  933. /* start the GUI */
  934. MsiSetInternalUI(InstallUILevel, NULL);
  935. Properties = build_properties( property_list );
  936. if(FunctionInstallAdmin && FunctionPatch)
  937. FunctionInstall = FALSE;
  938. ReturnCode = 1;
  939. if(FunctionInstall)
  940. {
  941. if(IsProductCode(PackageName))
  942. ReturnCode = MsiConfigureProductExW(PackageName, 0, INSTALLSTATE_DEFAULT, Properties);
  943. else
  944. ReturnCode = MsiInstallProductW(PackageName, Properties);
  945. }
  946. else if(FunctionRepair)
  947. {
  948. if(IsProductCode(PackageName))
  949. WINE_FIXME("Product code treatment not implemented yet\n");
  950. else
  951. ReturnCode = MsiReinstallProductW(PackageName, RepairMode);
  952. }
  953. else if(FunctionAdvertise)
  954. {
  955. LPWSTR Transforms = build_transforms( property_list );
  956. ReturnCode = MsiAdvertiseProductW(PackageName, (LPWSTR) AdvertiseMode, Transforms, Language);
  957. }
  958. else if(FunctionPatch)
  959. {
  960. ReturnCode = MsiApplyPatchW(PatchFileName, PackageName, InstallType, Properties);
  961. }
  962. else if(FunctionDllRegisterServer)
  963. {
  964. ReturnCode = DoDllRegisterServer(DllName);
  965. }
  966. else if(FunctionDllUnregisterServer)
  967. {
  968. ReturnCode = DoDllUnregisterServer(DllName);
  969. }
  970. else if (FunctionRegServer)
  971. {
  972. ReturnCode = DoRegServer();
  973. }
  974. else if (FunctionUnregServer)
  975. {
  976. ReturnCode = DoUnregServer();
  977. }
  978. else if (FunctionServer)
  979. {
  980. ReturnCode = DoService();
  981. }
  982. else if (FunctionUnknown)
  983. {
  984. WINE_FIXME( "Unknown function, ignoring\n" );
  985. }
  986. else
  987. ShowUsage(1);
  988. return ReturnCode;
  989. }