advpack: Fix the documentation for the cmdline parameter of LaunchInfSection/Ex.
[wine/wine-kai.git] / dlls / advpack / install.c
blob417084ea051bccbd295b8aa87adf183c3dd673be
1 /*
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
21 #include <stdarg.h>
22 #include <stdlib.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "winreg.h"
28 #include "winver.h"
29 #include "winternl.h"
30 #include "setupapi.h"
31 #include "advpub.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(advpack);
36 /* this structure very closely resembles parameters of RunSetupCommand() */
37 typedef struct
39 HWND hwnd;
40 LPCSTR title;
41 LPCSTR inf_name;
42 LPCSTR dir;
43 LPCSTR section_name;
44 } SETUPCOMMAND_PARAMS;
46 /***********************************************************************
47 * DoInfInstall (ADVPACK.@)
49 * Install an INF section.
51 * PARAMS
52 * setup [I] Structure containing install information.
54 * RETURNS
55 * S_OK Everything OK
56 * HRESULT_FROM_WIN32(GetLastError()) Some other error
58 HRESULT WINAPI DoInfInstall(const SETUPCOMMAND_PARAMS *setup)
60 BOOL ret;
61 HINF hinf;
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.
87 * PARAMS
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.
92 * RETURNS
93 * Success: S_OK.
94 * Failure: E_FAIL.
96 * BUGS
97 * Unimplemented
99 HRESULT WINAPI ExecuteCabA( HWND hwnd, CABINFOA* pCab, LPVOID pReserved )
101 FIXME("(%p %p %p): stub\n", hwnd, pCab, pReserved);
102 return E_FAIL;
105 /***********************************************************************
106 * LaunchINFSectionA (ADVPACK.@)
108 * Installs an INF section without BACKUP/ROLLBACK capabilities.
110 * PARAMS
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.
116 * RETURNS
117 * Success: S_OK.
118 * Failure: S_FALSE
120 * NOTES
121 * INF - Filename of the INF to launch.
122 * section - INF section to install.
123 * flags - see advpub.h.
124 * reboot - smart reboot behavior
125 * 'A' Always reboot.
126 * 'I' Reboot if needed (default).
127 * 'N' No reboot.
129 * BUGS
130 * Unimplemented.
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 );
135 return 0;
138 /***********************************************************************
139 * LaunchINFSectionExA (ADVPACK.@)
141 * Installs an INF section with BACKUP/ROLLBACK capabilities.
143 * PARAMS
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.
149 * RETURNS
150 * Success: S_OK.
151 * Failure: E_FAIL.
153 * NOTES
154 * INF - Filename of the INF to launch.
155 * section - INF section to install.
156 * flags - see advpub.h.
157 * reboot - smart reboot behavior
158 * 'A' Always reboot.
159 * 'I' Reboot if needed (default).
160 * 'N' No reboot.
162 * BUGS
163 * Unimplemented.
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 );
168 return E_FAIL;
171 static HRESULT launch_exe(LPCWSTR cmd, LPCWSTR dir, HANDLE *phEXE)
173 STARTUPINFOW si;
174 PROCESS_INFORMATION pi;
176 if (phEXE) *phEXE = NULL;
178 ZeroMemory(&pi, sizeof(pi));
179 ZeroMemory(&si, sizeof(si));
180 si.cb = 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);
191 if (phEXE)
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);
201 return S_OK;
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;
216 HRESULT hr;
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)
224 return E_INVALIDARG;
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);
239 return hr;
242 /***********************************************************************
243 * RunSetupCommandW (ADVPACK.@)
245 * Executes an install section in an INF file or a program.
247 * PARAMS
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
257 * RETURNS
258 * S_OK Everything OK
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
267 * BUGS
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);
280 if (dwFlags)
281 FIXME("Unhandled flags: 0x%08lx\n", dwFlags);
283 if (!szCmdName || !szDir)
284 return E_INVALIDARG;
286 if (!(dwFlags & RSC_FLAG_INF))
287 return launch_exe(szCmdName, szDir, phEXE);
289 return E_UNEXPECTED;