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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(advpack
);
36 /* this structure very closely resembles parameters of RunSetupCommand() */
44 } SETUPCOMMAND_PARAMS
;
46 /***********************************************************************
47 * DoInfInstall (ADVPACK.@)
49 * Install an INF section.
52 * setup [I] Structure containing install information.
56 * HRESULT_FROM_WIN32(GetLastError()) Some other error
58 HRESULT WINAPI
DoInfInstall(const SETUPCOMMAND_PARAMS
*setup
)
62 void *callback_context
;
64 TRACE("%p %s %s %s %s\n", setup
->hwnd
, debugstr_a(setup
->title
),
65 debugstr_a(setup
->inf_name
), debugstr_a(setup
->dir
),
66 debugstr_a(setup
->section_name
));
68 hinf
= SetupOpenInfFileA(setup
->inf_name
, NULL
, INF_STYLE_WIN4
, NULL
);
69 if (hinf
== INVALID_HANDLE_VALUE
) return HRESULT_FROM_WIN32(GetLastError());
71 callback_context
= SetupInitDefaultQueueCallback(setup
->hwnd
);
73 ret
= SetupInstallFromInfSectionA(NULL
, hinf
, setup
->section_name
, SPINST_ALL
,
74 NULL
, NULL
, 0, SetupDefaultQueueCallbackA
,
75 callback_context
, NULL
, NULL
);
76 SetupTermDefaultQueueCallback(callback_context
);
77 SetupCloseInfFile(hinf
);
79 return ret
? S_OK
: HRESULT_FROM_WIN32(GetLastError());
82 /***********************************************************************
83 * ExecuteCabA (ADVPACK.@)
85 * Installs the INF file extracted from a specified cabinet file.
88 * hwnd [I] Handle to the window used for the display.
89 * pCab [I] Information about the cabinet file.
90 * pReserved [I] Reserved. Must be NULL.
99 HRESULT WINAPI
ExecuteCabA( HWND hwnd
, CABINFOA
* pCab
, LPVOID pReserved
)
101 FIXME("(%p %p %p): stub\n", hwnd
, pCab
, pReserved
);
105 /***********************************************************************
106 * LaunchINFSectionA (ADVPACK.@)
108 * Installs an INF section without BACKUP/ROLLBACK capabilities.
111 * hWnd [I] Handle to parent window, NULL for desktop.
112 * hInst [I] Instance of the process.
113 * cmdline [I] Contains parameters in the order INF,section,flags,reboot.
114 * show [I] How the window should be shown.
121 * INF - Filename of the INF to launch.
122 * section - INF section to install.
123 * flags - see advpub.h.
124 * reboot - smart reboot behavior
126 * 'I' Reboot if needed (default).
132 INT WINAPI
LaunchINFSectionA( HWND hWnd
, HINSTANCE hInst
, LPSTR cmdline
, INT show
)
134 FIXME("(%p %p %s %d): stub\n", hWnd
, hInst
, debugstr_a(cmdline
), show
);
138 /***********************************************************************
139 * LaunchINFSectionExA (ADVPACK.@)
141 * Installs an INF section with BACKUP/ROLLBACK capabilities.
144 * hWnd [I] Handle to parent window, NULL for desktop.
145 * hInst [I] Instance of the process.
146 * cmdline [I] Contains parameters in the order INF,section,CAB,flags,reboot.
147 * show [I] How the window should be shown.
154 * INF - Filename of the INF to launch.
155 * section - INF section to install.
156 * flags - see advpub.h.
157 * reboot - smart reboot behavior
159 * 'I' Reboot if needed (default).
165 HRESULT WINAPI
LaunchINFSectionExA( HWND hWnd
, HINSTANCE hInst
, LPSTR cmdline
, INT show
)
167 FIXME("(%p %p %s %d): stub\n", hWnd
, hInst
, debugstr_a(cmdline
), show
);
171 static HRESULT
launch_exe(LPCWSTR cmd
, LPCWSTR dir
, HANDLE
*phEXE
)
174 PROCESS_INFORMATION pi
;
176 if (phEXE
) *phEXE
= NULL
;
178 ZeroMemory(&pi
, sizeof(pi
));
179 ZeroMemory(&si
, sizeof(si
));
182 if (!CreateProcessW(NULL
, (LPWSTR
)cmd
, NULL
, NULL
, FALSE
,
183 CREATE_DEFAULT_ERROR_MODE
| CREATE_NEW_PROCESS_GROUP
,
184 NULL
, dir
, &si
, &pi
))
186 return HRESULT_FROM_WIN32(GetLastError());
189 CloseHandle(pi
.hThread
);
193 *phEXE
= pi
.hProcess
;
194 return S_ASYNCHRONOUS
;
197 /* wait for the child process to finish */
198 WaitForSingleObject(pi
.hProcess
, INFINITE
);
199 CloseHandle(pi
.hProcess
);
204 /***********************************************************************
205 * RunSetupCommandA (ADVPACK.@)
207 * See RunSetupCommandW.
209 HRESULT WINAPI
RunSetupCommandA(HWND hWnd
, LPCSTR szCmdName
,
210 LPCSTR szInfSection
, LPCSTR szDir
,
211 LPCSTR lpszTitle
, HANDLE
*phEXE
,
212 DWORD dwFlags
, LPVOID pvReserved
)
214 UNICODE_STRING cmdname
, infsec
;
215 UNICODE_STRING dir
, title
;
218 TRACE("(%p, %s, %s, %s, %s, %p, 0x%08lx, %p)\n",
219 hWnd
, debugstr_a(szCmdName
), debugstr_a(szInfSection
),
220 debugstr_a(szDir
), debugstr_a(lpszTitle
),
221 phEXE
, dwFlags
, pvReserved
);
223 if (!szCmdName
|| !szDir
)
226 RtlCreateUnicodeStringFromAsciiz(&cmdname
, szCmdName
);
227 RtlCreateUnicodeStringFromAsciiz(&infsec
, szInfSection
);
228 RtlCreateUnicodeStringFromAsciiz(&dir
, szDir
);
229 RtlCreateUnicodeStringFromAsciiz(&title
, lpszTitle
);
231 hr
= RunSetupCommandW(hWnd
, cmdname
.Buffer
, infsec
.Buffer
, dir
.Buffer
,
232 title
.Buffer
, phEXE
, dwFlags
, pvReserved
);
234 RtlFreeUnicodeString(&cmdname
);
235 RtlFreeUnicodeString(&infsec
);
236 RtlFreeUnicodeString(&dir
);
237 RtlFreeUnicodeString(&title
);
242 /***********************************************************************
243 * RunSetupCommandW (ADVPACK.@)
245 * Executes an install section in an INF file or a program.
248 * hWnd [I] Handle to parent window, NULL for quiet mode
249 * szCmdName [I] Inf or EXE filename to execute
250 * szInfSection [I] Inf section to install, NULL for DefaultInstall
251 * szDir [I] Path to extracted files
252 * szTitle [I] Title of all dialogs
253 * phEXE [O] Handle of EXE to wait for
254 * dwFlags [I] Flags; see include/advpub.h
255 * pvReserved [I] Reserved
259 * S_ASYNCHRONOUS OK, required to wait on phEXE
260 * ERROR_SUCCESS_REBOOT_REQUIRED Reboot required
261 * E_INVALIDARG Invalid argument given
262 * HRESULT_FROM_WIN32(ERROR_OLD_WIN_VERSION)
263 * Not supported on this Windows version
264 * E_UNEXPECTED Unexpected error
265 * HRESULT_FROM_WIN32(GetLastError()) Some other error
268 * INF install unimplemented.
270 HRESULT WINAPI
RunSetupCommandW(HWND hWnd
, LPCWSTR szCmdName
,
271 LPCWSTR szInfSection
, LPCWSTR szDir
,
272 LPCWSTR lpszTitle
, HANDLE
*phEXE
,
273 DWORD dwFlags
, LPVOID pvReserved
)
275 TRACE("(%p, %s, %s, %s, %s, %p, 0x%08lx, %p)\n",
276 hWnd
, debugstr_w(szCmdName
), debugstr_w(szInfSection
),
277 debugstr_w(szDir
), debugstr_w(lpszTitle
),
278 phEXE
, dwFlags
, pvReserved
);
281 FIXME("Unhandled flags: 0x%08lx\n", dwFlags
);
283 if (!szCmdName
|| !szDir
)
286 if (!(dwFlags
& RSC_FLAG_INF
))
287 return launch_exe(szCmdName
, szDir
, phEXE
);