2 * Advpack install functions
4 * Copyright 2006 James Hawkins
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #include "wine/debug.h"
34 #include "wine/unicode.h"
35 #include "advpack_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(advpack);
39 #define SPAPI_ERROR 0xE0000000L
40 #define SPAPI_PREFIX 0x800F0000L
41 #define SPAPI_MASK 0xFFFFL
42 #define HRESULT_FROM_SPAPI(x) ((x & SPAPI_MASK) | SPAPI_PREFIX)
44 #define ADV_HRESULT(x) ((x & SPAPI_ERROR) ? HRESULT_FROM_SPAPI(x) : HRESULT_FROM_WIN32(x))
49 /* contains information about a specific install instance */
50 typedef struct _ADVInfo
60 typedef HRESULT (*iterate_fields_func)(HINF hinf, PCWSTR field, void *arg);
62 /* Advanced INF commands */
63 static const WCHAR CheckAdminRights[] = {
64 'C','h','e','c','k','A','d','m','i','n','R','i','g','h','t','s',0
66 static const WCHAR DelDirs[] = {'D','e','l','D','i','r','s',0};
67 static const WCHAR PerUserInstall[] = {'P','e','r','U','s','e','r','I','n','s','t','a','l','l',0};
68 static const WCHAR RegisterOCXs[] = {'R','e','g','i','s','t','e','r','O','C','X','s',0};
69 static const WCHAR RunPreSetupCommands[] = {
70 'R','u','n','P','r','e','S','e','t','u','p','C','o','m','m','a','n','d','s',0
72 static const WCHAR RunPostSetupCommands[] = {
73 'R','u','n','P','o','s','t','S','e','t','u','p','C','o','m','m','a','n','d','s',0
76 /* Advanced INF callbacks */
77 static HRESULT del_dirs_callback(HINF hinf, PCWSTR field, void *arg)
83 BOOL ok = SetupFindFirstLineW(hinf, field, NULL, &context);
85 for (; ok; ok = SetupFindNextLine(&context, &context))
87 WCHAR directory[MAX_INF_STRING_LENGTH];
89 if (!SetupGetLineTextW(&context, NULL, NULL, NULL, directory,
90 MAX_INF_STRING_LENGTH, &size))
93 if (DelNodeW(directory, ADN_DEL_IF_EMPTY))
100 static HRESULT per_user_install_callback(HINF hinf, PCWSTR field, void *arg)
102 PERUSERSECTIONW per_user;
106 static const WCHAR disp_name[] = {'D','i','s','p','l','a','y','N','a','m','e',0};
107 static const WCHAR version[] = {'V','e','r','s','i','o','n',0};
108 static const WCHAR is_installed[] = {'I','s','I','n','s','t','a','l','l','e','d',0};
109 static const WCHAR comp_id[] = {'C','o','m','p','o','n','e','n','t','I','D',0};
110 static const WCHAR guid[] = {'G','U','I','D',0};
111 static const WCHAR locale[] = {'L','o','c','a','l','e',0};
112 static const WCHAR stub_path[] = {'S','t','u','b','P','a','t','h',0};
114 per_user.bRollback = FALSE;
115 per_user.dwIsInstalled = 0;
117 SetupGetLineTextW(NULL, hinf, field, disp_name, per_user.szDispName,
118 sizeof(per_user.szDispName) / sizeof(WCHAR), &size);
120 SetupGetLineTextW(NULL, hinf, field, version, per_user.szVersion,
121 sizeof(per_user.szVersion) / sizeof(WCHAR), &size);
123 if (SetupFindFirstLineW(hinf, field, is_installed, &context))
125 SetupGetIntField(&context, 1, (PINT)&per_user.dwIsInstalled);
128 SetupGetLineTextW(NULL, hinf, field, comp_id, per_user.szCompID,
129 sizeof(per_user.szCompID) / sizeof(WCHAR), &size);
131 SetupGetLineTextW(NULL, hinf, field, guid, per_user.szGUID,
132 sizeof(per_user.szGUID) / sizeof(WCHAR), &size);
134 SetupGetLineTextW(NULL, hinf, field, locale, per_user.szLocale,
135 sizeof(per_user.szLocale) / sizeof(WCHAR), &size);
137 SetupGetLineTextW(NULL, hinf, field, stub_path, per_user.szStub,
138 sizeof(per_user.szStub) / sizeof(WCHAR), &size);
140 return SetPerUserSecValuesW(&per_user);
143 static HRESULT register_ocxs_callback(HINF hinf, PCWSTR field, void *arg)
149 BOOL ok = SetupFindFirstLineW(hinf, field, NULL, &context);
151 for (; ok; ok = SetupFindNextLine(&context, &context))
153 WCHAR buffer[MAX_INF_STRING_LENGTH];
155 /* get OCX filename */
156 if (!SetupGetStringFieldW(&context, 1, buffer,
157 sizeof(buffer) / sizeof(WCHAR), NULL))
160 hm = LoadLibraryExW(buffer, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
164 if (do_ocx_reg(hm, TRUE))
173 static HRESULT run_setup_commands_callback(HINF hinf, PCWSTR field, void *arg)
175 ADVInfo *info = (ADVInfo *)arg;
180 BOOL ok = SetupFindFirstLineW(hinf, field, NULL, &context);
182 for (; ok; ok = SetupFindNextLine(&context, &context))
184 WCHAR buffer[MAX_INF_STRING_LENGTH];
186 if (!SetupGetLineTextW(&context, NULL, NULL, NULL, buffer,
187 MAX_INF_STRING_LENGTH, &size))
190 if (launch_exe(buffer, info->working_dir, NULL))
197 /* sequentially returns pointers to parameters in a parameter list
198 * returns NULL if the parameter is empty, e.g. one,,three */
199 LPWSTR get_parameter(LPWSTR *params, WCHAR separator)
201 LPWSTR token = *params;
206 *params = strchrW(*params, separator);
216 static BOOL is_full_path(LPWSTR path)
218 const int MIN_PATH_LEN = 3;
220 if (!path || lstrlenW(path) < MIN_PATH_LEN)
223 if (path[1] == ':' || (path[0] == '\\' && path[1] == '\\'))
229 /* retrieves the contents of a field, dynamically growing the buffer if necessary */
230 static WCHAR *get_field_string(INFCONTEXT *context, DWORD index, WCHAR *buffer,
231 WCHAR *static_buffer, DWORD *size)
235 if (SetupGetStringFieldW(context, index, buffer, *size, &required)) return buffer;
237 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
239 /* now grow the buffer */
240 if (buffer != static_buffer) HeapFree(GetProcessHeap(), 0, buffer);
241 if (!(buffer = HeapAlloc(GetProcessHeap(), 0, required*sizeof(WCHAR)))) return NULL;
243 if (SetupGetStringFieldW(context, index, buffer, *size, &required)) return buffer;
246 if (buffer != static_buffer) HeapFree(GetProcessHeap(), 0, buffer);
250 /* iterates over all fields of a certain key of a certain section */
251 static HRESULT iterate_section_fields(HINF hinf, PCWSTR section, PCWSTR key,
252 iterate_fields_func callback, void *arg)
254 WCHAR static_buffer[200];
255 WCHAR *buffer = static_buffer;
256 DWORD size = sizeof(static_buffer) / sizeof(WCHAR);
260 BOOL ok = SetupFindFirstLineW(hinf, section, key, &context);
263 UINT i, count = SetupGetFieldCount(&context);
265 for (i = 1; i <= count; i++)
267 if (!(buffer = get_field_string(&context, i, buffer, static_buffer, &size)))
270 if ((hr = callback(hinf, buffer, arg)) != S_OK)
274 ok = SetupFindNextMatchLineW(&context, key, &context);
280 if (buffer != static_buffer) HeapFree(GetProcessHeap(), 0, buffer);
284 static HRESULT check_admin_rights(ADVInfo *info)
290 if (!SetupFindFirstLineW(info->hinf, info->install_sec,
291 CheckAdminRights, &context))
294 if (!SetupGetIntField(&context, 1, &check))
298 hr = IsNTAdmin(0, NULL) ? S_OK : E_FAIL;
303 /* performs a setupapi-level install of the INF file */
304 static HRESULT spapi_install(ADVInfo *info)
310 context = SetupInitDefaultQueueCallbackEx(NULL, INVALID_HANDLE_VALUE, 0, 0, NULL);
312 return ADV_HRESULT(GetLastError());
314 ret = SetupInstallFromInfSectionW(NULL, info->hinf, info->install_sec,
315 SPINST_FILES, NULL, info->working_dir,
316 SP_COPY_NEWER, SetupDefaultQueueCallbackW,
317 context, NULL, NULL);
320 res = ADV_HRESULT(GetLastError());
321 SetupTermDefaultQueueCallback(context);
326 SetupTermDefaultQueueCallback(context);
328 ret = SetupInstallFromInfSectionW(NULL, info->hinf, info->install_sec,
329 SPINST_INIFILES | SPINST_REGISTRY,
330 HKEY_LOCAL_MACHINE, NULL, 0,
331 NULL, NULL, NULL, NULL);
333 return ADV_HRESULT(GetLastError());
338 /* processes the Advanced INF commands */
339 static HRESULT adv_install(ADVInfo *info)
343 hr = check_admin_rights(info);
347 hr = iterate_section_fields(info->hinf, info->install_sec, RunPreSetupCommands,
348 run_setup_commands_callback, info);
352 hr = iterate_section_fields(info->hinf, info->install_sec,
353 RegisterOCXs, register_ocxs_callback, NULL);
357 hr = iterate_section_fields(info->hinf, info->install_sec,
358 PerUserInstall, per_user_install_callback, info);
362 hr = iterate_section_fields(info->hinf, info->install_sec, RunPostSetupCommands,
363 run_setup_commands_callback, info);
367 hr = iterate_section_fields(info->hinf, info->install_sec,
368 DelDirs, del_dirs_callback, info);
375 /* loads the INF file and performs checks on it */
376 HRESULT install_init(LPCWSTR inf_filename, LPCWSTR install_sec,
377 LPCWSTR working_dir, DWORD flags, ADVInfo *info)
382 static const WCHAR default_install[] = {
383 'D','e','f','a','u','l','t','I','n','s','t','a','l','l',0
386 len = lstrlenW(inf_filename);
388 info->inf_filename = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
389 if (!info->inf_filename)
390 return E_OUTOFMEMORY;
392 lstrcpyW(info->inf_filename, inf_filename);
394 /* FIXME: determine the proper platform to install (NTx86, etc) */
395 if (!install_sec || !*install_sec)
397 len = sizeof(default_install) - 1;
398 ptr = default_install;
402 len = lstrlenW(install_sec);
406 info->install_sec = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
407 if (!info->install_sec)
408 return E_OUTOFMEMORY;
410 lstrcpyW(info->install_sec, ptr);
412 /* FIXME: need to get the real working directory */
413 if (!working_dir || !*working_dir)
415 ptr = strrchrW(info->inf_filename, '\\');
416 len = ptr - info->inf_filename + 1;
417 ptr = info->inf_filename;
421 len = lstrlenW(working_dir) + 1;
425 info->working_dir = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
426 if (!info->working_dir)
427 return E_OUTOFMEMORY;
429 lstrcpynW(info->working_dir, ptr, len);
431 info->hinf = SetupOpenInfFileW(info->inf_filename, NULL, INF_STYLE_WIN4, NULL);
432 if (info->hinf == INVALID_HANDLE_VALUE)
433 return ADV_HRESULT(GetLastError());
435 set_ldids(info->hinf, info->install_sec, info->working_dir);
437 /* FIXME: check that the INF is advanced */
440 info->need_reboot = FALSE;
445 /* release the install instance information */
446 void install_release(ADVInfo *info)
448 if (info->hinf && info->hinf != INVALID_HANDLE_VALUE)
449 SetupCloseInfFile(info->hinf);
451 HeapFree(GetProcessHeap(), 0, info->inf_filename);
452 HeapFree(GetProcessHeap(), 0, info->install_sec);
453 HeapFree(GetProcessHeap(), 0, info->working_dir);
456 /* this structure very closely resembles parameters of RunSetupCommand() */
464 } SETUPCOMMAND_PARAMS;
472 LPCWSTR section_name;
473 } SETUPCOMMAND_PARAMSW;
475 /* internal: see DoInfInstall */
476 static HRESULT DoInfInstallW(const SETUPCOMMAND_PARAMSW *setup)
481 TRACE("(%p)\n", setup);
483 ZeroMemory(&info, sizeof(ADVInfo));
485 hr = install_init(setup->inf_name, setup->section_name, setup->dir, 0, &info);
489 hr = spapi_install(&info);
493 hr = adv_install(&info);
496 install_release(&info);
501 /***********************************************************************
502 * DoInfInstall (ADVPACK.@)
504 * Install an INF section.
507 * setup [I] Structure containing install information.
511 * HRESULT_FROM_WIN32(GetLastError()) Some other error
513 HRESULT WINAPI DoInfInstall(const SETUPCOMMAND_PARAMS *setup)
515 UNICODE_STRING title, inf, section, dir;
516 SETUPCOMMAND_PARAMSW params;
522 RtlCreateUnicodeStringFromAsciiz(&title, setup->title);
523 RtlCreateUnicodeStringFromAsciiz(&inf, setup->inf_name);
524 RtlCreateUnicodeStringFromAsciiz(§ion, setup->section_name);
525 RtlCreateUnicodeStringFromAsciiz(&dir, setup->dir);
527 params.title = title.Buffer;
528 params.inf_name = inf.Buffer;
529 params.section_name = section.Buffer;
530 params.dir = dir.Buffer;
531 params.hwnd = setup->hwnd;
533 hr = DoInfInstallW(¶ms);
535 RtlFreeUnicodeString(&title);
536 RtlFreeUnicodeString(&inf);
537 RtlFreeUnicodeString(§ion);
538 RtlFreeUnicodeString(&dir);
543 /***********************************************************************
544 * ExecuteCabA (ADVPACK.@)
548 HRESULT WINAPI ExecuteCabA(HWND hwnd, CABINFOA* pCab, LPVOID pReserved)
550 UNICODE_STRING cab, inf, section;
554 TRACE("(%p, %p, %p)\n", hwnd, pCab, pReserved);
561 RtlCreateUnicodeStringFromAsciiz(&cab, pCab->pszCab);
562 cabinfo.pszCab = cab.Buffer;
565 cabinfo.pszCab = NULL;
567 RtlCreateUnicodeStringFromAsciiz(&inf, pCab->pszInf);
568 RtlCreateUnicodeStringFromAsciiz(§ion, pCab->pszSection);
570 MultiByteToWideChar(CP_ACP, 0, pCab->szSrcPath, -1, cabinfo.szSrcPath,
571 sizeof(cabinfo.szSrcPath) / sizeof(WCHAR));
573 cabinfo.pszInf = inf.Buffer;
574 cabinfo.pszSection = section.Buffer;
575 cabinfo.dwFlags = pCab->dwFlags;
577 hr = ExecuteCabW(hwnd, &cabinfo, pReserved);
580 RtlFreeUnicodeString(&cab);
582 RtlFreeUnicodeString(&inf);
583 RtlFreeUnicodeString(§ion);
588 /***********************************************************************
589 * ExecuteCabW (ADVPACK.@)
591 * Installs the INF file extracted from a specified cabinet file.
594 * hwnd [I] Handle to the window used for the display.
595 * pCab [I] Information about the cabinet file.
596 * pReserved [I] Reserved. Must be NULL.
602 HRESULT WINAPI ExecuteCabW(HWND hwnd, CABINFOW* pCab, LPVOID pReserved)
607 TRACE("(%p, %p, %p)\n", hwnd, pCab, pReserved);
609 ZeroMemory(&info, sizeof(ADVInfo));
611 if (pCab->pszCab && *pCab->pszCab)
612 FIXME("Cab archive not extracted!\n");
614 hr = install_init(pCab->pszInf, pCab->pszSection, pCab->szSrcPath, pCab->dwFlags, &info);
618 hr = spapi_install(&info);
622 hr = adv_install(&info);
625 install_release(&info);
630 /***********************************************************************
631 * LaunchINFSectionA (ADVPACK.@)
633 * See LaunchINFSectionW.
635 INT WINAPI LaunchINFSectionA(HWND hWnd, HINSTANCE hInst, LPSTR cmdline, INT show)
640 TRACE("(%p, %p, %s, %i)\n", hWnd, hInst, debugstr_a(cmdline), show);
645 RtlCreateUnicodeStringFromAsciiz(&cmd, cmdline);
647 hr = LaunchINFSectionW(hWnd, hInst, cmd.Buffer, show);
649 RtlFreeUnicodeString(&cmd);
654 /***********************************************************************
655 * LaunchINFSectionW (ADVPACK.@)
657 * Installs an INF section without BACKUP/ROLLBACK capabilities.
660 * hWnd [I] Handle to parent window, NULL for desktop.
661 * hInst [I] Instance of the process.
662 * cmdline [I] Contains parameters in the order INF,section,flags,reboot.
663 * show [I] How the window should be shown.
666 * Success: ADV_SUCCESS.
667 * Failure: ADV_FAILURE.
670 * INF - Filename of the INF to launch.
671 * section - INF section to install.
672 * flags - see advpub.h.
673 * reboot - smart reboot behavior
675 * 'I' Reboot if needed (default).
678 INT WINAPI LaunchINFSectionW(HWND hWnd, HINSTANCE hInst, LPWSTR cmdline, INT show)
681 LPWSTR cmdline_copy, cmdline_ptr;
682 LPWSTR inf_filename, install_sec;
687 TRACE("(%p, %p, %s, %d)\n", hWnd, hInst, debugstr_w(cmdline), show);
692 cmdline_copy = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(cmdline) + 1) * sizeof(WCHAR));
693 cmdline_ptr = cmdline_copy;
694 lstrcpyW(cmdline_copy, cmdline);
696 inf_filename = get_parameter(&cmdline_ptr, ',');
697 install_sec = get_parameter(&cmdline_ptr, ',');
699 str_flags = get_parameter(&cmdline_ptr, ',');
701 flags = atolW(str_flags);
703 ZeroMemory(&info, sizeof(ADVInfo));
705 hr = install_init(inf_filename, install_sec, NULL, flags, &info);
709 hr = spapi_install(&info);
713 hr = adv_install(&info);
716 install_release(&info);
717 HeapFree(GetProcessHeap(), 0, cmdline_copy);
719 return SUCCEEDED(hr) ? ADV_SUCCESS : ADV_FAILURE;
722 /***********************************************************************
723 * LaunchINFSectionExA (ADVPACK.@)
725 * See LaunchINFSectionExW.
727 HRESULT WINAPI LaunchINFSectionExA(HWND hWnd, HINSTANCE hInst, LPSTR cmdline, INT show)
732 TRACE("(%p, %p, %s, %i)\n", hWnd, hInst, debugstr_a(cmdline), show);
737 RtlCreateUnicodeStringFromAsciiz(&cmd, cmdline);
739 hr = LaunchINFSectionExW(hWnd, hInst, cmd.Buffer, show);
741 RtlFreeUnicodeString(&cmd);
746 /***********************************************************************
747 * LaunchINFSectionExW (ADVPACK.@)
749 * Installs an INF section with BACKUP/ROLLBACK capabilities.
752 * hWnd [I] Handle to parent window, NULL for desktop.
753 * hInst [I] Instance of the process.
754 * cmdline [I] Contains parameters in the order INF,section,CAB,flags,reboot.
755 * show [I] How the window should be shown.
758 * Success: ADV_SUCCESS.
759 * Failure: ADV_FAILURE.
762 * INF - Filename of the INF to launch.
763 * section - INF section to install.
764 * flags - see advpub.h.
765 * reboot - smart reboot behavior
767 * 'I' Reboot if needed (default).
771 * Doesn't handle the reboot flag.
773 HRESULT WINAPI LaunchINFSectionExW(HWND hWnd, HINSTANCE hInst, LPWSTR cmdline, INT show)
775 LPWSTR cmdline_copy, cmdline_ptr;
780 TRACE("(%p, %p, %s, %d)\n", hWnd, hInst, debugstr_w(cmdline), show);
785 cmdline_copy = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(cmdline) + 1) * sizeof(WCHAR));
786 cmdline_ptr = cmdline_copy;
787 lstrcpyW(cmdline_copy, cmdline);
789 cabinfo.pszInf = get_parameter(&cmdline_ptr, ',');
790 cabinfo.pszSection = get_parameter(&cmdline_ptr, ',');
791 cabinfo.pszCab = get_parameter(&cmdline_ptr, ',');
792 *cabinfo.szSrcPath = '\0';
794 flags = get_parameter(&cmdline_ptr, ',');
796 cabinfo.dwFlags = atolW(flags);
798 /* get the source path from the cab filename */
799 if (cabinfo.pszCab && *cabinfo.pszCab)
801 if (!is_full_path(cabinfo.pszCab))
804 lstrcpyW(cabinfo.szSrcPath, cabinfo.pszCab);
805 ptr = strrchrW(cabinfo.szSrcPath, '\\');
809 hr = ExecuteCabW(hWnd, &cabinfo, NULL);
812 HeapFree(GetProcessHeap(), 0, cmdline_copy);
814 return SUCCEEDED(hr) ? ADV_SUCCESS : ADV_FAILURE;
817 HRESULT launch_exe(LPCWSTR cmd, LPCWSTR dir, HANDLE *phEXE)
820 PROCESS_INFORMATION pi;
822 if (phEXE) *phEXE = NULL;
824 ZeroMemory(&pi, sizeof(pi));
825 ZeroMemory(&si, sizeof(si));
828 if (!CreateProcessW(NULL, (LPWSTR)cmd, NULL, NULL, FALSE,
829 CREATE_DEFAULT_ERROR_MODE | CREATE_NEW_PROCESS_GROUP,
830 NULL, dir, &si, &pi))
832 return HRESULT_FROM_WIN32(GetLastError());
835 CloseHandle(pi.hThread);
839 *phEXE = pi.hProcess;
840 return S_ASYNCHRONOUS;
843 /* wait for the child process to finish */
844 WaitForSingleObject(pi.hProcess, INFINITE);
845 CloseHandle(pi.hProcess);
850 /***********************************************************************
851 * RunSetupCommandA (ADVPACK.@)
853 * See RunSetupCommandW.
855 HRESULT WINAPI RunSetupCommandA(HWND hWnd, LPCSTR szCmdName,
856 LPCSTR szInfSection, LPCSTR szDir,
857 LPCSTR lpszTitle, HANDLE *phEXE,
858 DWORD dwFlags, LPVOID pvReserved)
860 UNICODE_STRING cmdname, infsec;
861 UNICODE_STRING dir, title;
864 TRACE("(%p, %s, %s, %s, %s, %p, %ld, %p)\n",
865 hWnd, debugstr_a(szCmdName), debugstr_a(szInfSection),
866 debugstr_a(szDir), debugstr_a(lpszTitle),
867 phEXE, dwFlags, pvReserved);
869 if (!szCmdName || !szDir)
872 RtlCreateUnicodeStringFromAsciiz(&cmdname, szCmdName);
873 RtlCreateUnicodeStringFromAsciiz(&infsec, szInfSection);
874 RtlCreateUnicodeStringFromAsciiz(&dir, szDir);
875 RtlCreateUnicodeStringFromAsciiz(&title, lpszTitle);
877 hr = RunSetupCommandW(hWnd, cmdname.Buffer, infsec.Buffer, dir.Buffer,
878 title.Buffer, phEXE, dwFlags, pvReserved);
880 RtlFreeUnicodeString(&cmdname);
881 RtlFreeUnicodeString(&infsec);
882 RtlFreeUnicodeString(&dir);
883 RtlFreeUnicodeString(&title);
888 /***********************************************************************
889 * RunSetupCommandW (ADVPACK.@)
891 * Executes an install section in an INF file or a program.
894 * hWnd [I] Handle to parent window, NULL for quiet mode
895 * szCmdName [I] Inf or EXE filename to execute
896 * szInfSection [I] Inf section to install, NULL for DefaultInstall
897 * szDir [I] Path to extracted files
898 * szTitle [I] Title of all dialogs
899 * phEXE [O] Handle of EXE to wait for
900 * dwFlags [I] Flags; see include/advpub.h
901 * pvReserved [I] Reserved
905 * S_ASYNCHRONOUS OK, required to wait on phEXE
906 * ERROR_SUCCESS_REBOOT_REQUIRED Reboot required
907 * E_INVALIDARG Invalid argument given
908 * HRESULT_FROM_WIN32(ERROR_OLD_WIN_VERSION)
909 * Not supported on this Windows version
910 * E_UNEXPECTED Unexpected error
911 * HRESULT_FROM_WIN32(GetLastError()) Some other error
913 HRESULT WINAPI RunSetupCommandW(HWND hWnd, LPCWSTR szCmdName,
914 LPCWSTR szInfSection, LPCWSTR szDir,
915 LPCWSTR lpszTitle, HANDLE *phEXE,
916 DWORD dwFlags, LPVOID pvReserved)
921 TRACE("(%p, %s, %s, %s, %s, %p, %ld, %p)\n",
922 hWnd, debugstr_w(szCmdName), debugstr_w(szInfSection),
923 debugstr_w(szDir), debugstr_w(lpszTitle),
924 phEXE, dwFlags, pvReserved);
926 if (dwFlags & RSC_FLAG_UPDHLPDLLS)
927 FIXME("Unhandled flag: RSC_FLAG_UPDHLPDLLS\n");
929 if (!szCmdName || !szDir)
932 if (!(dwFlags & RSC_FLAG_INF))
933 return launch_exe(szCmdName, szDir, phEXE);
935 ZeroMemory(&info, sizeof(ADVInfo));
937 hr = install_init(szCmdName, szInfSection, szDir, dwFlags, &info);
941 hr = spapi_install(&info);
945 hr = adv_install(&info);
948 install_release(&info);