msiexec.c 27 KB

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