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
34 #include "wine/debug.h"
35 #include "wine/unicode.h"
36 #include "advpack_private.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(advpack);
40 #define SPAPI_ERROR 0xE0000000L
41 #define SPAPI_PREFIX 0x800F0000L
42 #define SPAPI_MASK 0xFFFFL
43 #define HRESULT_FROM_SPAPI(x) ((x & SPAPI_MASK) | SPAPI_PREFIX)
45 #define ADV_HRESULT(x) ((x & SPAPI_ERROR) ? HRESULT_FROM_SPAPI(x) : HRESULT_FROM_WIN32(x))
50 /* contains information about a specific install instance */
51 typedef struct _ADVInfo
62 typedef HRESULT (*iterate_fields_func)(HINF hinf, PCWSTR field, void *arg);
64 /* Advanced INF commands */
65 static const WCHAR CheckAdminRights[] = {
66 'C','h','e','c','k','A','d','m','i','n','R','i','g','h','t','s',0
68 static const WCHAR DelDirs[] = {'D','e','l','D','i','r','s',0};
69 static const WCHAR PerUserInstall[] = {'P','e','r','U','s','e','r','I','n','s','t','a','l','l',0};
70 static const WCHAR RegisterOCXs[] = {'R','e','g','i','s','t','e','r','O','C','X','s',0};
71 static const WCHAR RunPreSetupCommands[] = {
72 'R','u','n','P','r','e','S','e','t','u','p','C','o','m','m','a','n','d','s',0
74 static const WCHAR RunPostSetupCommands[] = {
75 'R','u','n','P','o','s','t','S','e','t','u','p','C','o','m','m','a','n','d','s',0
78 /* Advanced INF callbacks */
79 static HRESULT del_dirs_callback(HINF hinf, PCWSTR field, void *arg)
85 BOOL ok = SetupFindFirstLineW(hinf, field, NULL, &context);
87 for (; ok; ok = SetupFindNextLine(&context, &context))
89 WCHAR directory[MAX_INF_STRING_LENGTH];
91 if (!SetupGetLineTextW(&context, NULL, NULL, NULL, directory,
92 MAX_INF_STRING_LENGTH, &size))
95 if (DelNodeW(directory, ADN_DEL_IF_EMPTY))
102 static HRESULT per_user_install_callback(HINF hinf, PCWSTR field, void *arg)
104 PERUSERSECTIONW per_user;
108 static const WCHAR disp_name[] = {'D','i','s','p','l','a','y','N','a','m','e',0};
109 static const WCHAR version[] = {'V','e','r','s','i','o','n',0};
110 static const WCHAR is_installed[] = {'I','s','I','n','s','t','a','l','l','e','d',0};
111 static const WCHAR comp_id[] = {'C','o','m','p','o','n','e','n','t','I','D',0};
112 static const WCHAR guid[] = {'G','U','I','D',0};
113 static const WCHAR locale[] = {'L','o','c','a','l','e',0};
114 static const WCHAR stub_path[] = {'S','t','u','b','P','a','t','h',0};
116 per_user.bRollback = FALSE;
117 per_user.dwIsInstalled = 0;
119 SetupGetLineTextW(NULL, hinf, field, disp_name, per_user.szDispName,
120 sizeof(per_user.szDispName) / sizeof(WCHAR), &size);
122 SetupGetLineTextW(NULL, hinf, field, version, per_user.szVersion,
123 sizeof(per_user.szVersion) / sizeof(WCHAR), &size);
125 if (SetupFindFirstLineW(hinf, field, is_installed, &context))
127 SetupGetIntField(&context, 1, (PINT)&per_user.dwIsInstalled);
130 SetupGetLineTextW(NULL, hinf, field, comp_id, per_user.szCompID,
131 sizeof(per_user.szCompID) / sizeof(WCHAR), &size);
133 SetupGetLineTextW(NULL, hinf, field, guid, per_user.szGUID,
134 sizeof(per_user.szGUID) / sizeof(WCHAR), &size);
136 SetupGetLineTextW(NULL, hinf, field, locale, per_user.szLocale,
137 sizeof(per_user.szLocale) / sizeof(WCHAR), &size);
139 SetupGetLineTextW(NULL, hinf, field, stub_path, per_user.szStub,
140 sizeof(per_user.szStub) / sizeof(WCHAR), &size);
142 return SetPerUserSecValuesW(&per_user);
145 static HRESULT register_ocxs_callback(HINF hinf, PCWSTR field, void *arg)
151 BOOL ok = SetupFindFirstLineW(hinf, field, NULL, &context);
153 for (; ok; ok = SetupFindNextLine(&context, &context))
155 WCHAR buffer[MAX_INF_STRING_LENGTH];
157 /* get OCX filename */
158 if (!SetupGetStringFieldW(&context, 1, buffer,
159 sizeof(buffer) / sizeof(WCHAR), NULL))
162 hm = LoadLibraryExW(buffer, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
165 if (do_ocx_reg(hm, TRUE))
175 /* FIXME: display a message box */
183 static HRESULT run_setup_commands_callback(HINF hinf, PCWSTR field, void *arg)
185 ADVInfo *info = (ADVInfo *)arg;
190 BOOL ok = SetupFindFirstLineW(hinf, field, NULL, &context);
192 for (; ok; ok = SetupFindNextLine(&context, &context))
194 WCHAR buffer[MAX_INF_STRING_LENGTH];
196 if (!SetupGetLineTextW(&context, NULL, NULL, NULL, buffer,
197 MAX_INF_STRING_LENGTH, &size))
200 if (launch_exe(buffer, info->working_dir, NULL))
207 /* sequentially returns pointers to parameters in a parameter list
208 * returns NULL if the parameter is empty, e.g. one,,three */
209 LPWSTR get_parameter(LPWSTR *params, WCHAR separator)
211 LPWSTR token = *params;
216 *params = strchrW(*params, separator);
226 static BOOL is_full_path(LPCWSTR path)
228 const int MIN_PATH_LEN = 3;
230 if (!path || lstrlenW(path) < MIN_PATH_LEN)
233 if ((path[1] == ':' && path[2] == '\\') || (path[0] == '\\' && path[1] == '\\'))
239 /* retrieves the contents of a field, dynamically growing the buffer if necessary */
240 static WCHAR *get_field_string(INFCONTEXT *context, DWORD index, WCHAR *buffer,
241 const WCHAR *static_buffer, DWORD *size)
245 if (SetupGetStringFieldW(context, index, buffer, *size, &required)) return buffer;
247 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
249 /* now grow the buffer */
250 if (buffer != static_buffer) HeapFree(GetProcessHeap(), 0, buffer);
251 if (!(buffer = HeapAlloc(GetProcessHeap(), 0, required*sizeof(WCHAR)))) return NULL;
253 if (SetupGetStringFieldW(context, index, buffer, *size, &required)) return buffer;
256 if (buffer != static_buffer) HeapFree(GetProcessHeap(), 0, buffer);
260 /* iterates over all fields of a certain key of a certain section */
261 static HRESULT iterate_section_fields(HINF hinf, PCWSTR section, PCWSTR key,
262 iterate_fields_func callback, void *arg)
264 WCHAR static_buffer[200];
265 WCHAR *buffer = static_buffer;
266 DWORD size = sizeof(static_buffer) / sizeof(WCHAR);
270 BOOL ok = SetupFindFirstLineW(hinf, section, key, &context);
273 UINT i, count = SetupGetFieldCount(&context);
275 for (i = 1; i <= count; i++)
277 if (!(buffer = get_field_string(&context, i, buffer, static_buffer, &size)))
280 if ((hr = callback(hinf, buffer, arg)) != S_OK)
284 ok = SetupFindNextMatchLineW(&context, key, &context);
290 if (buffer != static_buffer) HeapFree(GetProcessHeap(), 0, buffer);
294 static HRESULT check_admin_rights(ADVInfo *info)
300 if (!SetupFindFirstLineW(info->hinf, info->install_sec,
301 CheckAdminRights, &context))
304 if (!SetupGetIntField(&context, 1, &check))
308 hr = IsNTAdmin(0, NULL) ? S_OK : E_FAIL;
313 /* performs a setupapi-level install of the INF file */
314 static HRESULT spapi_install(ADVInfo *info)
320 context = SetupInitDefaultQueueCallbackEx(NULL, INVALID_HANDLE_VALUE, 0, 0, NULL);
322 return ADV_HRESULT(GetLastError());
324 ret = SetupInstallFromInfSectionW(NULL, info->hinf, info->install_sec,
325 SPINST_FILES, NULL, info->working_dir,
326 SP_COPY_NEWER, SetupDefaultQueueCallbackW,
327 context, NULL, NULL);
330 res = ADV_HRESULT(GetLastError());
331 SetupTermDefaultQueueCallback(context);
336 SetupTermDefaultQueueCallback(context);
338 ret = SetupInstallFromInfSectionW(NULL, info->hinf, info->install_sec,
339 SPINST_INIFILES | SPINST_REGISTRY | SPINST_REGSVR,
340 HKEY_LOCAL_MACHINE, NULL, 0,
341 NULL, NULL, NULL, NULL);
343 return ADV_HRESULT(GetLastError());
348 /* processes the Advanced INF commands */
349 static HRESULT adv_install(ADVInfo *info)
353 hr = check_admin_rights(info);
357 hr = iterate_section_fields(info->hinf, info->install_sec, RunPreSetupCommands,
358 run_setup_commands_callback, info);
363 hr = iterate_section_fields(info->hinf, info->install_sec,
364 RegisterOCXs, register_ocxs_callback, NULL);
369 hr = iterate_section_fields(info->hinf, info->install_sec,
370 PerUserInstall, per_user_install_callback, info);
374 hr = iterate_section_fields(info->hinf, info->install_sec, RunPostSetupCommands,
375 run_setup_commands_callback, info);
379 hr = iterate_section_fields(info->hinf, info->install_sec,
380 DelDirs, del_dirs_callback, info);
387 /* determines the proper working directory for the INF file */
388 static HRESULT get_working_dir(ADVInfo *info, LPCWSTR inf_filename, LPCWSTR working_dir)
390 WCHAR path[MAX_PATH];
394 static const WCHAR backslash[] = {'\\',0};
395 static const WCHAR inf_dir[] = {'\\','I','N','F',0};
397 if ((ptr = strrchrW(inf_filename, '\\')))
399 len = ptr - inf_filename + 1;
402 else if (working_dir && *working_dir)
404 len = lstrlenW(working_dir) + 1;
409 GetCurrentDirectoryW(MAX_PATH, path);
410 lstrcatW(path, backslash);
411 lstrcatW(path, inf_filename);
413 /* check if the INF file is in the current directory */
414 if (GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
416 GetCurrentDirectoryW(MAX_PATH, path);
420 /* default to the windows\inf directory if all else fails */
421 GetWindowsDirectoryW(path, MAX_PATH);
422 lstrcatW(path, inf_dir);
425 len = lstrlenW(path) + 1;
429 info->working_dir = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
430 if (!info->working_dir)
431 return E_OUTOFMEMORY;
433 lstrcpynW(info->working_dir, ptr, len);
438 /* loads the INF file and performs checks on it */
439 static HRESULT install_init(LPCWSTR inf_filename, LPCWSTR install_sec,
440 LPCWSTR working_dir, DWORD flags, ADVInfo *info)
446 static const WCHAR backslash[] = {'\\',0};
447 static const WCHAR default_install[] = {
448 'D','e','f','a','u','l','t','I','n','s','t','a','l','l',0
451 if (!(ptr = strrchrW(inf_filename, '\\')))
456 info->inf_filename = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
457 if (!info->inf_filename)
458 return E_OUTOFMEMORY;
460 lstrcpyW(info->inf_filename, ptr);
462 /* FIXME: determine the proper platform to install (NTx86, etc) */
463 if (!install_sec || !*install_sec)
465 len = sizeof(default_install) - 1;
466 ptr = default_install;
470 len = lstrlenW(install_sec);
474 info->install_sec = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
475 if (!info->install_sec)
476 return E_OUTOFMEMORY;
478 lstrcpyW(info->install_sec, ptr);
480 hr = get_working_dir(info, inf_filename, working_dir);
484 len = lstrlenW(info->working_dir) + lstrlenW(info->inf_filename) + 2;
485 info->inf_path = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
487 return E_OUTOFMEMORY;
489 lstrcpyW(info->inf_path, info->working_dir);
490 lstrcatW(info->inf_path, backslash);
491 lstrcatW(info->inf_path, info->inf_filename);
493 /* RunSetupCommand opens unmodifed filename parameter */
494 if (flags & RSC_FLAG_INF)
497 path = info->inf_path;
499 info->hinf = SetupOpenInfFileW(path, NULL, INF_STYLE_WIN4, NULL);
500 if (info->hinf == INVALID_HANDLE_VALUE)
501 return ADV_HRESULT(GetLastError());
503 set_ldids(info->hinf, info->install_sec, info->working_dir);
505 /* FIXME: check that the INF is advanced */
508 info->need_reboot = FALSE;
513 /* release the install instance information */
514 static void install_release(ADVInfo *info)
516 if (info->hinf && info->hinf != INVALID_HANDLE_VALUE)
517 SetupCloseInfFile(info->hinf);
519 HeapFree(GetProcessHeap(), 0, info->inf_path);
520 HeapFree(GetProcessHeap(), 0, info->inf_filename);
521 HeapFree(GetProcessHeap(), 0, info->install_sec);
522 HeapFree(GetProcessHeap(), 0, info->working_dir);
525 /* this structure very closely resembles parameters of RunSetupCommand() */
533 } SETUPCOMMAND_PARAMS;
541 LPCWSTR section_name;
542 } SETUPCOMMAND_PARAMSW;
544 /* internal: see DoInfInstall */
545 static HRESULT DoInfInstallW(const SETUPCOMMAND_PARAMSW *setup)
550 TRACE("(%p)\n", setup);
552 ZeroMemory(&info, sizeof(ADVInfo));
554 hr = install_init(setup->inf_name, setup->section_name, setup->dir, 0, &info);
558 hr = spapi_install(&info);
562 hr = adv_install(&info);
565 install_release(&info);
570 /***********************************************************************
571 * DoInfInstall (ADVPACK.@)
573 * Install an INF section.
576 * setup [I] Structure containing install information.
580 * HRESULT_FROM_WIN32(GetLastError()) Some other error
582 HRESULT WINAPI DoInfInstall(const SETUPCOMMAND_PARAMS *setup)
584 UNICODE_STRING title, inf, section, dir;
585 SETUPCOMMAND_PARAMSW params;
591 RtlCreateUnicodeStringFromAsciiz(&title, setup->title);
592 RtlCreateUnicodeStringFromAsciiz(&inf, setup->inf_name);
593 RtlCreateUnicodeStringFromAsciiz(§ion, setup->section_name);
594 RtlCreateUnicodeStringFromAsciiz(&dir, setup->dir);
596 params.title = title.Buffer;
597 params.inf_name = inf.Buffer;
598 params.section_name = section.Buffer;
599 params.dir = dir.Buffer;
600 params.hwnd = setup->hwnd;
602 hr = DoInfInstallW(¶ms);
604 RtlFreeUnicodeString(&title);
605 RtlFreeUnicodeString(&inf);
606 RtlFreeUnicodeString(§ion);
607 RtlFreeUnicodeString(&dir);
612 /***********************************************************************
613 * ExecuteCabA (ADVPACK.@)
617 HRESULT WINAPI ExecuteCabA(HWND hwnd, CABINFOA* pCab, LPVOID pReserved)
619 UNICODE_STRING cab, inf, section;
623 TRACE("(%p, %p, %p)\n", hwnd, pCab, pReserved);
630 RtlCreateUnicodeStringFromAsciiz(&cab, pCab->pszCab);
631 cabinfo.pszCab = cab.Buffer;
634 cabinfo.pszCab = NULL;
636 RtlCreateUnicodeStringFromAsciiz(&inf, pCab->pszInf);
637 RtlCreateUnicodeStringFromAsciiz(§ion, pCab->pszSection);
639 MultiByteToWideChar(CP_ACP, 0, pCab->szSrcPath, -1, cabinfo.szSrcPath,
640 sizeof(cabinfo.szSrcPath) / sizeof(WCHAR));
642 cabinfo.pszInf = inf.Buffer;
643 cabinfo.pszSection = section.Buffer;
644 cabinfo.dwFlags = pCab->dwFlags;
646 hr = ExecuteCabW(hwnd, &cabinfo, pReserved);
649 RtlFreeUnicodeString(&cab);
651 RtlFreeUnicodeString(&inf);
652 RtlFreeUnicodeString(§ion);
657 /***********************************************************************
658 * ExecuteCabW (ADVPACK.@)
660 * Installs the INF file extracted from a specified cabinet file.
663 * hwnd [I] Handle to the window used for the display.
664 * pCab [I] Information about the cabinet file.
665 * pReserved [I] Reserved. Must be NULL.
671 HRESULT WINAPI ExecuteCabW(HWND hwnd, CABINFOW* pCab, LPVOID pReserved)
676 TRACE("(%p, %p, %p)\n", hwnd, pCab, pReserved);
678 ZeroMemory(&info, sizeof(ADVInfo));
680 if (pCab->pszCab && *pCab->pszCab)
681 FIXME("Cab archive not extracted!\n");
683 hr = install_init(pCab->pszInf, pCab->pszSection, pCab->szSrcPath, pCab->dwFlags, &info);
687 hr = spapi_install(&info);
691 hr = adv_install(&info);
694 install_release(&info);
699 /***********************************************************************
700 * LaunchINFSectionA (ADVPACK.@)
702 * See LaunchINFSectionW.
704 INT WINAPI LaunchINFSectionA(HWND hWnd, HINSTANCE hInst, LPSTR cmdline, INT show)
709 TRACE("(%p, %p, %s, %i)\n", hWnd, hInst, debugstr_a(cmdline), show);
714 RtlCreateUnicodeStringFromAsciiz(&cmd, cmdline);
716 hr = LaunchINFSectionW(hWnd, hInst, cmd.Buffer, show);
718 RtlFreeUnicodeString(&cmd);
723 /***********************************************************************
724 * LaunchINFSectionW (ADVPACK.@)
726 * Installs an INF section without BACKUP/ROLLBACK capabilities.
729 * hWnd [I] Handle to parent window, NULL for desktop.
730 * hInst [I] Instance of the process.
731 * cmdline [I] Contains parameters in the order INF,section,flags,reboot.
732 * show [I] How the window should be shown.
735 * Success: ADV_SUCCESS.
736 * Failure: ADV_FAILURE.
739 * INF - Filename of the INF to launch.
740 * section - INF section to install.
741 * flags - see advpub.h.
742 * reboot - smart reboot behavior
744 * 'I' Reboot if needed (default).
747 INT WINAPI LaunchINFSectionW(HWND hWnd, HINSTANCE hInst, LPWSTR cmdline, INT show)
750 LPWSTR cmdline_copy, cmdline_ptr;
751 LPWSTR inf_filename, install_sec;
756 TRACE("(%p, %p, %s, %d)\n", hWnd, hInst, debugstr_w(cmdline), show);
761 cmdline_copy = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(cmdline) + 1) * sizeof(WCHAR));
762 cmdline_ptr = cmdline_copy;
763 lstrcpyW(cmdline_copy, cmdline);
765 inf_filename = get_parameter(&cmdline_ptr, ',');
766 install_sec = get_parameter(&cmdline_ptr, ',');
768 str_flags = get_parameter(&cmdline_ptr, ',');
770 flags = atolW(str_flags);
772 ZeroMemory(&info, sizeof(ADVInfo));
774 hr = install_init(inf_filename, install_sec, NULL, flags, &info);
778 hr = spapi_install(&info);
782 hr = adv_install(&info);
785 install_release(&info);
786 HeapFree(GetProcessHeap(), 0, cmdline_copy);
788 return SUCCEEDED(hr) ? ADV_SUCCESS : ADV_FAILURE;
791 /***********************************************************************
792 * LaunchINFSectionExA (ADVPACK.@)
794 * See LaunchINFSectionExW.
796 HRESULT WINAPI LaunchINFSectionExA(HWND hWnd, HINSTANCE hInst, LPSTR cmdline, INT show)
801 TRACE("(%p, %p, %s, %i)\n", hWnd, hInst, debugstr_a(cmdline), show);
806 RtlCreateUnicodeStringFromAsciiz(&cmd, cmdline);
808 hr = LaunchINFSectionExW(hWnd, hInst, cmd.Buffer, show);
810 RtlFreeUnicodeString(&cmd);
815 /***********************************************************************
816 * LaunchINFSectionExW (ADVPACK.@)
818 * Installs an INF section with BACKUP/ROLLBACK capabilities.
821 * hWnd [I] Handle to parent window, NULL for desktop.
822 * hInst [I] Instance of the process.
823 * cmdline [I] Contains parameters in the order INF,section,CAB,flags,reboot.
824 * show [I] How the window should be shown.
827 * Success: ADV_SUCCESS.
828 * Failure: ADV_FAILURE.
831 * INF - Filename of the INF to launch.
832 * section - INF section to install.
833 * flags - see advpub.h.
834 * reboot - smart reboot behavior
836 * 'I' Reboot if needed (default).
840 * Doesn't handle the reboot flag.
842 HRESULT WINAPI LaunchINFSectionExW(HWND hWnd, HINSTANCE hInst, LPWSTR cmdline, INT show)
844 LPWSTR cmdline_copy, cmdline_ptr;
849 TRACE("(%p, %p, %s, %d)\n", hWnd, hInst, debugstr_w(cmdline), show);
854 cmdline_copy = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(cmdline) + 1) * sizeof(WCHAR));
855 cmdline_ptr = cmdline_copy;
856 lstrcpyW(cmdline_copy, cmdline);
858 cabinfo.pszInf = get_parameter(&cmdline_ptr, ',');
859 cabinfo.pszSection = get_parameter(&cmdline_ptr, ',');
860 cabinfo.pszCab = get_parameter(&cmdline_ptr, ',');
861 *cabinfo.szSrcPath = '\0';
863 flags = get_parameter(&cmdline_ptr, ',');
865 cabinfo.dwFlags = atolW(flags);
867 if (!is_full_path(cabinfo.pszCab) && !is_full_path(cabinfo.pszInf))
869 HeapFree(GetProcessHeap(), 0, cmdline_copy);
873 /* get the source path from the cab filename */
874 if (cabinfo.pszCab && *cabinfo.pszCab)
876 if (!is_full_path(cabinfo.pszCab))
877 lstrcpyW(cabinfo.szSrcPath, cabinfo.pszInf);
879 lstrcpyW(cabinfo.szSrcPath, cabinfo.pszCab);
881 ptr = strrchrW(cabinfo.szSrcPath, '\\');
885 hr = ExecuteCabW(hWnd, &cabinfo, NULL);
886 HeapFree(GetProcessHeap(), 0, cmdline_copy);
887 return SUCCEEDED(hr) ? ADV_SUCCESS : ADV_FAILURE;
890 HRESULT launch_exe(LPCWSTR cmd, LPCWSTR dir, HANDLE *phEXE)
893 PROCESS_INFORMATION pi;
895 if (phEXE) *phEXE = NULL;
897 ZeroMemory(&pi, sizeof(pi));
898 ZeroMemory(&si, sizeof(si));
901 if (!CreateProcessW(NULL, (LPWSTR)cmd, NULL, NULL, FALSE,
902 CREATE_DEFAULT_ERROR_MODE | CREATE_NEW_PROCESS_GROUP,
903 NULL, dir, &si, &pi))
905 return HRESULT_FROM_WIN32(GetLastError());
908 CloseHandle(pi.hThread);
912 *phEXE = pi.hProcess;
913 return S_ASYNCHRONOUS;
916 /* wait for the child process to finish */
917 WaitForSingleObject(pi.hProcess, INFINITE);
918 CloseHandle(pi.hProcess);
923 /***********************************************************************
924 * RunSetupCommandA (ADVPACK.@)
926 * See RunSetupCommandW.
928 HRESULT WINAPI RunSetupCommandA(HWND hWnd, LPCSTR szCmdName,
929 LPCSTR szInfSection, LPCSTR szDir,
930 LPCSTR lpszTitle, HANDLE *phEXE,
931 DWORD dwFlags, LPVOID pvReserved)
933 UNICODE_STRING cmdname, infsec;
934 UNICODE_STRING dir, title;
937 TRACE("(%p, %s, %s, %s, %s, %p, %d, %p)\n",
938 hWnd, debugstr_a(szCmdName), debugstr_a(szInfSection),
939 debugstr_a(szDir), debugstr_a(lpszTitle),
940 phEXE, dwFlags, pvReserved);
942 if (!szCmdName || !szDir)
945 RtlCreateUnicodeStringFromAsciiz(&cmdname, szCmdName);
946 RtlCreateUnicodeStringFromAsciiz(&infsec, szInfSection);
947 RtlCreateUnicodeStringFromAsciiz(&dir, szDir);
948 RtlCreateUnicodeStringFromAsciiz(&title, lpszTitle);
950 hr = RunSetupCommandW(hWnd, cmdname.Buffer, infsec.Buffer, dir.Buffer,
951 title.Buffer, phEXE, dwFlags, pvReserved);
953 RtlFreeUnicodeString(&cmdname);
954 RtlFreeUnicodeString(&infsec);
955 RtlFreeUnicodeString(&dir);
956 RtlFreeUnicodeString(&title);
961 /***********************************************************************
962 * RunSetupCommandW (ADVPACK.@)
964 * Executes an install section in an INF file or a program.
967 * hWnd [I] Handle to parent window, NULL for quiet mode
968 * szCmdName [I] Inf or EXE filename to execute
969 * szInfSection [I] Inf section to install, NULL for DefaultInstall
970 * szDir [I] Path to extracted files
971 * szTitle [I] Title of all dialogs
972 * phEXE [O] Handle of EXE to wait for
973 * dwFlags [I] Flags; see include/advpub.h
974 * pvReserved [I] Reserved
978 * S_ASYNCHRONOUS OK, required to wait on phEXE
979 * ERROR_SUCCESS_REBOOT_REQUIRED Reboot required
980 * E_INVALIDARG Invalid argument given
981 * HRESULT_FROM_WIN32(ERROR_OLD_WIN_VERSION)
982 * Not supported on this Windows version
983 * E_UNEXPECTED Unexpected error
984 * HRESULT_FROM_WIN32(GetLastError()) Some other error
986 HRESULT WINAPI RunSetupCommandW(HWND hWnd, LPCWSTR szCmdName,
987 LPCWSTR szInfSection, LPCWSTR szDir,
988 LPCWSTR lpszTitle, HANDLE *phEXE,
989 DWORD dwFlags, LPVOID pvReserved)
994 TRACE("(%p, %s, %s, %s, %s, %p, %d, %p)\n",
995 hWnd, debugstr_w(szCmdName), debugstr_w(szInfSection),
996 debugstr_w(szDir), debugstr_w(lpszTitle),
997 phEXE, dwFlags, pvReserved);
999 if (dwFlags & RSC_FLAG_UPDHLPDLLS)
1000 FIXME("Unhandled flag: RSC_FLAG_UPDHLPDLLS\n");
1002 if (!szCmdName || !szDir)
1003 return E_INVALIDARG;
1005 if (!(dwFlags & RSC_FLAG_INF))
1006 return launch_exe(szCmdName, szDir, phEXE);
1008 ZeroMemory(&info, sizeof(ADVInfo));
1010 hr = install_init(szCmdName, szInfSection, szDir, dwFlags, &info);
1014 hr = spapi_install(&info);
1018 hr = adv_install(&info);
1021 install_release(&info);