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
61 typedef HRESULT (*iterate_fields_func
)(HINF hinf
, PCWSTR field
, void *arg
);
63 /* Advanced INF commands */
64 static const WCHAR CheckAdminRights
[] = {
65 'C','h','e','c','k','A','d','m','i','n','R','i','g','h','t','s',0
67 static const WCHAR DelDirs
[] = {'D','e','l','D','i','r','s',0};
68 static const WCHAR PerUserInstall
[] = {'P','e','r','U','s','e','r','I','n','s','t','a','l','l',0};
69 static const WCHAR RegisterOCXs
[] = {'R','e','g','i','s','t','e','r','O','C','X','s',0};
70 static const WCHAR RunPreSetupCommands
[] = {
71 'R','u','n','P','r','e','S','e','t','u','p','C','o','m','m','a','n','d','s',0
73 static const WCHAR RunPostSetupCommands
[] = {
74 'R','u','n','P','o','s','t','S','e','t','u','p','C','o','m','m','a','n','d','s',0
77 /* Advanced INF callbacks */
78 static HRESULT
del_dirs_callback(HINF hinf
, PCWSTR field
, void *arg
)
84 BOOL ok
= SetupFindFirstLineW(hinf
, field
, NULL
, &context
);
86 for (; ok
; ok
= SetupFindNextLine(&context
, &context
))
88 WCHAR directory
[MAX_INF_STRING_LENGTH
];
90 if (!SetupGetLineTextW(&context
, NULL
, NULL
, NULL
, directory
,
91 MAX_INF_STRING_LENGTH
, &size
))
94 if (DelNodeW(directory
, ADN_DEL_IF_EMPTY
))
101 static HRESULT
per_user_install_callback(HINF hinf
, PCWSTR field
, void *arg
)
103 PERUSERSECTIONW per_user
;
107 static const WCHAR disp_name
[] = {'D','i','s','p','l','a','y','N','a','m','e',0};
108 static const WCHAR version
[] = {'V','e','r','s','i','o','n',0};
109 static const WCHAR is_installed
[] = {'I','s','I','n','s','t','a','l','l','e','d',0};
110 static const WCHAR comp_id
[] = {'C','o','m','p','o','n','e','n','t','I','D',0};
111 static const WCHAR guid
[] = {'G','U','I','D',0};
112 static const WCHAR locale
[] = {'L','o','c','a','l','e',0};
113 static const WCHAR stub_path
[] = {'S','t','u','b','P','a','t','h',0};
115 per_user
.bRollback
= FALSE
;
116 per_user
.dwIsInstalled
= 0;
118 SetupGetLineTextW(NULL
, hinf
, field
, disp_name
, per_user
.szDispName
,
119 sizeof(per_user
.szDispName
) / sizeof(WCHAR
), &size
);
121 SetupGetLineTextW(NULL
, hinf
, field
, version
, per_user
.szVersion
,
122 sizeof(per_user
.szVersion
) / sizeof(WCHAR
), &size
);
124 if (SetupFindFirstLineW(hinf
, field
, is_installed
, &context
))
126 SetupGetIntField(&context
, 1, (PINT
)&per_user
.dwIsInstalled
);
129 SetupGetLineTextW(NULL
, hinf
, field
, comp_id
, per_user
.szCompID
,
130 sizeof(per_user
.szCompID
) / sizeof(WCHAR
), &size
);
132 SetupGetLineTextW(NULL
, hinf
, field
, guid
, per_user
.szGUID
,
133 sizeof(per_user
.szGUID
) / sizeof(WCHAR
), &size
);
135 SetupGetLineTextW(NULL
, hinf
, field
, locale
, per_user
.szLocale
,
136 sizeof(per_user
.szLocale
) / sizeof(WCHAR
), &size
);
138 SetupGetLineTextW(NULL
, hinf
, field
, stub_path
, per_user
.szStub
,
139 sizeof(per_user
.szStub
) / sizeof(WCHAR
), &size
);
141 return SetPerUserSecValuesW(&per_user
);
144 static HRESULT
register_ocxs_callback(HINF hinf
, PCWSTR field
, void *arg
)
150 BOOL ok
= SetupFindFirstLineW(hinf
, field
, NULL
, &context
);
152 for (; ok
; ok
= SetupFindNextLine(&context
, &context
))
154 WCHAR buffer
[MAX_INF_STRING_LENGTH
];
156 /* get OCX filename */
157 if (!SetupGetStringFieldW(&context
, 1, buffer
,
158 sizeof(buffer
) / sizeof(WCHAR
), NULL
))
161 hm
= LoadLibraryExW(buffer
, NULL
, LOAD_WITH_ALTERED_SEARCH_PATH
);
165 if (do_ocx_reg(hm
, TRUE
))
174 static HRESULT
run_setup_commands_callback(HINF hinf
, PCWSTR field
, void *arg
)
176 ADVInfo
*info
= (ADVInfo
*)arg
;
181 BOOL ok
= SetupFindFirstLineW(hinf
, field
, NULL
, &context
);
183 for (; ok
; ok
= SetupFindNextLine(&context
, &context
))
185 WCHAR buffer
[MAX_INF_STRING_LENGTH
];
187 if (!SetupGetLineTextW(&context
, NULL
, NULL
, NULL
, buffer
,
188 MAX_INF_STRING_LENGTH
, &size
))
191 if (launch_exe(buffer
, info
->working_dir
, NULL
))
198 /* sequentially returns pointers to parameters in a parameter list
199 * returns NULL if the parameter is empty, e.g. one,,three */
200 LPWSTR
get_parameter(LPWSTR
*params
, WCHAR separator
)
202 LPWSTR token
= *params
;
207 *params
= strchrW(*params
, separator
);
217 static BOOL
is_full_path(LPWSTR path
)
219 const int MIN_PATH_LEN
= 3;
221 if (!path
|| lstrlenW(path
) < MIN_PATH_LEN
)
224 if ((path
[1] == ':' && path
[2] == '\\') || (path
[0] == '\\' && path
[1] == '\\'))
230 /* retrieves the contents of a field, dynamically growing the buffer if necessary */
231 static WCHAR
*get_field_string(INFCONTEXT
*context
, DWORD index
, WCHAR
*buffer
,
232 WCHAR
*static_buffer
, DWORD
*size
)
236 if (SetupGetStringFieldW(context
, index
, buffer
, *size
, &required
)) return buffer
;
238 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
240 /* now grow the buffer */
241 if (buffer
!= static_buffer
) HeapFree(GetProcessHeap(), 0, buffer
);
242 if (!(buffer
= HeapAlloc(GetProcessHeap(), 0, required
*sizeof(WCHAR
)))) return NULL
;
244 if (SetupGetStringFieldW(context
, index
, buffer
, *size
, &required
)) return buffer
;
247 if (buffer
!= static_buffer
) HeapFree(GetProcessHeap(), 0, buffer
);
251 /* iterates over all fields of a certain key of a certain section */
252 static HRESULT
iterate_section_fields(HINF hinf
, PCWSTR section
, PCWSTR key
,
253 iterate_fields_func callback
, void *arg
)
255 WCHAR static_buffer
[200];
256 WCHAR
*buffer
= static_buffer
;
257 DWORD size
= sizeof(static_buffer
) / sizeof(WCHAR
);
261 BOOL ok
= SetupFindFirstLineW(hinf
, section
, key
, &context
);
264 UINT i
, count
= SetupGetFieldCount(&context
);
266 for (i
= 1; i
<= count
; i
++)
268 if (!(buffer
= get_field_string(&context
, i
, buffer
, static_buffer
, &size
)))
271 if ((hr
= callback(hinf
, buffer
, arg
)) != S_OK
)
275 ok
= SetupFindNextMatchLineW(&context
, key
, &context
);
281 if (buffer
!= static_buffer
) HeapFree(GetProcessHeap(), 0, buffer
);
285 static HRESULT
check_admin_rights(ADVInfo
*info
)
291 if (!SetupFindFirstLineW(info
->hinf
, info
->install_sec
,
292 CheckAdminRights
, &context
))
295 if (!SetupGetIntField(&context
, 1, &check
))
299 hr
= IsNTAdmin(0, NULL
) ? S_OK
: E_FAIL
;
304 /* performs a setupapi-level install of the INF file */
305 static HRESULT
spapi_install(ADVInfo
*info
)
311 context
= SetupInitDefaultQueueCallbackEx(NULL
, INVALID_HANDLE_VALUE
, 0, 0, NULL
);
313 return ADV_HRESULT(GetLastError());
315 ret
= SetupInstallFromInfSectionW(NULL
, info
->hinf
, info
->install_sec
,
316 SPINST_FILES
, NULL
, info
->working_dir
,
317 SP_COPY_NEWER
, SetupDefaultQueueCallbackW
,
318 context
, NULL
, NULL
);
321 res
= ADV_HRESULT(GetLastError());
322 SetupTermDefaultQueueCallback(context
);
327 SetupTermDefaultQueueCallback(context
);
329 ret
= SetupInstallFromInfSectionW(NULL
, info
->hinf
, info
->install_sec
,
330 SPINST_INIFILES
| SPINST_REGISTRY
| SPINST_REGSVR
,
331 HKEY_LOCAL_MACHINE
, NULL
, 0,
332 NULL
, NULL
, NULL
, NULL
);
334 return ADV_HRESULT(GetLastError());
339 /* processes the Advanced INF commands */
340 static HRESULT
adv_install(ADVInfo
*info
)
344 hr
= check_admin_rights(info
);
348 hr
= iterate_section_fields(info
->hinf
, info
->install_sec
, RunPreSetupCommands
,
349 run_setup_commands_callback
, info
);
353 hr
= iterate_section_fields(info
->hinf
, info
->install_sec
,
354 RegisterOCXs
, register_ocxs_callback
, NULL
);
358 hr
= iterate_section_fields(info
->hinf
, info
->install_sec
,
359 PerUserInstall
, per_user_install_callback
, info
);
363 hr
= iterate_section_fields(info
->hinf
, info
->install_sec
, RunPostSetupCommands
,
364 run_setup_commands_callback
, info
);
368 hr
= iterate_section_fields(info
->hinf
, info
->install_sec
,
369 DelDirs
, del_dirs_callback
, info
);
376 /* determines the proper working directory for the INF file */
377 static HRESULT
get_working_dir(ADVInfo
*info
, LPCWSTR inf_filename
, LPCWSTR working_dir
)
379 WCHAR path
[MAX_PATH
];
383 static const WCHAR backslash
[] = {'\\',0};
384 static const WCHAR inf_dir
[] = {'\\','I','N','F',0};
386 if ((ptr
= strrchrW(inf_filename
, '\\')))
388 len
= ptr
- inf_filename
+ 1;
391 else if (working_dir
&& *working_dir
)
393 len
= lstrlenW(working_dir
) + 1;
398 GetCurrentDirectoryW(MAX_PATH
, path
);
399 lstrcatW(path
, backslash
);
400 lstrcatW(path
, inf_filename
);
402 /* check if the INF file is in the current directory */
403 if (GetFileAttributesW(path
) != INVALID_FILE_ATTRIBUTES
)
405 GetCurrentDirectoryW(MAX_PATH
, path
);
409 /* default to the windows\inf directory if all else fails */
410 GetWindowsDirectoryW(path
, MAX_PATH
);
411 lstrcatW(path
, inf_dir
);
414 len
= lstrlenW(path
) + 1;
418 info
->working_dir
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
419 if (!info
->working_dir
)
420 return E_OUTOFMEMORY
;
422 lstrcpynW(info
->working_dir
, ptr
, len
);
427 /* loads the INF file and performs checks on it */
428 static HRESULT
install_init(LPCWSTR inf_filename
, LPCWSTR install_sec
,
429 LPCWSTR working_dir
, DWORD flags
, ADVInfo
*info
)
435 static const WCHAR backslash
[] = {'\\',0};
436 static const WCHAR default_install
[] = {
437 'D','e','f','a','u','l','t','I','n','s','t','a','l','l',0
440 if (!(ptr
= strrchrW(inf_filename
, '\\')))
445 info
->inf_filename
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
446 if (!info
->inf_filename
)
447 return E_OUTOFMEMORY
;
449 lstrcpyW(info
->inf_filename
, ptr
);
451 /* FIXME: determine the proper platform to install (NTx86, etc) */
452 if (!install_sec
|| !*install_sec
)
454 len
= sizeof(default_install
) - 1;
455 ptr
= default_install
;
459 len
= lstrlenW(install_sec
);
463 info
->install_sec
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
464 if (!info
->install_sec
)
465 return E_OUTOFMEMORY
;
467 lstrcpyW(info
->install_sec
, ptr
);
469 hr
= get_working_dir(info
, inf_filename
, working_dir
);
473 len
= lstrlenW(info
->working_dir
) + lstrlenW(info
->inf_filename
) + 2;
474 info
->inf_path
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
476 return E_OUTOFMEMORY
;
478 lstrcpyW(info
->inf_path
, info
->working_dir
);
479 lstrcatW(info
->inf_path
, backslash
);
480 lstrcatW(info
->inf_path
, info
->inf_filename
);
482 /* RunSetupCommand opens unmodifed filename parameter */
483 if (flags
& RSC_FLAG_INF
)
486 path
= info
->inf_path
;
488 info
->hinf
= SetupOpenInfFileW(path
, NULL
, INF_STYLE_WIN4
, NULL
);
489 if (info
->hinf
== INVALID_HANDLE_VALUE
)
490 return ADV_HRESULT(GetLastError());
492 set_ldids(info
->hinf
, info
->install_sec
, info
->working_dir
);
494 /* FIXME: check that the INF is advanced */
497 info
->need_reboot
= FALSE
;
502 /* release the install instance information */
503 static void install_release(ADVInfo
*info
)
505 if (info
->hinf
&& info
->hinf
!= INVALID_HANDLE_VALUE
)
506 SetupCloseInfFile(info
->hinf
);
508 HeapFree(GetProcessHeap(), 0, info
->inf_path
);
509 HeapFree(GetProcessHeap(), 0, info
->inf_filename
);
510 HeapFree(GetProcessHeap(), 0, info
->install_sec
);
511 HeapFree(GetProcessHeap(), 0, info
->working_dir
);
514 /* this structure very closely resembles parameters of RunSetupCommand() */
522 } SETUPCOMMAND_PARAMS
;
530 LPCWSTR section_name
;
531 } SETUPCOMMAND_PARAMSW
;
533 /* internal: see DoInfInstall */
534 static HRESULT
DoInfInstallW(const SETUPCOMMAND_PARAMSW
*setup
)
539 TRACE("(%p)\n", setup
);
541 ZeroMemory(&info
, sizeof(ADVInfo
));
543 hr
= install_init(setup
->inf_name
, setup
->section_name
, setup
->dir
, 0, &info
);
547 hr
= spapi_install(&info
);
551 hr
= adv_install(&info
);
554 install_release(&info
);
559 /***********************************************************************
560 * DoInfInstall (ADVPACK.@)
562 * Install an INF section.
565 * setup [I] Structure containing install information.
569 * HRESULT_FROM_WIN32(GetLastError()) Some other error
571 HRESULT WINAPI
DoInfInstall(const SETUPCOMMAND_PARAMS
*setup
)
573 UNICODE_STRING title
, inf
, section
, dir
;
574 SETUPCOMMAND_PARAMSW params
;
580 RtlCreateUnicodeStringFromAsciiz(&title
, setup
->title
);
581 RtlCreateUnicodeStringFromAsciiz(&inf
, setup
->inf_name
);
582 RtlCreateUnicodeStringFromAsciiz(§ion
, setup
->section_name
);
583 RtlCreateUnicodeStringFromAsciiz(&dir
, setup
->dir
);
585 params
.title
= title
.Buffer
;
586 params
.inf_name
= inf
.Buffer
;
587 params
.section_name
= section
.Buffer
;
588 params
.dir
= dir
.Buffer
;
589 params
.hwnd
= setup
->hwnd
;
591 hr
= DoInfInstallW(¶ms
);
593 RtlFreeUnicodeString(&title
);
594 RtlFreeUnicodeString(&inf
);
595 RtlFreeUnicodeString(§ion
);
596 RtlFreeUnicodeString(&dir
);
601 /***********************************************************************
602 * ExecuteCabA (ADVPACK.@)
606 HRESULT WINAPI
ExecuteCabA(HWND hwnd
, CABINFOA
* pCab
, LPVOID pReserved
)
608 UNICODE_STRING cab
, inf
, section
;
612 TRACE("(%p, %p, %p)\n", hwnd
, pCab
, pReserved
);
619 RtlCreateUnicodeStringFromAsciiz(&cab
, pCab
->pszCab
);
620 cabinfo
.pszCab
= cab
.Buffer
;
623 cabinfo
.pszCab
= NULL
;
625 RtlCreateUnicodeStringFromAsciiz(&inf
, pCab
->pszInf
);
626 RtlCreateUnicodeStringFromAsciiz(§ion
, pCab
->pszSection
);
628 MultiByteToWideChar(CP_ACP
, 0, pCab
->szSrcPath
, -1, cabinfo
.szSrcPath
,
629 sizeof(cabinfo
.szSrcPath
) / sizeof(WCHAR
));
631 cabinfo
.pszInf
= inf
.Buffer
;
632 cabinfo
.pszSection
= section
.Buffer
;
633 cabinfo
.dwFlags
= pCab
->dwFlags
;
635 hr
= ExecuteCabW(hwnd
, &cabinfo
, pReserved
);
638 RtlFreeUnicodeString(&cab
);
640 RtlFreeUnicodeString(&inf
);
641 RtlFreeUnicodeString(§ion
);
646 /***********************************************************************
647 * ExecuteCabW (ADVPACK.@)
649 * Installs the INF file extracted from a specified cabinet file.
652 * hwnd [I] Handle to the window used for the display.
653 * pCab [I] Information about the cabinet file.
654 * pReserved [I] Reserved. Must be NULL.
660 HRESULT WINAPI
ExecuteCabW(HWND hwnd
, CABINFOW
* pCab
, LPVOID pReserved
)
665 TRACE("(%p, %p, %p)\n", hwnd
, pCab
, pReserved
);
667 ZeroMemory(&info
, sizeof(ADVInfo
));
669 if (pCab
->pszCab
&& *pCab
->pszCab
)
670 FIXME("Cab archive not extracted!\n");
672 hr
= install_init(pCab
->pszInf
, pCab
->pszSection
, pCab
->szSrcPath
, pCab
->dwFlags
, &info
);
676 hr
= spapi_install(&info
);
680 hr
= adv_install(&info
);
683 install_release(&info
);
688 /***********************************************************************
689 * LaunchINFSectionA (ADVPACK.@)
691 * See LaunchINFSectionW.
693 INT WINAPI
LaunchINFSectionA(HWND hWnd
, HINSTANCE hInst
, LPSTR cmdline
, INT show
)
698 TRACE("(%p, %p, %s, %i)\n", hWnd
, hInst
, debugstr_a(cmdline
), show
);
703 RtlCreateUnicodeStringFromAsciiz(&cmd
, cmdline
);
705 hr
= LaunchINFSectionW(hWnd
, hInst
, cmd
.Buffer
, show
);
707 RtlFreeUnicodeString(&cmd
);
712 /***********************************************************************
713 * LaunchINFSectionW (ADVPACK.@)
715 * Installs an INF section without BACKUP/ROLLBACK capabilities.
718 * hWnd [I] Handle to parent window, NULL for desktop.
719 * hInst [I] Instance of the process.
720 * cmdline [I] Contains parameters in the order INF,section,flags,reboot.
721 * show [I] How the window should be shown.
724 * Success: ADV_SUCCESS.
725 * Failure: ADV_FAILURE.
728 * INF - Filename of the INF to launch.
729 * section - INF section to install.
730 * flags - see advpub.h.
731 * reboot - smart reboot behavior
733 * 'I' Reboot if needed (default).
736 INT WINAPI
LaunchINFSectionW(HWND hWnd
, HINSTANCE hInst
, LPWSTR cmdline
, INT show
)
739 LPWSTR cmdline_copy
, cmdline_ptr
;
740 LPWSTR inf_filename
, install_sec
;
745 TRACE("(%p, %p, %s, %d)\n", hWnd
, hInst
, debugstr_w(cmdline
), show
);
750 cmdline_copy
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(cmdline
) + 1) * sizeof(WCHAR
));
751 cmdline_ptr
= cmdline_copy
;
752 lstrcpyW(cmdline_copy
, cmdline
);
754 inf_filename
= get_parameter(&cmdline_ptr
, ',');
755 install_sec
= get_parameter(&cmdline_ptr
, ',');
757 str_flags
= get_parameter(&cmdline_ptr
, ',');
759 flags
= atolW(str_flags
);
761 ZeroMemory(&info
, sizeof(ADVInfo
));
763 hr
= install_init(inf_filename
, install_sec
, NULL
, flags
, &info
);
767 hr
= spapi_install(&info
);
771 hr
= adv_install(&info
);
774 install_release(&info
);
775 HeapFree(GetProcessHeap(), 0, cmdline_copy
);
777 return SUCCEEDED(hr
) ? ADV_SUCCESS
: ADV_FAILURE
;
780 /***********************************************************************
781 * LaunchINFSectionExA (ADVPACK.@)
783 * See LaunchINFSectionExW.
785 HRESULT WINAPI
LaunchINFSectionExA(HWND hWnd
, HINSTANCE hInst
, LPSTR cmdline
, INT show
)
790 TRACE("(%p, %p, %s, %i)\n", hWnd
, hInst
, debugstr_a(cmdline
), show
);
795 RtlCreateUnicodeStringFromAsciiz(&cmd
, cmdline
);
797 hr
= LaunchINFSectionExW(hWnd
, hInst
, cmd
.Buffer
, show
);
799 RtlFreeUnicodeString(&cmd
);
804 /***********************************************************************
805 * LaunchINFSectionExW (ADVPACK.@)
807 * Installs an INF section with BACKUP/ROLLBACK capabilities.
810 * hWnd [I] Handle to parent window, NULL for desktop.
811 * hInst [I] Instance of the process.
812 * cmdline [I] Contains parameters in the order INF,section,CAB,flags,reboot.
813 * show [I] How the window should be shown.
816 * Success: ADV_SUCCESS.
817 * Failure: ADV_FAILURE.
820 * INF - Filename of the INF to launch.
821 * section - INF section to install.
822 * flags - see advpub.h.
823 * reboot - smart reboot behavior
825 * 'I' Reboot if needed (default).
829 * Doesn't handle the reboot flag.
831 HRESULT WINAPI
LaunchINFSectionExW(HWND hWnd
, HINSTANCE hInst
, LPWSTR cmdline
, INT show
)
833 LPWSTR cmdline_copy
, cmdline_ptr
;
838 TRACE("(%p, %p, %s, %d)\n", hWnd
, hInst
, debugstr_w(cmdline
), show
);
843 cmdline_copy
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(cmdline
) + 1) * sizeof(WCHAR
));
844 cmdline_ptr
= cmdline_copy
;
845 lstrcpyW(cmdline_copy
, cmdline
);
847 cabinfo
.pszInf
= get_parameter(&cmdline_ptr
, ',');
848 cabinfo
.pszSection
= get_parameter(&cmdline_ptr
, ',');
849 cabinfo
.pszCab
= get_parameter(&cmdline_ptr
, ',');
850 *cabinfo
.szSrcPath
= '\0';
852 flags
= get_parameter(&cmdline_ptr
, ',');
854 cabinfo
.dwFlags
= atolW(flags
);
856 if (!is_full_path(cabinfo
.pszCab
) && !is_full_path(cabinfo
.pszInf
))
858 HeapFree(GetProcessHeap(), 0, cmdline_copy
);
862 /* get the source path from the cab filename */
863 if (cabinfo
.pszCab
&& *cabinfo
.pszCab
)
865 if (!is_full_path(cabinfo
.pszCab
))
866 lstrcpyW(cabinfo
.szSrcPath
, cabinfo
.pszInf
);
868 lstrcpyW(cabinfo
.szSrcPath
, cabinfo
.pszCab
);
870 ptr
= strrchrW(cabinfo
.szSrcPath
, '\\');
874 hr
= ExecuteCabW(hWnd
, &cabinfo
, NULL
);
875 HeapFree(GetProcessHeap(), 0, cmdline_copy
);
876 return SUCCEEDED(hr
) ? ADV_SUCCESS
: ADV_FAILURE
;
879 HRESULT
launch_exe(LPCWSTR cmd
, LPCWSTR dir
, HANDLE
*phEXE
)
882 PROCESS_INFORMATION pi
;
884 if (phEXE
) *phEXE
= NULL
;
886 ZeroMemory(&pi
, sizeof(pi
));
887 ZeroMemory(&si
, sizeof(si
));
890 if (!CreateProcessW(NULL
, (LPWSTR
)cmd
, NULL
, NULL
, FALSE
,
891 CREATE_DEFAULT_ERROR_MODE
| CREATE_NEW_PROCESS_GROUP
,
892 NULL
, dir
, &si
, &pi
))
894 return HRESULT_FROM_WIN32(GetLastError());
897 CloseHandle(pi
.hThread
);
901 *phEXE
= pi
.hProcess
;
902 return S_ASYNCHRONOUS
;
905 /* wait for the child process to finish */
906 WaitForSingleObject(pi
.hProcess
, INFINITE
);
907 CloseHandle(pi
.hProcess
);
912 /***********************************************************************
913 * RunSetupCommandA (ADVPACK.@)
915 * See RunSetupCommandW.
917 HRESULT WINAPI
RunSetupCommandA(HWND hWnd
, LPCSTR szCmdName
,
918 LPCSTR szInfSection
, LPCSTR szDir
,
919 LPCSTR lpszTitle
, HANDLE
*phEXE
,
920 DWORD dwFlags
, LPVOID pvReserved
)
922 UNICODE_STRING cmdname
, infsec
;
923 UNICODE_STRING dir
, title
;
926 TRACE("(%p, %s, %s, %s, %s, %p, %d, %p)\n",
927 hWnd
, debugstr_a(szCmdName
), debugstr_a(szInfSection
),
928 debugstr_a(szDir
), debugstr_a(lpszTitle
),
929 phEXE
, dwFlags
, pvReserved
);
931 if (!szCmdName
|| !szDir
)
934 RtlCreateUnicodeStringFromAsciiz(&cmdname
, szCmdName
);
935 RtlCreateUnicodeStringFromAsciiz(&infsec
, szInfSection
);
936 RtlCreateUnicodeStringFromAsciiz(&dir
, szDir
);
937 RtlCreateUnicodeStringFromAsciiz(&title
, lpszTitle
);
939 hr
= RunSetupCommandW(hWnd
, cmdname
.Buffer
, infsec
.Buffer
, dir
.Buffer
,
940 title
.Buffer
, phEXE
, dwFlags
, pvReserved
);
942 RtlFreeUnicodeString(&cmdname
);
943 RtlFreeUnicodeString(&infsec
);
944 RtlFreeUnicodeString(&dir
);
945 RtlFreeUnicodeString(&title
);
950 /***********************************************************************
951 * RunSetupCommandW (ADVPACK.@)
953 * Executes an install section in an INF file or a program.
956 * hWnd [I] Handle to parent window, NULL for quiet mode
957 * szCmdName [I] Inf or EXE filename to execute
958 * szInfSection [I] Inf section to install, NULL for DefaultInstall
959 * szDir [I] Path to extracted files
960 * szTitle [I] Title of all dialogs
961 * phEXE [O] Handle of EXE to wait for
962 * dwFlags [I] Flags; see include/advpub.h
963 * pvReserved [I] Reserved
967 * S_ASYNCHRONOUS OK, required to wait on phEXE
968 * ERROR_SUCCESS_REBOOT_REQUIRED Reboot required
969 * E_INVALIDARG Invalid argument given
970 * HRESULT_FROM_WIN32(ERROR_OLD_WIN_VERSION)
971 * Not supported on this Windows version
972 * E_UNEXPECTED Unexpected error
973 * HRESULT_FROM_WIN32(GetLastError()) Some other error
975 HRESULT WINAPI
RunSetupCommandW(HWND hWnd
, LPCWSTR szCmdName
,
976 LPCWSTR szInfSection
, LPCWSTR szDir
,
977 LPCWSTR lpszTitle
, HANDLE
*phEXE
,
978 DWORD dwFlags
, LPVOID pvReserved
)
983 TRACE("(%p, %s, %s, %s, %s, %p, %d, %p)\n",
984 hWnd
, debugstr_w(szCmdName
), debugstr_w(szInfSection
),
985 debugstr_w(szDir
), debugstr_w(lpszTitle
),
986 phEXE
, dwFlags
, pvReserved
);
988 if (dwFlags
& RSC_FLAG_UPDHLPDLLS
)
989 FIXME("Unhandled flag: RSC_FLAG_UPDHLPDLLS\n");
991 if (!szCmdName
|| !szDir
)
994 if (!(dwFlags
& RSC_FLAG_INF
))
995 return launch_exe(szCmdName
, szDir
, phEXE
);
997 ZeroMemory(&info
, sizeof(ADVInfo
));
999 hr
= install_init(szCmdName
, szInfSection
, szDir
, dwFlags
, &info
);
1003 hr
= spapi_install(&info
);
1007 hr
= adv_install(&info
);
1010 install_release(&info
);