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) ((HRESULT)((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
, const 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
, const 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
) != S_OK
)
101 static HRESULT
per_user_install_callback(HINF hinf
, PCWSTR field
, const 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
, const 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
);
164 if (do_ocx_reg(hm
, TRUE
, NULL
, NULL
) != S_OK
)
174 /* FIXME: display a message box */
182 static HRESULT
run_setup_commands_callback(HINF hinf
, PCWSTR field
, const void *arg
)
184 const ADVInfo
*info
= (const ADVInfo
*)arg
;
189 BOOL ok
= SetupFindFirstLineW(hinf
, field
, NULL
, &context
);
191 for (; ok
; ok
= SetupFindNextLine(&context
, &context
))
193 WCHAR buffer
[MAX_INF_STRING_LENGTH
];
195 if (!SetupGetLineTextW(&context
, NULL
, NULL
, NULL
, buffer
,
196 MAX_INF_STRING_LENGTH
, &size
))
199 if (launch_exe(buffer
, info
->working_dir
, NULL
) != S_OK
)
206 /* sequentially returns pointers to parameters in a parameter list
207 * returns NULL if the parameter is empty, e.g. one,,three */
208 LPWSTR
get_parameter(LPWSTR
*params
, WCHAR separator
, BOOL quoted
)
210 LPWSTR token
= *params
;
215 if (quoted
&& *token
== '"')
217 WCHAR
*end
= strchrW(token
+ 1, '"');
226 *params
= strchrW(*params
, separator
);
236 static BOOL
is_full_path(LPCWSTR path
)
238 const int MIN_PATH_LEN
= 3;
240 if (!path
|| lstrlenW(path
) < MIN_PATH_LEN
)
243 if ((path
[1] == ':' && path
[2] == '\\') || (path
[0] == '\\' && path
[1] == '\\'))
249 /* retrieves the contents of a field, dynamically growing the buffer if necessary */
250 static WCHAR
*get_field_string(INFCONTEXT
*context
, DWORD index
, WCHAR
*buffer
,
251 const WCHAR
*static_buffer
, DWORD
*size
)
255 if (SetupGetStringFieldW(context
, index
, buffer
, *size
, &required
)) return buffer
;
257 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
259 /* now grow the buffer */
260 if (buffer
!= static_buffer
) HeapFree(GetProcessHeap(), 0, buffer
);
261 if (!(buffer
= HeapAlloc(GetProcessHeap(), 0, required
*sizeof(WCHAR
)))) return NULL
;
263 if (SetupGetStringFieldW(context
, index
, buffer
, *size
, &required
)) return buffer
;
266 if (buffer
!= static_buffer
) HeapFree(GetProcessHeap(), 0, buffer
);
270 /* iterates over all fields of a certain key of a certain section */
271 static HRESULT
iterate_section_fields(HINF hinf
, PCWSTR section
, PCWSTR key
,
272 iterate_fields_func callback
, void *arg
)
274 WCHAR static_buffer
[200];
275 WCHAR
*buffer
= static_buffer
;
276 DWORD size
= sizeof(static_buffer
) / sizeof(WCHAR
);
280 BOOL ok
= SetupFindFirstLineW(hinf
, section
, key
, &context
);
283 UINT i
, count
= SetupGetFieldCount(&context
);
285 for (i
= 1; i
<= count
; i
++)
287 if (!(buffer
= get_field_string(&context
, i
, buffer
, static_buffer
, &size
)))
290 if ((hr
= callback(hinf
, buffer
, arg
)) != S_OK
)
294 ok
= SetupFindNextMatchLineW(&context
, key
, &context
);
300 if (buffer
!= static_buffer
) HeapFree(GetProcessHeap(), 0, buffer
);
304 static HRESULT
check_admin_rights(const ADVInfo
*info
)
310 if (!SetupFindFirstLineW(info
->hinf
, info
->install_sec
,
311 CheckAdminRights
, &context
))
314 if (!SetupGetIntField(&context
, 1, &check
))
318 hr
= IsNTAdmin(0, NULL
) ? S_OK
: E_FAIL
;
323 /* performs a setupapi-level install of the INF file */
324 static HRESULT
spapi_install(const ADVInfo
*info
)
330 context
= SetupInitDefaultQueueCallbackEx(NULL
, INVALID_HANDLE_VALUE
, 0, 0, NULL
);
332 return ADV_HRESULT(GetLastError());
334 ret
= SetupInstallFromInfSectionW(NULL
, info
->hinf
, info
->install_sec
,
335 SPINST_FILES
, NULL
, info
->working_dir
,
336 SP_COPY_NEWER
, SetupDefaultQueueCallbackW
,
337 context
, NULL
, NULL
);
340 res
= ADV_HRESULT(GetLastError());
341 SetupTermDefaultQueueCallback(context
);
346 SetupTermDefaultQueueCallback(context
);
348 ret
= SetupInstallFromInfSectionW(NULL
, info
->hinf
, info
->install_sec
,
349 SPINST_INIFILES
| SPINST_REGISTRY
| SPINST_REGSVR
,
350 HKEY_LOCAL_MACHINE
, NULL
, 0,
351 NULL
, NULL
, NULL
, NULL
);
353 return ADV_HRESULT(GetLastError());
358 /* processes the Advanced INF commands */
359 static HRESULT
adv_install(ADVInfo
*info
)
363 hr
= check_admin_rights(info
);
367 hr
= iterate_section_fields(info
->hinf
, info
->install_sec
, RunPreSetupCommands
,
368 run_setup_commands_callback
, info
);
373 hr
= iterate_section_fields(info
->hinf
, info
->install_sec
,
374 RegisterOCXs
, register_ocxs_callback
, NULL
);
379 hr
= iterate_section_fields(info
->hinf
, info
->install_sec
,
380 PerUserInstall
, per_user_install_callback
, info
);
384 hr
= iterate_section_fields(info
->hinf
, info
->install_sec
, RunPostSetupCommands
,
385 run_setup_commands_callback
, info
);
389 hr
= iterate_section_fields(info
->hinf
, info
->install_sec
,
390 DelDirs
, del_dirs_callback
, info
);
397 /* determines the proper working directory for the INF file */
398 static HRESULT
get_working_dir(ADVInfo
*info
, LPCWSTR inf_filename
, LPCWSTR working_dir
)
400 WCHAR path
[MAX_PATH
];
404 static const WCHAR backslash
[] = {'\\',0};
405 static const WCHAR inf_dir
[] = {'\\','I','N','F',0};
407 if ((ptr
= strrchrW(inf_filename
, '\\')))
409 len
= ptr
- inf_filename
+ 1;
412 else if (working_dir
&& *working_dir
)
414 len
= lstrlenW(working_dir
) + 1;
419 GetCurrentDirectoryW(MAX_PATH
, path
);
420 lstrcatW(path
, backslash
);
421 lstrcatW(path
, inf_filename
);
423 /* check if the INF file is in the current directory */
424 if (GetFileAttributesW(path
) != INVALID_FILE_ATTRIBUTES
)
426 GetCurrentDirectoryW(MAX_PATH
, path
);
430 /* default to the windows\inf directory if all else fails */
431 GetWindowsDirectoryW(path
, MAX_PATH
);
432 lstrcatW(path
, inf_dir
);
435 len
= lstrlenW(path
) + 1;
439 info
->working_dir
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
440 if (!info
->working_dir
)
441 return E_OUTOFMEMORY
;
443 lstrcpynW(info
->working_dir
, ptr
, len
);
448 /* loads the INF file and performs checks on it */
449 static HRESULT
install_init(LPCWSTR inf_filename
, LPCWSTR install_sec
,
450 LPCWSTR working_dir
, DWORD flags
, ADVInfo
*info
)
456 static const WCHAR backslash
[] = {'\\',0};
457 static const WCHAR default_install
[] = {
458 'D','e','f','a','u','l','t','I','n','s','t','a','l','l',0
461 if (!(ptr
= strrchrW(inf_filename
, '\\')))
466 info
->inf_filename
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
467 if (!info
->inf_filename
)
468 return E_OUTOFMEMORY
;
470 lstrcpyW(info
->inf_filename
, ptr
);
472 /* FIXME: determine the proper platform to install (NTx86, etc) */
473 if (!install_sec
|| !*install_sec
)
475 len
= sizeof(default_install
) - 1;
476 ptr
= default_install
;
480 len
= lstrlenW(install_sec
);
484 info
->install_sec
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
485 if (!info
->install_sec
)
486 return E_OUTOFMEMORY
;
488 lstrcpyW(info
->install_sec
, ptr
);
490 hr
= get_working_dir(info
, inf_filename
, working_dir
);
494 len
= lstrlenW(info
->working_dir
) + lstrlenW(info
->inf_filename
) + 2;
495 info
->inf_path
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
497 return E_OUTOFMEMORY
;
499 lstrcpyW(info
->inf_path
, info
->working_dir
);
500 lstrcatW(info
->inf_path
, backslash
);
501 lstrcatW(info
->inf_path
, info
->inf_filename
);
503 /* RunSetupCommand opens unmodifed filename parameter */
504 if (flags
& RSC_FLAG_INF
)
507 path
= info
->inf_path
;
509 info
->hinf
= SetupOpenInfFileW(path
, NULL
, INF_STYLE_WIN4
, NULL
);
510 if (info
->hinf
== INVALID_HANDLE_VALUE
)
511 return ADV_HRESULT(GetLastError());
513 set_ldids(info
->hinf
, info
->install_sec
, info
->working_dir
);
515 /* FIXME: check that the INF is advanced */
518 info
->need_reboot
= FALSE
;
523 /* release the install instance information */
524 static void install_release(const ADVInfo
*info
)
526 SetupCloseInfFile(info
->hinf
);
528 HeapFree(GetProcessHeap(), 0, info
->inf_path
);
529 HeapFree(GetProcessHeap(), 0, info
->inf_filename
);
530 HeapFree(GetProcessHeap(), 0, info
->install_sec
);
531 HeapFree(GetProcessHeap(), 0, info
->working_dir
);
534 /* this structure very closely resembles parameters of RunSetupCommand() */
542 } SETUPCOMMAND_PARAMS
;
550 LPCWSTR section_name
;
551 } SETUPCOMMAND_PARAMSW
;
553 /* internal: see DoInfInstall */
554 static HRESULT
DoInfInstallW(const SETUPCOMMAND_PARAMSW
*setup
)
559 TRACE("(%p)\n", setup
);
561 ZeroMemory(&info
, sizeof(ADVInfo
));
563 hr
= install_init(setup
->inf_name
, setup
->section_name
, setup
->dir
, 0, &info
);
567 hr
= spapi_install(&info
);
571 hr
= adv_install(&info
);
574 install_release(&info
);
579 /***********************************************************************
580 * DoInfInstall (ADVPACK.@)
582 * Install an INF section.
585 * setup [I] Structure containing install information.
589 * HRESULT_FROM_WIN32(GetLastError()) Some other error
591 HRESULT WINAPI
DoInfInstall(const SETUPCOMMAND_PARAMS
*setup
)
593 UNICODE_STRING title
, inf
, section
, dir
;
594 SETUPCOMMAND_PARAMSW params
;
600 RtlCreateUnicodeStringFromAsciiz(&title
, setup
->title
);
601 RtlCreateUnicodeStringFromAsciiz(&inf
, setup
->inf_name
);
602 RtlCreateUnicodeStringFromAsciiz(§ion
, setup
->section_name
);
603 RtlCreateUnicodeStringFromAsciiz(&dir
, setup
->dir
);
605 params
.title
= title
.Buffer
;
606 params
.inf_name
= inf
.Buffer
;
607 params
.section_name
= section
.Buffer
;
608 params
.dir
= dir
.Buffer
;
609 params
.hwnd
= setup
->hwnd
;
611 hr
= DoInfInstallW(¶ms
);
613 RtlFreeUnicodeString(&title
);
614 RtlFreeUnicodeString(&inf
);
615 RtlFreeUnicodeString(§ion
);
616 RtlFreeUnicodeString(&dir
);
621 /***********************************************************************
622 * ExecuteCabA (ADVPACK.@)
626 HRESULT WINAPI
ExecuteCabA(HWND hwnd
, CABINFOA
* pCab
, LPVOID pReserved
)
628 UNICODE_STRING cab
, inf
, section
;
632 TRACE("(%p, %p, %p)\n", hwnd
, pCab
, pReserved
);
639 RtlCreateUnicodeStringFromAsciiz(&cab
, pCab
->pszCab
);
640 cabinfo
.pszCab
= cab
.Buffer
;
643 cabinfo
.pszCab
= NULL
;
645 RtlCreateUnicodeStringFromAsciiz(&inf
, pCab
->pszInf
);
646 RtlCreateUnicodeStringFromAsciiz(§ion
, pCab
->pszSection
);
648 MultiByteToWideChar(CP_ACP
, 0, pCab
->szSrcPath
, -1, cabinfo
.szSrcPath
,
649 sizeof(cabinfo
.szSrcPath
) / sizeof(WCHAR
));
651 cabinfo
.pszInf
= inf
.Buffer
;
652 cabinfo
.pszSection
= section
.Buffer
;
653 cabinfo
.dwFlags
= pCab
->dwFlags
;
655 hr
= ExecuteCabW(hwnd
, &cabinfo
, pReserved
);
658 RtlFreeUnicodeString(&cab
);
660 RtlFreeUnicodeString(&inf
);
661 RtlFreeUnicodeString(§ion
);
666 /***********************************************************************
667 * ExecuteCabW (ADVPACK.@)
669 * Installs the INF file extracted from a specified cabinet file.
672 * hwnd [I] Handle to the window used for the display.
673 * pCab [I] Information about the cabinet file.
674 * pReserved [I] Reserved. Must be NULL.
680 HRESULT WINAPI
ExecuteCabW(HWND hwnd
, CABINFOW
* pCab
, LPVOID pReserved
)
685 TRACE("(%p, %p, %p)\n", hwnd
, pCab
, pReserved
);
687 ZeroMemory(&info
, sizeof(ADVInfo
));
689 if (pCab
->pszCab
&& *pCab
->pszCab
)
690 FIXME("Cab archive not extracted!\n");
692 hr
= install_init(pCab
->pszInf
, pCab
->pszSection
, pCab
->szSrcPath
, pCab
->dwFlags
, &info
);
696 hr
= spapi_install(&info
);
700 hr
= adv_install(&info
);
703 install_release(&info
);
708 /***********************************************************************
709 * LaunchINFSectionA (ADVPACK.@)
711 * See LaunchINFSectionW.
713 INT WINAPI
LaunchINFSectionA(HWND hWnd
, HINSTANCE hInst
, LPSTR cmdline
, INT show
)
718 TRACE("(%p, %p, %s, %i)\n", hWnd
, hInst
, debugstr_a(cmdline
), show
);
723 RtlCreateUnicodeStringFromAsciiz(&cmd
, cmdline
);
725 hr
= LaunchINFSectionW(hWnd
, hInst
, cmd
.Buffer
, show
);
727 RtlFreeUnicodeString(&cmd
);
732 /***********************************************************************
733 * LaunchINFSectionW (ADVPACK.@)
735 * Installs an INF section without BACKUP/ROLLBACK capabilities.
738 * hWnd [I] Handle to parent window, NULL for desktop.
739 * hInst [I] Instance of the process.
740 * cmdline [I] Contains parameters in the order INF,section,flags,reboot.
741 * show [I] How the window should be shown.
744 * Success: ADV_SUCCESS.
745 * Failure: ADV_FAILURE.
748 * INF - Filename of the INF to launch.
749 * section - INF section to install.
750 * flags - see advpub.h.
751 * reboot - smart reboot behavior
753 * 'I' Reboot if needed (default).
756 INT WINAPI
LaunchINFSectionW(HWND hWnd
, HINSTANCE hInst
, LPWSTR cmdline
, INT show
)
759 LPWSTR cmdline_copy
, cmdline_ptr
;
760 LPWSTR inf_filename
, install_sec
;
765 TRACE("(%p, %p, %s, %d)\n", hWnd
, hInst
, debugstr_w(cmdline
), show
);
770 cmdline_copy
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(cmdline
) + 1) * sizeof(WCHAR
));
771 cmdline_ptr
= cmdline_copy
;
772 lstrcpyW(cmdline_copy
, cmdline
);
774 inf_filename
= get_parameter(&cmdline_ptr
, ',', TRUE
);
775 install_sec
= get_parameter(&cmdline_ptr
, ',', TRUE
);
777 str_flags
= get_parameter(&cmdline_ptr
, ',', TRUE
);
779 flags
= atolW(str_flags
);
781 ZeroMemory(&info
, sizeof(ADVInfo
));
783 hr
= install_init(inf_filename
, install_sec
, NULL
, flags
, &info
);
787 hr
= spapi_install(&info
);
791 hr
= adv_install(&info
);
794 install_release(&info
);
795 HeapFree(GetProcessHeap(), 0, cmdline_copy
);
797 return SUCCEEDED(hr
) ? ADV_SUCCESS
: ADV_FAILURE
;
800 /***********************************************************************
801 * LaunchINFSectionExA (ADVPACK.@)
803 * See LaunchINFSectionExW.
805 HRESULT WINAPI
LaunchINFSectionExA(HWND hWnd
, HINSTANCE hInst
, LPSTR cmdline
, INT show
)
810 TRACE("(%p, %p, %s, %i)\n", hWnd
, hInst
, debugstr_a(cmdline
), show
);
815 RtlCreateUnicodeStringFromAsciiz(&cmd
, cmdline
);
817 hr
= LaunchINFSectionExW(hWnd
, hInst
, cmd
.Buffer
, show
);
819 RtlFreeUnicodeString(&cmd
);
824 /***********************************************************************
825 * LaunchINFSectionExW (ADVPACK.@)
827 * Installs an INF section with BACKUP/ROLLBACK capabilities.
830 * hWnd [I] Handle to parent window, NULL for desktop.
831 * hInst [I] Instance of the process.
832 * cmdline [I] Contains parameters in the order INF,section,CAB,flags,reboot.
833 * show [I] How the window should be shown.
836 * Success: ADV_SUCCESS.
837 * Failure: ADV_FAILURE.
840 * INF - Filename of the INF to launch.
841 * section - INF section to install.
842 * flags - see advpub.h.
843 * reboot - smart reboot behavior
845 * 'I' Reboot if needed (default).
849 * Doesn't handle the reboot flag.
851 HRESULT WINAPI
LaunchINFSectionExW(HWND hWnd
, HINSTANCE hInst
, LPWSTR cmdline
, INT show
)
853 LPWSTR cmdline_copy
, cmdline_ptr
;
858 TRACE("(%p, %p, %s, %d)\n", hWnd
, hInst
, debugstr_w(cmdline
), show
);
863 cmdline_copy
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(cmdline
) + 1) * sizeof(WCHAR
));
864 cmdline_ptr
= cmdline_copy
;
865 lstrcpyW(cmdline_copy
, cmdline
);
867 cabinfo
.pszInf
= get_parameter(&cmdline_ptr
, ',', TRUE
);
868 cabinfo
.pszSection
= get_parameter(&cmdline_ptr
, ',', TRUE
);
869 cabinfo
.pszCab
= get_parameter(&cmdline_ptr
, ',', TRUE
);
870 *cabinfo
.szSrcPath
= '\0';
872 flags
= get_parameter(&cmdline_ptr
, ',', TRUE
);
874 cabinfo
.dwFlags
= atolW(flags
);
876 if (!is_full_path(cabinfo
.pszCab
) && !is_full_path(cabinfo
.pszInf
))
878 HeapFree(GetProcessHeap(), 0, cmdline_copy
);
882 /* get the source path from the cab filename */
883 if (cabinfo
.pszCab
&& *cabinfo
.pszCab
)
885 if (!is_full_path(cabinfo
.pszCab
))
886 lstrcpyW(cabinfo
.szSrcPath
, cabinfo
.pszInf
);
888 lstrcpyW(cabinfo
.szSrcPath
, cabinfo
.pszCab
);
890 ptr
= strrchrW(cabinfo
.szSrcPath
, '\\');
894 hr
= ExecuteCabW(hWnd
, &cabinfo
, NULL
);
895 HeapFree(GetProcessHeap(), 0, cmdline_copy
);
896 return SUCCEEDED(hr
) ? ADV_SUCCESS
: ADV_FAILURE
;
899 HRESULT
launch_exe(LPCWSTR cmd
, LPCWSTR dir
, HANDLE
*phEXE
)
902 PROCESS_INFORMATION pi
;
904 if (phEXE
) *phEXE
= NULL
;
906 ZeroMemory(&pi
, sizeof(pi
));
907 ZeroMemory(&si
, sizeof(si
));
910 if (!CreateProcessW(NULL
, (LPWSTR
)cmd
, NULL
, NULL
, FALSE
,
911 CREATE_DEFAULT_ERROR_MODE
| CREATE_NEW_PROCESS_GROUP
,
912 NULL
, dir
, &si
, &pi
))
914 return HRESULT_FROM_WIN32(GetLastError());
917 CloseHandle(pi
.hThread
);
921 *phEXE
= pi
.hProcess
;
922 return S_ASYNCHRONOUS
;
925 /* wait for the child process to finish */
926 WaitForSingleObject(pi
.hProcess
, INFINITE
);
927 CloseHandle(pi
.hProcess
);
932 /***********************************************************************
933 * RunSetupCommandA (ADVPACK.@)
935 * See RunSetupCommandW.
937 HRESULT WINAPI
RunSetupCommandA(HWND hWnd
, LPCSTR szCmdName
,
938 LPCSTR szInfSection
, LPCSTR szDir
,
939 LPCSTR lpszTitle
, HANDLE
*phEXE
,
940 DWORD dwFlags
, LPVOID pvReserved
)
942 UNICODE_STRING cmdname
, infsec
;
943 UNICODE_STRING dir
, title
;
946 TRACE("(%p, %s, %s, %s, %s, %p, %d, %p)\n",
947 hWnd
, debugstr_a(szCmdName
), debugstr_a(szInfSection
),
948 debugstr_a(szDir
), debugstr_a(lpszTitle
),
949 phEXE
, dwFlags
, pvReserved
);
951 if (!szCmdName
|| !szDir
)
954 RtlCreateUnicodeStringFromAsciiz(&cmdname
, szCmdName
);
955 RtlCreateUnicodeStringFromAsciiz(&infsec
, szInfSection
);
956 RtlCreateUnicodeStringFromAsciiz(&dir
, szDir
);
957 RtlCreateUnicodeStringFromAsciiz(&title
, lpszTitle
);
959 hr
= RunSetupCommandW(hWnd
, cmdname
.Buffer
, infsec
.Buffer
, dir
.Buffer
,
960 title
.Buffer
, phEXE
, dwFlags
, pvReserved
);
962 RtlFreeUnicodeString(&cmdname
);
963 RtlFreeUnicodeString(&infsec
);
964 RtlFreeUnicodeString(&dir
);
965 RtlFreeUnicodeString(&title
);
970 /***********************************************************************
971 * RunSetupCommandW (ADVPACK.@)
973 * Executes an install section in an INF file or a program.
976 * hWnd [I] Handle to parent window, NULL for quiet mode
977 * szCmdName [I] Inf or EXE filename to execute
978 * szInfSection [I] Inf section to install, NULL for DefaultInstall
979 * szDir [I] Path to extracted files
980 * szTitle [I] Title of all dialogs
981 * phEXE [O] Handle of EXE to wait for
982 * dwFlags [I] Flags; see include/advpub.h
983 * pvReserved [I] Reserved
987 * S_ASYNCHRONOUS OK, required to wait on phEXE
988 * ERROR_SUCCESS_REBOOT_REQUIRED Reboot required
989 * E_INVALIDARG Invalid argument given
990 * HRESULT_FROM_WIN32(ERROR_OLD_WIN_VERSION)
991 * Not supported on this Windows version
992 * E_UNEXPECTED Unexpected error
993 * HRESULT_FROM_WIN32(GetLastError()) Some other error
995 HRESULT WINAPI
RunSetupCommandW(HWND hWnd
, LPCWSTR szCmdName
,
996 LPCWSTR szInfSection
, LPCWSTR szDir
,
997 LPCWSTR lpszTitle
, HANDLE
*phEXE
,
998 DWORD dwFlags
, LPVOID pvReserved
)
1003 TRACE("(%p, %s, %s, %s, %s, %p, %d, %p)\n",
1004 hWnd
, debugstr_w(szCmdName
), debugstr_w(szInfSection
),
1005 debugstr_w(szDir
), debugstr_w(lpszTitle
),
1006 phEXE
, dwFlags
, pvReserved
);
1008 if (dwFlags
& RSC_FLAG_UPDHLPDLLS
)
1009 FIXME("Unhandled flag: RSC_FLAG_UPDHLPDLLS\n");
1011 if (!szCmdName
|| !szDir
)
1012 return E_INVALIDARG
;
1014 if (!(dwFlags
& RSC_FLAG_INF
))
1015 return launch_exe(szCmdName
, szDir
, phEXE
);
1017 ZeroMemory(&info
, sizeof(ADVInfo
));
1019 hr
= install_init(szCmdName
, szInfSection
, szDir
, dwFlags
, &info
);
1023 hr
= spapi_install(&info
);
1027 hr
= adv_install(&info
);
1030 install_release(&info
);