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
, ARRAY_SIZE(per_user
.szDispName
), &size
);
120 SetupGetLineTextW(NULL
, hinf
, field
, version
, per_user
.szVersion
, ARRAY_SIZE(per_user
.szVersion
), &size
);
122 if (SetupFindFirstLineW(hinf
, field
, is_installed
, &context
))
124 SetupGetIntField(&context
, 1, (PINT
)&per_user
.dwIsInstalled
);
127 SetupGetLineTextW(NULL
, hinf
, field
, comp_id
, per_user
.szCompID
, ARRAY_SIZE(per_user
.szCompID
), &size
);
129 SetupGetLineTextW(NULL
, hinf
, field
, guid
, per_user
.szGUID
, ARRAY_SIZE(per_user
.szGUID
), &size
);
131 SetupGetLineTextW(NULL
, hinf
, field
, locale
, per_user
.szLocale
, ARRAY_SIZE(per_user
.szLocale
), &size
);
133 SetupGetLineTextW(NULL
, hinf
, field
, stub_path
, per_user
.szStub
, ARRAY_SIZE(per_user
.szStub
), &size
);
135 return SetPerUserSecValuesW(&per_user
);
138 static HRESULT
register_ocxs_callback(HINF hinf
, PCWSTR field
, const void *arg
)
144 BOOL ok
= SetupFindFirstLineW(hinf
, field
, NULL
, &context
);
146 for (; ok
; ok
= SetupFindNextLine(&context
, &context
))
148 WCHAR buffer
[MAX_INF_STRING_LENGTH
];
150 /* get OCX filename */
151 if (!SetupGetStringFieldW(&context
, 1, buffer
, ARRAY_SIZE(buffer
), NULL
))
154 hm
= LoadLibraryExW(buffer
, NULL
, LOAD_WITH_ALTERED_SEARCH_PATH
);
157 if (do_ocx_reg(hm
, TRUE
, NULL
, NULL
) != S_OK
)
167 /* FIXME: display a message box */
175 static HRESULT
run_setup_commands_callback(HINF hinf
, PCWSTR field
, const void *arg
)
177 const ADVInfo
*info
= (const ADVInfo
*)arg
;
182 BOOL ok
= SetupFindFirstLineW(hinf
, field
, NULL
, &context
);
184 for (; ok
; ok
= SetupFindNextLine(&context
, &context
))
186 WCHAR buffer
[MAX_INF_STRING_LENGTH
];
188 if (!SetupGetLineTextW(&context
, NULL
, NULL
, NULL
, buffer
,
189 MAX_INF_STRING_LENGTH
, &size
))
192 if (launch_exe(buffer
, info
->working_dir
, NULL
) != S_OK
)
199 /* sequentially returns pointers to parameters in a parameter list
200 * returns NULL if the parameter is empty, e.g. one,,three */
201 LPWSTR
get_parameter(LPWSTR
*params
, WCHAR separator
, BOOL quoted
)
203 LPWSTR token
= *params
;
208 if (quoted
&& *token
== '"')
210 WCHAR
*end
= strchrW(token
+ 1, '"');
219 *params
= strchrW(*params
, separator
);
229 static BOOL
is_full_path(LPCWSTR path
)
231 const int MIN_PATH_LEN
= 3;
233 if (!path
|| lstrlenW(path
) < MIN_PATH_LEN
)
236 if ((path
[1] == ':' && path
[2] == '\\') || (path
[0] == '\\' && path
[1] == '\\'))
242 /* retrieves the contents of a field, dynamically growing the buffer if necessary */
243 static WCHAR
*get_field_string(INFCONTEXT
*context
, DWORD index
, WCHAR
*buffer
,
244 const WCHAR
*static_buffer
, DWORD
*size
)
248 if (SetupGetStringFieldW(context
, index
, buffer
, *size
, &required
)) return buffer
;
250 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
252 /* now grow the buffer */
253 if (buffer
!= static_buffer
) HeapFree(GetProcessHeap(), 0, buffer
);
254 if (!(buffer
= HeapAlloc(GetProcessHeap(), 0, required
*sizeof(WCHAR
)))) return NULL
;
256 if (SetupGetStringFieldW(context
, index
, buffer
, *size
, &required
)) return buffer
;
259 if (buffer
!= static_buffer
) HeapFree(GetProcessHeap(), 0, buffer
);
263 /* iterates over all fields of a certain key of a certain section */
264 static HRESULT
iterate_section_fields(HINF hinf
, PCWSTR section
, PCWSTR key
,
265 iterate_fields_func callback
, void *arg
)
267 WCHAR static_buffer
[200];
268 WCHAR
*buffer
= static_buffer
;
269 DWORD size
= ARRAY_SIZE(static_buffer
);
273 BOOL ok
= SetupFindFirstLineW(hinf
, section
, key
, &context
);
276 UINT i
, count
= SetupGetFieldCount(&context
);
278 for (i
= 1; i
<= count
; i
++)
280 if (!(buffer
= get_field_string(&context
, i
, buffer
, static_buffer
, &size
)))
283 if ((hr
= callback(hinf
, buffer
, arg
)) != S_OK
)
287 ok
= SetupFindNextMatchLineW(&context
, key
, &context
);
293 if (buffer
!= static_buffer
) HeapFree(GetProcessHeap(), 0, buffer
);
297 static HRESULT
check_admin_rights(const ADVInfo
*info
)
303 if (!SetupFindFirstLineW(info
->hinf
, info
->install_sec
,
304 CheckAdminRights
, &context
))
307 if (!SetupGetIntField(&context
, 1, &check
))
311 hr
= IsNTAdmin(0, NULL
) ? S_OK
: E_FAIL
;
316 /* performs a setupapi-level install of the INF file */
317 static HRESULT
spapi_install(const ADVInfo
*info
)
323 context
= SetupInitDefaultQueueCallbackEx(NULL
, INVALID_HANDLE_VALUE
, 0, 0, NULL
);
325 return ADV_HRESULT(GetLastError());
327 ret
= SetupInstallFromInfSectionW(NULL
, info
->hinf
, info
->install_sec
,
328 SPINST_FILES
, NULL
, info
->working_dir
,
329 SP_COPY_NEWER
, SetupDefaultQueueCallbackW
,
330 context
, NULL
, NULL
);
333 res
= ADV_HRESULT(GetLastError());
334 SetupTermDefaultQueueCallback(context
);
339 SetupTermDefaultQueueCallback(context
);
341 ret
= SetupInstallFromInfSectionW(NULL
, info
->hinf
, info
->install_sec
,
342 SPINST_INIFILES
| SPINST_REGISTRY
| SPINST_REGSVR
,
343 HKEY_LOCAL_MACHINE
, NULL
, 0,
344 NULL
, NULL
, NULL
, NULL
);
346 return ADV_HRESULT(GetLastError());
351 /* processes the Advanced INF commands */
352 static HRESULT
adv_install(ADVInfo
*info
)
356 hr
= check_admin_rights(info
);
360 hr
= iterate_section_fields(info
->hinf
, info
->install_sec
, RunPreSetupCommands
,
361 run_setup_commands_callback
, info
);
366 hr
= iterate_section_fields(info
->hinf
, info
->install_sec
,
367 RegisterOCXs
, register_ocxs_callback
, NULL
);
372 hr
= iterate_section_fields(info
->hinf
, info
->install_sec
,
373 PerUserInstall
, per_user_install_callback
, info
);
377 hr
= iterate_section_fields(info
->hinf
, info
->install_sec
, RunPostSetupCommands
,
378 run_setup_commands_callback
, info
);
382 hr
= iterate_section_fields(info
->hinf
, info
->install_sec
,
383 DelDirs
, del_dirs_callback
, info
);
390 /* determines the proper working directory for the INF file */
391 static HRESULT
get_working_dir(ADVInfo
*info
, LPCWSTR inf_filename
, LPCWSTR working_dir
)
393 WCHAR path
[MAX_PATH
];
397 static const WCHAR backslash
[] = {'\\',0};
398 static const WCHAR inf_dir
[] = {'\\','I','N','F',0};
400 if ((ptr
= strrchrW(inf_filename
, '\\')))
402 len
= ptr
- inf_filename
+ 1;
405 else if (working_dir
&& *working_dir
)
407 len
= lstrlenW(working_dir
) + 1;
412 GetCurrentDirectoryW(MAX_PATH
, path
);
413 lstrcatW(path
, backslash
);
414 lstrcatW(path
, inf_filename
);
416 /* check if the INF file is in the current directory */
417 if (GetFileAttributesW(path
) != INVALID_FILE_ATTRIBUTES
)
419 GetCurrentDirectoryW(MAX_PATH
, path
);
423 /* default to the windows\inf directory if all else fails */
424 GetWindowsDirectoryW(path
, MAX_PATH
);
425 lstrcatW(path
, inf_dir
);
428 len
= lstrlenW(path
) + 1;
432 info
->working_dir
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
433 if (!info
->working_dir
)
434 return E_OUTOFMEMORY
;
436 lstrcpynW(info
->working_dir
, ptr
, len
);
441 /* loads the INF file and performs checks on it */
442 static HRESULT
install_init(LPCWSTR inf_filename
, LPCWSTR install_sec
,
443 LPCWSTR working_dir
, DWORD flags
, ADVInfo
*info
)
449 static const WCHAR backslash
[] = {'\\',0};
450 static const WCHAR default_install
[] = {
451 'D','e','f','a','u','l','t','I','n','s','t','a','l','l',0
454 if (!(ptr
= strrchrW(inf_filename
, '\\')))
459 info
->inf_filename
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
460 if (!info
->inf_filename
)
461 return E_OUTOFMEMORY
;
463 lstrcpyW(info
->inf_filename
, ptr
);
465 /* FIXME: determine the proper platform to install (NTx86, etc) */
466 if (!install_sec
|| !*install_sec
)
468 len
= sizeof(default_install
) - 1;
469 ptr
= default_install
;
473 len
= lstrlenW(install_sec
);
477 info
->install_sec
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
478 if (!info
->install_sec
)
479 return E_OUTOFMEMORY
;
481 lstrcpyW(info
->install_sec
, ptr
);
483 hr
= get_working_dir(info
, inf_filename
, working_dir
);
487 len
= lstrlenW(info
->working_dir
) + lstrlenW(info
->inf_filename
) + 2;
488 info
->inf_path
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
490 return E_OUTOFMEMORY
;
492 lstrcpyW(info
->inf_path
, info
->working_dir
);
493 lstrcatW(info
->inf_path
, backslash
);
494 lstrcatW(info
->inf_path
, info
->inf_filename
);
496 /* RunSetupCommand opens unmodifed filename parameter */
497 if (flags
& RSC_FLAG_INF
)
500 path
= info
->inf_path
;
502 info
->hinf
= SetupOpenInfFileW(path
, NULL
, INF_STYLE_WIN4
, NULL
);
503 if (info
->hinf
== INVALID_HANDLE_VALUE
)
504 return ADV_HRESULT(GetLastError());
506 set_ldids(info
->hinf
, info
->install_sec
, info
->working_dir
);
508 /* FIXME: check that the INF is advanced */
511 info
->need_reboot
= FALSE
;
516 /* release the install instance information */
517 static void install_release(const ADVInfo
*info
)
519 SetupCloseInfFile(info
->hinf
);
521 HeapFree(GetProcessHeap(), 0, info
->inf_path
);
522 HeapFree(GetProcessHeap(), 0, info
->inf_filename
);
523 HeapFree(GetProcessHeap(), 0, info
->install_sec
);
524 HeapFree(GetProcessHeap(), 0, info
->working_dir
);
527 /* this structure very closely resembles parameters of RunSetupCommand() */
535 } SETUPCOMMAND_PARAMS
;
543 LPCWSTR section_name
;
544 } SETUPCOMMAND_PARAMSW
;
546 /* internal: see DoInfInstall */
547 static HRESULT
DoInfInstallW(const SETUPCOMMAND_PARAMSW
*setup
)
552 TRACE("(%p)\n", setup
);
554 ZeroMemory(&info
, sizeof(ADVInfo
));
556 hr
= install_init(setup
->inf_name
, setup
->section_name
, setup
->dir
, 0, &info
);
560 hr
= spapi_install(&info
);
564 hr
= adv_install(&info
);
567 install_release(&info
);
572 /***********************************************************************
573 * DoInfInstall (ADVPACK.@)
575 * Install an INF section.
578 * setup [I] Structure containing install information.
582 * HRESULT_FROM_WIN32(GetLastError()) Some other error
584 HRESULT WINAPI
DoInfInstall(const SETUPCOMMAND_PARAMS
*setup
)
586 UNICODE_STRING title
, inf
, section
, dir
;
587 SETUPCOMMAND_PARAMSW params
;
593 RtlCreateUnicodeStringFromAsciiz(&title
, setup
->title
);
594 RtlCreateUnicodeStringFromAsciiz(&inf
, setup
->inf_name
);
595 RtlCreateUnicodeStringFromAsciiz(§ion
, setup
->section_name
);
596 RtlCreateUnicodeStringFromAsciiz(&dir
, setup
->dir
);
598 params
.title
= title
.Buffer
;
599 params
.inf_name
= inf
.Buffer
;
600 params
.section_name
= section
.Buffer
;
601 params
.dir
= dir
.Buffer
;
602 params
.hwnd
= setup
->hwnd
;
604 hr
= DoInfInstallW(¶ms
);
606 RtlFreeUnicodeString(&title
);
607 RtlFreeUnicodeString(&inf
);
608 RtlFreeUnicodeString(§ion
);
609 RtlFreeUnicodeString(&dir
);
614 /***********************************************************************
615 * ExecuteCabA (ADVPACK.@)
619 HRESULT WINAPI
ExecuteCabA(HWND hwnd
, CABINFOA
* pCab
, LPVOID pReserved
)
621 UNICODE_STRING cab
, inf
, section
;
625 TRACE("(%p, %p, %p)\n", hwnd
, pCab
, pReserved
);
632 RtlCreateUnicodeStringFromAsciiz(&cab
, pCab
->pszCab
);
633 cabinfo
.pszCab
= cab
.Buffer
;
636 cabinfo
.pszCab
= NULL
;
638 RtlCreateUnicodeStringFromAsciiz(&inf
, pCab
->pszInf
);
639 RtlCreateUnicodeStringFromAsciiz(§ion
, pCab
->pszSection
);
641 MultiByteToWideChar(CP_ACP
, 0, pCab
->szSrcPath
, -1, cabinfo
.szSrcPath
, ARRAY_SIZE(cabinfo
.szSrcPath
));
643 cabinfo
.pszInf
= inf
.Buffer
;
644 cabinfo
.pszSection
= section
.Buffer
;
645 cabinfo
.dwFlags
= pCab
->dwFlags
;
647 hr
= ExecuteCabW(hwnd
, &cabinfo
, pReserved
);
650 RtlFreeUnicodeString(&cab
);
652 RtlFreeUnicodeString(&inf
);
653 RtlFreeUnicodeString(§ion
);
658 /***********************************************************************
659 * ExecuteCabW (ADVPACK.@)
661 * Installs the INF file extracted from a specified cabinet file.
664 * hwnd [I] Handle to the window used for the display.
665 * pCab [I] Information about the cabinet file.
666 * pReserved [I] Reserved. Must be NULL.
672 HRESULT WINAPI
ExecuteCabW(HWND hwnd
, CABINFOW
* pCab
, LPVOID pReserved
)
677 TRACE("(%p, %p, %p)\n", hwnd
, pCab
, pReserved
);
679 ZeroMemory(&info
, sizeof(ADVInfo
));
681 if (pCab
->pszCab
&& *pCab
->pszCab
)
682 FIXME("Cab archive not extracted!\n");
684 hr
= install_init(pCab
->pszInf
, pCab
->pszSection
, pCab
->szSrcPath
, pCab
->dwFlags
, &info
);
688 hr
= spapi_install(&info
);
692 hr
= adv_install(&info
);
695 install_release(&info
);
700 /***********************************************************************
701 * LaunchINFSectionA (ADVPACK.@)
703 * See LaunchINFSectionW.
705 INT WINAPI
LaunchINFSectionA(HWND hWnd
, HINSTANCE hInst
, LPSTR cmdline
, INT show
)
710 TRACE("(%p, %p, %s, %i)\n", hWnd
, hInst
, debugstr_a(cmdline
), show
);
715 RtlCreateUnicodeStringFromAsciiz(&cmd
, cmdline
);
717 hr
= LaunchINFSectionW(hWnd
, hInst
, cmd
.Buffer
, show
);
719 RtlFreeUnicodeString(&cmd
);
724 /***********************************************************************
725 * LaunchINFSectionW (ADVPACK.@)
727 * Installs an INF section without BACKUP/ROLLBACK capabilities.
730 * hWnd [I] Handle to parent window, NULL for desktop.
731 * hInst [I] Instance of the process.
732 * cmdline [I] Contains parameters in the order INF,section,flags,reboot.
733 * show [I] How the window should be shown.
736 * Success: ADV_SUCCESS.
737 * Failure: ADV_FAILURE.
740 * INF - Filename of the INF to launch.
741 * section - INF section to install.
742 * flags - see advpub.h.
743 * reboot - smart reboot behavior
745 * 'I' Reboot if needed (default).
748 INT WINAPI
LaunchINFSectionW(HWND hWnd
, HINSTANCE hInst
, LPWSTR cmdline
, INT show
)
751 LPWSTR cmdline_copy
, cmdline_ptr
;
752 LPWSTR inf_filename
, install_sec
;
757 TRACE("(%p, %p, %s, %d)\n", hWnd
, hInst
, debugstr_w(cmdline
), show
);
762 cmdline_copy
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(cmdline
) + 1) * sizeof(WCHAR
));
763 cmdline_ptr
= cmdline_copy
;
764 lstrcpyW(cmdline_copy
, cmdline
);
766 inf_filename
= get_parameter(&cmdline_ptr
, ',', TRUE
);
767 install_sec
= get_parameter(&cmdline_ptr
, ',', TRUE
);
769 str_flags
= get_parameter(&cmdline_ptr
, ',', TRUE
);
772 DWORD inf_flags
= atolW(str_flags
);
773 if (inf_flags
& LIS_QUIET
) flags
|= RSC_FLAG_QUIET
;
774 if (inf_flags
& LIS_NOGRPCONV
) flags
|= RSC_FLAG_NGCONV
;
777 ZeroMemory(&info
, sizeof(ADVInfo
));
779 hr
= install_init(inf_filename
, install_sec
, NULL
, flags
, &info
);
783 hr
= spapi_install(&info
);
787 hr
= adv_install(&info
);
790 install_release(&info
);
791 HeapFree(GetProcessHeap(), 0, cmdline_copy
);
793 return SUCCEEDED(hr
) ? ADV_SUCCESS
: ADV_FAILURE
;
796 /***********************************************************************
797 * LaunchINFSectionExA (ADVPACK.@)
799 * See LaunchINFSectionExW.
801 HRESULT WINAPI
LaunchINFSectionExA(HWND hWnd
, HINSTANCE hInst
, LPSTR cmdline
, INT show
)
806 TRACE("(%p, %p, %s, %i)\n", hWnd
, hInst
, debugstr_a(cmdline
), show
);
811 RtlCreateUnicodeStringFromAsciiz(&cmd
, cmdline
);
813 hr
= LaunchINFSectionExW(hWnd
, hInst
, cmd
.Buffer
, show
);
815 RtlFreeUnicodeString(&cmd
);
820 /***********************************************************************
821 * LaunchINFSectionExW (ADVPACK.@)
823 * Installs an INF section with BACKUP/ROLLBACK capabilities.
826 * hWnd [I] Handle to parent window, NULL for desktop.
827 * hInst [I] Instance of the process.
828 * cmdline [I] Contains parameters in the order INF,section,CAB,flags,reboot.
829 * show [I] How the window should be shown.
832 * Success: ADV_SUCCESS.
833 * Failure: ADV_FAILURE.
836 * INF - Filename of the INF to launch.
837 * section - INF section to install.
838 * flags - see advpub.h.
839 * reboot - smart reboot behavior
841 * 'I' Reboot if needed (default).
845 * Doesn't handle the reboot flag.
847 HRESULT WINAPI
LaunchINFSectionExW(HWND hWnd
, HINSTANCE hInst
, LPWSTR cmdline
, INT show
)
849 LPWSTR cmdline_copy
, cmdline_ptr
;
854 TRACE("(%p, %p, %s, %d)\n", hWnd
, hInst
, debugstr_w(cmdline
), show
);
859 cmdline_copy
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(cmdline
) + 1) * sizeof(WCHAR
));
860 cmdline_ptr
= cmdline_copy
;
861 lstrcpyW(cmdline_copy
, cmdline
);
863 cabinfo
.pszInf
= get_parameter(&cmdline_ptr
, ',', TRUE
);
864 cabinfo
.pszSection
= get_parameter(&cmdline_ptr
, ',', TRUE
);
865 cabinfo
.pszCab
= get_parameter(&cmdline_ptr
, ',', TRUE
);
866 *cabinfo
.szSrcPath
= '\0';
868 flags
= get_parameter(&cmdline_ptr
, ',', TRUE
);
870 cabinfo
.dwFlags
= atolW(flags
);
872 if (!is_full_path(cabinfo
.pszCab
) && !is_full_path(cabinfo
.pszInf
))
874 HeapFree(GetProcessHeap(), 0, cmdline_copy
);
878 /* get the source path from the cab filename */
879 if (cabinfo
.pszCab
&& *cabinfo
.pszCab
)
881 if (!is_full_path(cabinfo
.pszCab
))
882 lstrcpyW(cabinfo
.szSrcPath
, cabinfo
.pszInf
);
884 lstrcpyW(cabinfo
.szSrcPath
, cabinfo
.pszCab
);
886 ptr
= strrchrW(cabinfo
.szSrcPath
, '\\');
890 hr
= ExecuteCabW(hWnd
, &cabinfo
, NULL
);
891 HeapFree(GetProcessHeap(), 0, cmdline_copy
);
892 return SUCCEEDED(hr
) ? ADV_SUCCESS
: ADV_FAILURE
;
895 HRESULT
launch_exe(LPCWSTR cmd
, LPCWSTR dir
, HANDLE
*phEXE
)
898 PROCESS_INFORMATION pi
;
900 if (phEXE
) *phEXE
= NULL
;
902 ZeroMemory(&pi
, sizeof(pi
));
903 ZeroMemory(&si
, sizeof(si
));
906 if (!CreateProcessW(NULL
, (LPWSTR
)cmd
, NULL
, NULL
, FALSE
,
907 CREATE_DEFAULT_ERROR_MODE
| CREATE_NEW_PROCESS_GROUP
,
908 NULL
, dir
, &si
, &pi
))
910 return HRESULT_FROM_WIN32(GetLastError());
913 CloseHandle(pi
.hThread
);
917 *phEXE
= pi
.hProcess
;
918 return S_ASYNCHRONOUS
;
921 /* wait for the child process to finish */
922 WaitForSingleObject(pi
.hProcess
, INFINITE
);
923 CloseHandle(pi
.hProcess
);
928 /***********************************************************************
929 * RunSetupCommandA (ADVPACK.@)
931 * See RunSetupCommandW.
933 HRESULT WINAPI
RunSetupCommandA(HWND hWnd
, LPCSTR szCmdName
,
934 LPCSTR szInfSection
, LPCSTR szDir
,
935 LPCSTR lpszTitle
, HANDLE
*phEXE
,
936 DWORD dwFlags
, LPVOID pvReserved
)
938 UNICODE_STRING cmdname
, infsec
;
939 UNICODE_STRING dir
, title
;
942 TRACE("(%p, %s, %s, %s, %s, %p, %d, %p)\n",
943 hWnd
, debugstr_a(szCmdName
), debugstr_a(szInfSection
),
944 debugstr_a(szDir
), debugstr_a(lpszTitle
),
945 phEXE
, dwFlags
, pvReserved
);
947 if (!szCmdName
|| !szDir
)
950 RtlCreateUnicodeStringFromAsciiz(&cmdname
, szCmdName
);
951 RtlCreateUnicodeStringFromAsciiz(&infsec
, szInfSection
);
952 RtlCreateUnicodeStringFromAsciiz(&dir
, szDir
);
953 RtlCreateUnicodeStringFromAsciiz(&title
, lpszTitle
);
955 hr
= RunSetupCommandW(hWnd
, cmdname
.Buffer
, infsec
.Buffer
, dir
.Buffer
,
956 title
.Buffer
, phEXE
, dwFlags
, pvReserved
);
958 RtlFreeUnicodeString(&cmdname
);
959 RtlFreeUnicodeString(&infsec
);
960 RtlFreeUnicodeString(&dir
);
961 RtlFreeUnicodeString(&title
);
966 /***********************************************************************
967 * RunSetupCommandW (ADVPACK.@)
969 * Executes an install section in an INF file or a program.
972 * hWnd [I] Handle to parent window, NULL for quiet mode
973 * szCmdName [I] Inf or EXE filename to execute
974 * szInfSection [I] Inf section to install, NULL for DefaultInstall
975 * szDir [I] Path to extracted files
976 * szTitle [I] Title of all dialogs
977 * phEXE [O] Handle of EXE to wait for
978 * dwFlags [I] Flags; see include/advpub.h
979 * pvReserved [I] Reserved
983 * S_ASYNCHRONOUS OK, required to wait on phEXE
984 * ERROR_SUCCESS_REBOOT_REQUIRED Reboot required
985 * E_INVALIDARG Invalid argument given
986 * HRESULT_FROM_WIN32(ERROR_OLD_WIN_VERSION)
987 * Not supported on this Windows version
988 * E_UNEXPECTED Unexpected error
989 * HRESULT_FROM_WIN32(GetLastError()) Some other error
991 HRESULT WINAPI
RunSetupCommandW(HWND hWnd
, LPCWSTR szCmdName
,
992 LPCWSTR szInfSection
, LPCWSTR szDir
,
993 LPCWSTR lpszTitle
, HANDLE
*phEXE
,
994 DWORD dwFlags
, LPVOID pvReserved
)
999 TRACE("(%p, %s, %s, %s, %s, %p, %d, %p)\n",
1000 hWnd
, debugstr_w(szCmdName
), debugstr_w(szInfSection
),
1001 debugstr_w(szDir
), debugstr_w(lpszTitle
),
1002 phEXE
, dwFlags
, pvReserved
);
1004 if (dwFlags
& RSC_FLAG_UPDHLPDLLS
)
1005 FIXME("Unhandled flag: RSC_FLAG_UPDHLPDLLS\n");
1007 if (!szCmdName
|| !szDir
)
1008 return E_INVALIDARG
;
1010 if (!(dwFlags
& RSC_FLAG_INF
))
1011 return launch_exe(szCmdName
, szDir
, phEXE
);
1013 ZeroMemory(&info
, sizeof(ADVInfo
));
1015 hr
= install_init(szCmdName
, szInfSection
, szDir
, dwFlags
, &info
);
1019 hr
= spapi_install(&info
);
1023 hr
= adv_install(&info
);
1026 install_release(&info
);