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
21 #include "advpack_private.h"
25 #define SPAPI_ERROR 0xE0000000L
26 #define SPAPI_PREFIX 0x800F0000L
27 #define SPAPI_MASK 0xFFFFL
28 #define HRESULT_FROM_SPAPI(x) ((HRESULT)((x & SPAPI_MASK) | SPAPI_PREFIX))
30 #define ADV_HRESULT(x) ((x & SPAPI_ERROR) ? HRESULT_FROM_SPAPI(x) : HRESULT_FROM_WIN32(x))
35 /* contains information about a specific install instance */
36 typedef struct _ADVInfo
47 typedef HRESULT (*iterate_fields_func
)(HINF hinf
, PCWSTR field
, const void *arg
);
49 /* Advanced INF commands */
50 static const WCHAR CheckAdminRights
[] = {
51 'C','h','e','c','k','A','d','m','i','n','R','i','g','h','t','s',0
53 static const WCHAR DelDirs
[] = {'D','e','l','D','i','r','s',0};
54 static const WCHAR PerUserInstall
[] = {'P','e','r','U','s','e','r','I','n','s','t','a','l','l',0};
55 static const WCHAR RegisterOCXs
[] = {'R','e','g','i','s','t','e','r','O','C','X','s',0};
56 static const WCHAR RunPreSetupCommands
[] = {
57 'R','u','n','P','r','e','S','e','t','u','p','C','o','m','m','a','n','d','s',0
59 static const WCHAR RunPostSetupCommands
[] = {
60 'R','u','n','P','o','s','t','S','e','t','u','p','C','o','m','m','a','n','d','s',0
63 /* Advanced INF callbacks */
64 static HRESULT
del_dirs_callback(HINF hinf
, PCWSTR field
, const void *arg
)
70 BOOL ok
= SetupFindFirstLineW(hinf
, field
, NULL
, &context
);
72 for (; ok
; ok
= SetupFindNextLine(&context
, &context
))
74 WCHAR directory
[MAX_INF_STRING_LENGTH
];
76 if (!SetupGetLineTextW(&context
, NULL
, NULL
, NULL
, directory
,
77 MAX_INF_STRING_LENGTH
, &size
))
80 if (DelNodeW(directory
, ADN_DEL_IF_EMPTY
) != S_OK
)
87 static HRESULT
per_user_install_callback(HINF hinf
, PCWSTR field
, const void *arg
)
89 PERUSERSECTIONW per_user
;
93 static const WCHAR disp_name
[] = {'D','i','s','p','l','a','y','N','a','m','e',0};
94 static const WCHAR version
[] = {'V','e','r','s','i','o','n',0};
95 static const WCHAR is_installed
[] = {'I','s','I','n','s','t','a','l','l','e','d',0};
96 static const WCHAR comp_id
[] = {'C','o','m','p','o','n','e','n','t','I','D',0};
97 static const WCHAR guid
[] = {'G','U','I','D',0};
98 static const WCHAR locale
[] = {'L','o','c','a','l','e',0};
99 static const WCHAR stub_path
[] = {'S','t','u','b','P','a','t','h',0};
101 per_user
.bRollback
= FALSE
;
102 per_user
.dwIsInstalled
= 0;
104 SetupGetLineTextW(NULL
, hinf
, field
, disp_name
, per_user
.szDispName
,
105 sizeof(per_user
.szDispName
) / sizeof(WCHAR
), &size
);
107 SetupGetLineTextW(NULL
, hinf
, field
, version
, per_user
.szVersion
,
108 sizeof(per_user
.szVersion
) / sizeof(WCHAR
), &size
);
110 if (SetupFindFirstLineW(hinf
, field
, is_installed
, &context
))
112 SetupGetIntField(&context
, 1, (PINT
)&per_user
.dwIsInstalled
);
115 SetupGetLineTextW(NULL
, hinf
, field
, comp_id
, per_user
.szCompID
,
116 sizeof(per_user
.szCompID
) / sizeof(WCHAR
), &size
);
118 SetupGetLineTextW(NULL
, hinf
, field
, guid
, per_user
.szGUID
,
119 sizeof(per_user
.szGUID
) / sizeof(WCHAR
), &size
);
121 SetupGetLineTextW(NULL
, hinf
, field
, locale
, per_user
.szLocale
,
122 sizeof(per_user
.szLocale
) / sizeof(WCHAR
), &size
);
124 SetupGetLineTextW(NULL
, hinf
, field
, stub_path
, per_user
.szStub
,
125 sizeof(per_user
.szStub
) / sizeof(WCHAR
), &size
);
127 return SetPerUserSecValuesW(&per_user
);
130 static HRESULT
register_ocxs_callback(HINF hinf
, PCWSTR field
, const void *arg
)
136 BOOL ok
= SetupFindFirstLineW(hinf
, field
, NULL
, &context
);
138 for (; ok
; ok
= SetupFindNextLine(&context
, &context
))
140 WCHAR buffer
[MAX_INF_STRING_LENGTH
];
142 /* get OCX filename */
143 if (!SetupGetStringFieldW(&context
, 1, buffer
,
144 sizeof(buffer
) / sizeof(WCHAR
), NULL
))
147 hm
= LoadLibraryExW(buffer
, NULL
, LOAD_WITH_ALTERED_SEARCH_PATH
);
150 if (do_ocx_reg(hm
, TRUE
, NULL
, NULL
) != S_OK
)
160 /* FIXME: display a message box */
168 static HRESULT
run_setup_commands_callback(HINF hinf
, PCWSTR field
, const void *arg
)
170 const ADVInfo
*info
= (const ADVInfo
*)arg
;
175 BOOL ok
= SetupFindFirstLineW(hinf
, field
, NULL
, &context
);
177 for (; ok
; ok
= SetupFindNextLine(&context
, &context
))
179 WCHAR buffer
[MAX_INF_STRING_LENGTH
];
181 if (!SetupGetLineTextW(&context
, NULL
, NULL
, NULL
, buffer
,
182 MAX_INF_STRING_LENGTH
, &size
))
185 if (launch_exe(buffer
, info
->working_dir
, NULL
) != S_OK
)
192 /* sequentially returns pointers to parameters in a parameter list
193 * returns NULL if the parameter is empty, e.g. one,,three */
194 LPWSTR
get_parameter(LPWSTR
*params
, WCHAR separator
, BOOL quoted
)
196 LPWSTR token
= *params
;
201 if (quoted
&& *token
== '"')
203 WCHAR
*end
= strchrW(token
+ 1, '"');
212 *params
= strchrW(*params
, separator
);
222 static BOOL
is_full_path(LPCWSTR path
)
224 const int MIN_PATH_LEN
= 3;
226 if (!path
|| lstrlenW(path
) < MIN_PATH_LEN
)
229 if ((path
[1] == ':' && path
[2] == '\\') || (path
[0] == '\\' && path
[1] == '\\'))
235 /* retrieves the contents of a field, dynamically growing the buffer if necessary */
236 static WCHAR
*get_field_string(INFCONTEXT
*context
, DWORD index
, WCHAR
*buffer
,
237 const WCHAR
*static_buffer
, DWORD
*size
)
241 if (SetupGetStringFieldW(context
, index
, buffer
, *size
, &required
)) return buffer
;
243 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
245 /* now grow the buffer */
246 if (buffer
!= static_buffer
) HeapFree(GetProcessHeap(), 0, buffer
);
247 if (!(buffer
= HeapAlloc(GetProcessHeap(), 0, required
*sizeof(WCHAR
)))) return NULL
;
249 if (SetupGetStringFieldW(context
, index
, buffer
, *size
, &required
)) return buffer
;
252 if (buffer
!= static_buffer
) HeapFree(GetProcessHeap(), 0, buffer
);
256 /* iterates over all fields of a certain key of a certain section */
257 static HRESULT
iterate_section_fields(HINF hinf
, PCWSTR section
, PCWSTR key
,
258 iterate_fields_func callback
, void *arg
)
260 WCHAR static_buffer
[200];
261 WCHAR
*buffer
= static_buffer
;
262 DWORD size
= sizeof(static_buffer
) / sizeof(WCHAR
);
266 BOOL ok
= SetupFindFirstLineW(hinf
, section
, key
, &context
);
269 UINT i
, count
= SetupGetFieldCount(&context
);
271 for (i
= 1; i
<= count
; i
++)
273 if (!(buffer
= get_field_string(&context
, i
, buffer
, static_buffer
, &size
)))
276 if ((hr
= callback(hinf
, buffer
, arg
)) != S_OK
)
280 ok
= SetupFindNextMatchLineW(&context
, key
, &context
);
286 if (buffer
!= static_buffer
) HeapFree(GetProcessHeap(), 0, buffer
);
290 static HRESULT
check_admin_rights(const ADVInfo
*info
)
296 if (!SetupFindFirstLineW(info
->hinf
, info
->install_sec
,
297 CheckAdminRights
, &context
))
300 if (!SetupGetIntField(&context
, 1, &check
))
304 hr
= IsNTAdmin(0, NULL
) ? S_OK
: E_FAIL
;
309 /* performs a setupapi-level install of the INF file */
310 static HRESULT
spapi_install(const ADVInfo
*info
)
316 context
= SetupInitDefaultQueueCallbackEx(NULL
, INVALID_HANDLE_VALUE
, 0, 0, NULL
);
318 return ADV_HRESULT(GetLastError());
320 ret
= SetupInstallFromInfSectionW(NULL
, info
->hinf
, info
->install_sec
,
321 SPINST_FILES
, NULL
, info
->working_dir
,
322 SP_COPY_NEWER
, SetupDefaultQueueCallbackW
,
323 context
, NULL
, NULL
);
326 res
= ADV_HRESULT(GetLastError());
327 SetupTermDefaultQueueCallback(context
);
332 SetupTermDefaultQueueCallback(context
);
334 ret
= SetupInstallFromInfSectionW(NULL
, info
->hinf
, info
->install_sec
,
335 SPINST_INIFILES
| SPINST_REGISTRY
| SPINST_REGSVR
,
336 HKEY_LOCAL_MACHINE
, NULL
, 0,
337 NULL
, NULL
, NULL
, NULL
);
339 return ADV_HRESULT(GetLastError());
344 /* processes the Advanced INF commands */
345 static HRESULT
adv_install(ADVInfo
*info
)
349 hr
= check_admin_rights(info
);
353 hr
= iterate_section_fields(info
->hinf
, info
->install_sec
, RunPreSetupCommands
,
354 run_setup_commands_callback
, info
);
359 hr
= iterate_section_fields(info
->hinf
, info
->install_sec
,
360 RegisterOCXs
, register_ocxs_callback
, NULL
);
365 hr
= iterate_section_fields(info
->hinf
, info
->install_sec
,
366 PerUserInstall
, per_user_install_callback
, info
);
370 hr
= iterate_section_fields(info
->hinf
, info
->install_sec
, RunPostSetupCommands
,
371 run_setup_commands_callback
, info
);
375 hr
= iterate_section_fields(info
->hinf
, info
->install_sec
,
376 DelDirs
, del_dirs_callback
, info
);
383 /* determines the proper working directory for the INF file */
384 static HRESULT
get_working_dir(ADVInfo
*info
, LPCWSTR inf_filename
, LPCWSTR working_dir
)
386 WCHAR path
[MAX_PATH
];
390 static const WCHAR backslash
[] = {'\\',0};
391 static const WCHAR inf_dir
[] = {'\\','I','N','F',0};
393 if ((ptr
= strrchrW(inf_filename
, '\\')))
395 len
= ptr
- inf_filename
+ 1;
398 else if (working_dir
&& *working_dir
)
400 len
= lstrlenW(working_dir
) + 1;
405 GetCurrentDirectoryW(MAX_PATH
, path
);
406 lstrcatW(path
, backslash
);
407 lstrcatW(path
, inf_filename
);
409 /* check if the INF file is in the current directory */
410 if (GetFileAttributesW(path
) != INVALID_FILE_ATTRIBUTES
)
412 GetCurrentDirectoryW(MAX_PATH
, path
);
416 /* default to the windows\inf directory if all else fails */
417 GetWindowsDirectoryW(path
, MAX_PATH
);
418 lstrcatW(path
, inf_dir
);
421 len
= lstrlenW(path
) + 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
);
434 /* loads the INF file and performs checks on it */
435 static HRESULT
install_init(LPCWSTR inf_filename
, LPCWSTR install_sec
,
436 LPCWSTR working_dir
, DWORD flags
, ADVInfo
*info
)
442 static const WCHAR backslash
[] = {'\\',0};
443 static const WCHAR default_install
[] = {
444 'D','e','f','a','u','l','t','I','n','s','t','a','l','l',0
447 if (!(ptr
= strrchrW(inf_filename
, '\\')))
452 info
->inf_filename
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
453 if (!info
->inf_filename
)
454 return E_OUTOFMEMORY
;
456 lstrcpyW(info
->inf_filename
, ptr
);
458 /* FIXME: determine the proper platform to install (NTx86, etc) */
459 if (!install_sec
|| !*install_sec
)
461 len
= sizeof(default_install
) - 1;
462 ptr
= default_install
;
466 len
= lstrlenW(install_sec
);
470 info
->install_sec
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
471 if (!info
->install_sec
)
472 return E_OUTOFMEMORY
;
474 lstrcpyW(info
->install_sec
, ptr
);
476 hr
= get_working_dir(info
, inf_filename
, working_dir
);
480 len
= lstrlenW(info
->working_dir
) + lstrlenW(info
->inf_filename
) + 2;
481 info
->inf_path
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
483 return E_OUTOFMEMORY
;
485 lstrcpyW(info
->inf_path
, info
->working_dir
);
486 lstrcatW(info
->inf_path
, backslash
);
487 lstrcatW(info
->inf_path
, info
->inf_filename
);
489 /* RunSetupCommand opens unmodifed filename parameter */
490 if (flags
& RSC_FLAG_INF
)
493 path
= info
->inf_path
;
495 info
->hinf
= SetupOpenInfFileW(path
, NULL
, INF_STYLE_WIN4
, NULL
);
496 if (info
->hinf
== INVALID_HANDLE_VALUE
)
497 return ADV_HRESULT(GetLastError());
499 set_ldids(info
->hinf
, info
->install_sec
, info
->working_dir
);
501 /* FIXME: check that the INF is advanced */
504 info
->need_reboot
= FALSE
;
509 /* release the install instance information */
510 static void install_release(const ADVInfo
*info
)
512 SetupCloseInfFile(info
->hinf
);
514 HeapFree(GetProcessHeap(), 0, info
->inf_path
);
515 HeapFree(GetProcessHeap(), 0, info
->inf_filename
);
516 HeapFree(GetProcessHeap(), 0, info
->install_sec
);
517 HeapFree(GetProcessHeap(), 0, info
->working_dir
);
520 /* this structure very closely resembles parameters of RunSetupCommand() */
528 } SETUPCOMMAND_PARAMS
;
536 LPCWSTR section_name
;
537 } SETUPCOMMAND_PARAMSW
;
539 /* internal: see DoInfInstall */
540 static HRESULT
DoInfInstallW(const SETUPCOMMAND_PARAMSW
*setup
)
545 TRACE("(%p)\n", setup
);
547 ZeroMemory(&info
, sizeof(ADVInfo
));
549 hr
= install_init(setup
->inf_name
, setup
->section_name
, setup
->dir
, 0, &info
);
553 hr
= spapi_install(&info
);
557 hr
= adv_install(&info
);
560 install_release(&info
);
565 /***********************************************************************
566 * DoInfInstall (ADVPACK.@)
568 * Install an INF section.
571 * setup [I] Structure containing install information.
575 * HRESULT_FROM_WIN32(GetLastError()) Some other error
577 HRESULT WINAPI
DoInfInstall(const SETUPCOMMAND_PARAMS
*setup
)
579 UNICODE_STRING title
, inf
, section
, dir
;
580 SETUPCOMMAND_PARAMSW params
;
586 RtlCreateUnicodeStringFromAsciiz(&title
, setup
->title
);
587 RtlCreateUnicodeStringFromAsciiz(&inf
, setup
->inf_name
);
588 RtlCreateUnicodeStringFromAsciiz(§ion
, setup
->section_name
);
589 RtlCreateUnicodeStringFromAsciiz(&dir
, setup
->dir
);
591 params
.title
= title
.Buffer
;
592 params
.inf_name
= inf
.Buffer
;
593 params
.section_name
= section
.Buffer
;
594 params
.dir
= dir
.Buffer
;
595 params
.hwnd
= setup
->hwnd
;
597 hr
= DoInfInstallW(¶ms
);
599 RtlFreeUnicodeString(&title
);
600 RtlFreeUnicodeString(&inf
);
601 RtlFreeUnicodeString(§ion
);
602 RtlFreeUnicodeString(&dir
);
607 /***********************************************************************
608 * ExecuteCabA (ADVPACK.@)
612 HRESULT WINAPI
ExecuteCabA(HWND hwnd
, CABINFOA
* pCab
, LPVOID pReserved
)
614 UNICODE_STRING cab
, inf
, section
;
618 TRACE("(%p, %p, %p)\n", hwnd
, pCab
, pReserved
);
625 RtlCreateUnicodeStringFromAsciiz(&cab
, pCab
->pszCab
);
626 cabinfo
.pszCab
= cab
.Buffer
;
629 cabinfo
.pszCab
= NULL
;
631 RtlCreateUnicodeStringFromAsciiz(&inf
, pCab
->pszInf
);
632 RtlCreateUnicodeStringFromAsciiz(§ion
, pCab
->pszSection
);
634 MultiByteToWideChar(CP_ACP
, 0, pCab
->szSrcPath
, -1, cabinfo
.szSrcPath
,
635 sizeof(cabinfo
.szSrcPath
) / sizeof(WCHAR
));
637 cabinfo
.pszInf
= inf
.Buffer
;
638 cabinfo
.pszSection
= section
.Buffer
;
639 cabinfo
.dwFlags
= pCab
->dwFlags
;
641 hr
= ExecuteCabW(hwnd
, &cabinfo
, pReserved
);
644 RtlFreeUnicodeString(&cab
);
646 RtlFreeUnicodeString(&inf
);
647 RtlFreeUnicodeString(§ion
);
652 /***********************************************************************
653 * ExecuteCabW (ADVPACK.@)
655 * Installs the INF file extracted from a specified cabinet file.
658 * hwnd [I] Handle to the window used for the display.
659 * pCab [I] Information about the cabinet file.
660 * pReserved [I] Reserved. Must be NULL.
666 HRESULT WINAPI
ExecuteCabW(HWND hwnd
, CABINFOW
* pCab
, LPVOID pReserved
)
671 TRACE("(%p, %p, %p)\n", hwnd
, pCab
, pReserved
);
673 ZeroMemory(&info
, sizeof(ADVInfo
));
675 if (pCab
->pszCab
&& *pCab
->pszCab
)
676 FIXME("Cab archive not extracted!\n");
678 hr
= install_init(pCab
->pszInf
, pCab
->pszSection
, pCab
->szSrcPath
, pCab
->dwFlags
, &info
);
682 hr
= spapi_install(&info
);
686 hr
= adv_install(&info
);
689 install_release(&info
);
694 /***********************************************************************
695 * LaunchINFSectionA (ADVPACK.@)
697 * See LaunchINFSectionW.
699 INT WINAPI
LaunchINFSectionA(HWND hWnd
, HINSTANCE hInst
, LPSTR cmdline
, INT show
)
704 TRACE("(%p, %p, %s, %i)\n", hWnd
, hInst
, debugstr_a(cmdline
), show
);
709 RtlCreateUnicodeStringFromAsciiz(&cmd
, cmdline
);
711 hr
= LaunchINFSectionW(hWnd
, hInst
, cmd
.Buffer
, show
);
713 RtlFreeUnicodeString(&cmd
);
718 /***********************************************************************
719 * LaunchINFSectionW (ADVPACK.@)
721 * Installs an INF section without BACKUP/ROLLBACK capabilities.
724 * hWnd [I] Handle to parent window, NULL for desktop.
725 * hInst [I] Instance of the process.
726 * cmdline [I] Contains parameters in the order INF,section,flags,reboot.
727 * show [I] How the window should be shown.
730 * Success: ADV_SUCCESS.
731 * Failure: ADV_FAILURE.
734 * INF - Filename of the INF to launch.
735 * section - INF section to install.
736 * flags - see advpub.h.
737 * reboot - smart reboot behavior
739 * 'I' Reboot if needed (default).
742 INT WINAPI
LaunchINFSectionW(HWND hWnd
, HINSTANCE hInst
, LPWSTR cmdline
, INT show
)
745 LPWSTR cmdline_copy
, cmdline_ptr
;
746 LPWSTR inf_filename
, install_sec
;
751 TRACE("(%p, %p, %s, %d)\n", hWnd
, hInst
, debugstr_w(cmdline
), show
);
756 cmdline_copy
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(cmdline
) + 1) * sizeof(WCHAR
));
757 cmdline_ptr
= cmdline_copy
;
758 lstrcpyW(cmdline_copy
, cmdline
);
760 inf_filename
= get_parameter(&cmdline_ptr
, ',', TRUE
);
761 install_sec
= get_parameter(&cmdline_ptr
, ',', TRUE
);
763 str_flags
= get_parameter(&cmdline_ptr
, ',', TRUE
);
766 DWORD inf_flags
= atolW(str_flags
);
767 if (inf_flags
& LIS_QUIET
) flags
|= RSC_FLAG_QUIET
;
768 if (inf_flags
& LIS_NOGRPCONV
) flags
|= RSC_FLAG_NGCONV
;
771 ZeroMemory(&info
, sizeof(ADVInfo
));
773 hr
= install_init(inf_filename
, install_sec
, NULL
, flags
, &info
);
777 hr
= spapi_install(&info
);
781 hr
= adv_install(&info
);
784 install_release(&info
);
785 HeapFree(GetProcessHeap(), 0, cmdline_copy
);
787 return SUCCEEDED(hr
) ? ADV_SUCCESS
: ADV_FAILURE
;
790 /***********************************************************************
791 * LaunchINFSectionExA (ADVPACK.@)
793 * See LaunchINFSectionExW.
795 HRESULT WINAPI
LaunchINFSectionExA(HWND hWnd
, HINSTANCE hInst
, LPSTR cmdline
, INT show
)
800 TRACE("(%p, %p, %s, %i)\n", hWnd
, hInst
, debugstr_a(cmdline
), show
);
805 RtlCreateUnicodeStringFromAsciiz(&cmd
, cmdline
);
807 hr
= LaunchINFSectionExW(hWnd
, hInst
, cmd
.Buffer
, show
);
809 RtlFreeUnicodeString(&cmd
);
814 /***********************************************************************
815 * LaunchINFSectionExW (ADVPACK.@)
817 * Installs an INF section with BACKUP/ROLLBACK capabilities.
820 * hWnd [I] Handle to parent window, NULL for desktop.
821 * hInst [I] Instance of the process.
822 * cmdline [I] Contains parameters in the order INF,section,CAB,flags,reboot.
823 * show [I] How the window should be shown.
826 * Success: ADV_SUCCESS.
827 * Failure: ADV_FAILURE.
830 * INF - Filename of the INF to launch.
831 * section - INF section to install.
832 * flags - see advpub.h.
833 * reboot - smart reboot behavior
835 * 'I' Reboot if needed (default).
839 * Doesn't handle the reboot flag.
841 HRESULT WINAPI
LaunchINFSectionExW(HWND hWnd
, HINSTANCE hInst
, LPWSTR cmdline
, INT show
)
843 LPWSTR cmdline_copy
, cmdline_ptr
;
848 TRACE("(%p, %p, %s, %d)\n", hWnd
, hInst
, debugstr_w(cmdline
), show
);
853 cmdline_copy
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(cmdline
) + 1) * sizeof(WCHAR
));
854 cmdline_ptr
= cmdline_copy
;
855 lstrcpyW(cmdline_copy
, cmdline
);
857 cabinfo
.pszInf
= get_parameter(&cmdline_ptr
, ',', TRUE
);
858 cabinfo
.pszSection
= get_parameter(&cmdline_ptr
, ',', TRUE
);
859 cabinfo
.pszCab
= get_parameter(&cmdline_ptr
, ',', TRUE
);
860 *cabinfo
.szSrcPath
= '\0';
862 flags
= get_parameter(&cmdline_ptr
, ',', TRUE
);
864 cabinfo
.dwFlags
= atolW(flags
);
866 if (!is_full_path(cabinfo
.pszCab
) && !is_full_path(cabinfo
.pszInf
))
868 HeapFree(GetProcessHeap(), 0, cmdline_copy
);
872 /* get the source path from the cab filename */
873 if (cabinfo
.pszCab
&& *cabinfo
.pszCab
)
875 if (!is_full_path(cabinfo
.pszCab
))
876 lstrcpyW(cabinfo
.szSrcPath
, cabinfo
.pszInf
);
878 lstrcpyW(cabinfo
.szSrcPath
, cabinfo
.pszCab
);
880 ptr
= strrchrW(cabinfo
.szSrcPath
, '\\');
884 hr
= ExecuteCabW(hWnd
, &cabinfo
, NULL
);
885 HeapFree(GetProcessHeap(), 0, cmdline_copy
);
886 return SUCCEEDED(hr
) ? ADV_SUCCESS
: ADV_FAILURE
;
889 HRESULT
launch_exe(LPCWSTR cmd
, LPCWSTR dir
, HANDLE
*phEXE
)
892 PROCESS_INFORMATION pi
;
894 if (phEXE
) *phEXE
= NULL
;
896 ZeroMemory(&pi
, sizeof(pi
));
897 ZeroMemory(&si
, sizeof(si
));
900 if (!CreateProcessW(NULL
, (LPWSTR
)cmd
, NULL
, NULL
, FALSE
,
901 CREATE_DEFAULT_ERROR_MODE
| CREATE_NEW_PROCESS_GROUP
,
902 NULL
, dir
, &si
, &pi
))
904 return HRESULT_FROM_WIN32(GetLastError());
907 CloseHandle(pi
.hThread
);
911 *phEXE
= pi
.hProcess
;
912 return S_ASYNCHRONOUS
;
915 /* wait for the child process to finish */
916 WaitForSingleObject(pi
.hProcess
, INFINITE
);
917 CloseHandle(pi
.hProcess
);
922 /***********************************************************************
923 * RunSetupCommandA (ADVPACK.@)
925 * See RunSetupCommandW.
927 HRESULT WINAPI
RunSetupCommandA(HWND hWnd
, LPCSTR szCmdName
,
928 LPCSTR szInfSection
, LPCSTR szDir
,
929 LPCSTR lpszTitle
, HANDLE
*phEXE
,
930 DWORD dwFlags
, LPVOID pvReserved
)
932 UNICODE_STRING cmdname
, infsec
;
933 UNICODE_STRING dir
, title
;
936 TRACE("(%p, %s, %s, %s, %s, %p, %d, %p)\n",
937 hWnd
, debugstr_a(szCmdName
), debugstr_a(szInfSection
),
938 debugstr_a(szDir
), debugstr_a(lpszTitle
),
939 phEXE
, dwFlags
, pvReserved
);
941 if (!szCmdName
|| !szDir
)
944 RtlCreateUnicodeStringFromAsciiz(&cmdname
, szCmdName
);
945 RtlCreateUnicodeStringFromAsciiz(&infsec
, szInfSection
);
946 RtlCreateUnicodeStringFromAsciiz(&dir
, szDir
);
947 RtlCreateUnicodeStringFromAsciiz(&title
, lpszTitle
);
949 hr
= RunSetupCommandW(hWnd
, cmdname
.Buffer
, infsec
.Buffer
, dir
.Buffer
,
950 title
.Buffer
, phEXE
, dwFlags
, pvReserved
);
952 RtlFreeUnicodeString(&cmdname
);
953 RtlFreeUnicodeString(&infsec
);
954 RtlFreeUnicodeString(&dir
);
955 RtlFreeUnicodeString(&title
);
960 /***********************************************************************
961 * RunSetupCommandW (ADVPACK.@)
963 * Executes an install section in an INF file or a program.
966 * hWnd [I] Handle to parent window, NULL for quiet mode
967 * szCmdName [I] Inf or EXE filename to execute
968 * szInfSection [I] Inf section to install, NULL for DefaultInstall
969 * szDir [I] Path to extracted files
970 * szTitle [I] Title of all dialogs
971 * phEXE [O] Handle of EXE to wait for
972 * dwFlags [I] Flags; see include/advpub.h
973 * pvReserved [I] Reserved
977 * S_ASYNCHRONOUS OK, required to wait on phEXE
978 * ERROR_SUCCESS_REBOOT_REQUIRED Reboot required
979 * E_INVALIDARG Invalid argument given
980 * HRESULT_FROM_WIN32(ERROR_OLD_WIN_VERSION)
981 * Not supported on this Windows version
982 * E_UNEXPECTED Unexpected error
983 * HRESULT_FROM_WIN32(GetLastError()) Some other error
985 HRESULT WINAPI
RunSetupCommandW(HWND hWnd
, LPCWSTR szCmdName
,
986 LPCWSTR szInfSection
, LPCWSTR szDir
,
987 LPCWSTR lpszTitle
, HANDLE
*phEXE
,
988 DWORD dwFlags
, LPVOID pvReserved
)
993 TRACE("(%p, %s, %s, %s, %s, %p, %d, %p)\n",
994 hWnd
, debugstr_w(szCmdName
), debugstr_w(szInfSection
),
995 debugstr_w(szDir
), debugstr_w(lpszTitle
),
996 phEXE
, dwFlags
, pvReserved
);
998 if (dwFlags
& RSC_FLAG_UPDHLPDLLS
)
999 FIXME("Unhandled flag: RSC_FLAG_UPDHLPDLLS\n");
1001 if (!szCmdName
|| !szDir
)
1002 return E_INVALIDARG
;
1004 if (!(dwFlags
& RSC_FLAG_INF
))
1005 return launch_exe(szCmdName
, szDir
, phEXE
);
1007 ZeroMemory(&info
, sizeof(ADVInfo
));
1009 hr
= install_init(szCmdName
, szInfSection
, szDir
, dwFlags
, &info
);
1013 hr
= spapi_install(&info
);
1017 hr
= adv_install(&info
);
1020 install_release(&info
);