2006-02-21 04:44:03 +01:00
|
|
|
/*
|
|
|
|
* Advpack install functions
|
|
|
|
*
|
|
|
|
* Copyright 2006 James Hawkins
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2006-02-21 04:44:03 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "winreg.h"
|
2006-03-24 06:11:15 +01:00
|
|
|
#include "winternl.h"
|
2006-03-30 20:26:59 +02:00
|
|
|
#include "winnls.h"
|
2006-02-21 04:44:03 +01:00
|
|
|
#include "setupapi.h"
|
|
|
|
#include "advpub.h"
|
2007-04-01 14:44:18 +02:00
|
|
|
#include "ole2.h"
|
2006-02-21 04:44:03 +01:00
|
|
|
#include "wine/debug.h"
|
2006-04-18 23:13:26 +02:00
|
|
|
#include "advpack_private.h"
|
2006-02-21 04:44:03 +01:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(advpack);
|
|
|
|
|
2006-03-29 19:36:04 +02:00
|
|
|
#define SPAPI_ERROR 0xE0000000L
|
|
|
|
#define SPAPI_PREFIX 0x800F0000L
|
|
|
|
#define SPAPI_MASK 0xFFFFL
|
2008-07-19 11:08:05 +02:00
|
|
|
#define HRESULT_FROM_SPAPI(x) ((HRESULT)((x & SPAPI_MASK) | SPAPI_PREFIX))
|
2006-03-29 19:36:04 +02:00
|
|
|
|
2006-04-04 20:15:51 +02:00
|
|
|
#define ADV_HRESULT(x) ((x & SPAPI_ERROR) ? HRESULT_FROM_SPAPI(x) : HRESULT_FROM_WIN32(x))
|
|
|
|
|
2006-07-08 03:30:46 +02:00
|
|
|
#define ADV_SUCCESS 0
|
|
|
|
#define ADV_FAILURE 1
|
|
|
|
|
2006-04-17 08:51:06 +02:00
|
|
|
/* contains information about a specific install instance */
|
|
|
|
typedef struct _ADVInfo
|
|
|
|
{
|
|
|
|
HINF hinf;
|
2006-08-30 00:12:22 +02:00
|
|
|
LPWSTR inf_path;
|
2006-04-17 08:51:06 +02:00
|
|
|
LPWSTR inf_filename;
|
|
|
|
LPWSTR install_sec;
|
|
|
|
LPWSTR working_dir;
|
|
|
|
DWORD flags;
|
|
|
|
BOOL need_reboot;
|
|
|
|
} ADVInfo;
|
|
|
|
|
2007-04-02 23:49:59 +02:00
|
|
|
typedef HRESULT (*iterate_fields_func)(HINF hinf, PCWSTR field, const void *arg);
|
2006-04-20 08:36:26 +02:00
|
|
|
|
|
|
|
/* Advanced INF commands */
|
2006-04-29 03:08:35 +02:00
|
|
|
static const WCHAR CheckAdminRights[] = {
|
|
|
|
'C','h','e','c','k','A','d','m','i','n','R','i','g','h','t','s',0
|
|
|
|
};
|
2006-04-29 03:09:08 +02:00
|
|
|
static const WCHAR DelDirs[] = {'D','e','l','D','i','r','s',0};
|
2006-04-29 03:06:34 +02:00
|
|
|
static const WCHAR PerUserInstall[] = {'P','e','r','U','s','e','r','I','n','s','t','a','l','l',0};
|
2006-04-20 08:36:26 +02:00
|
|
|
static const WCHAR RegisterOCXs[] = {'R','e','g','i','s','t','e','r','O','C','X','s',0};
|
2006-04-29 03:08:10 +02:00
|
|
|
static const WCHAR RunPreSetupCommands[] = {
|
|
|
|
'R','u','n','P','r','e','S','e','t','u','p','C','o','m','m','a','n','d','s',0
|
|
|
|
};
|
2006-04-20 17:09:00 +02:00
|
|
|
static const WCHAR RunPostSetupCommands[] = {
|
|
|
|
'R','u','n','P','o','s','t','S','e','t','u','p','C','o','m','m','a','n','d','s',0
|
|
|
|
};
|
2006-04-20 08:36:26 +02:00
|
|
|
|
|
|
|
/* Advanced INF callbacks */
|
2007-04-02 23:49:59 +02:00
|
|
|
static HRESULT del_dirs_callback(HINF hinf, PCWSTR field, const void *arg)
|
2006-04-29 03:09:08 +02:00
|
|
|
{
|
|
|
|
INFCONTEXT context;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
BOOL ok = SetupFindFirstLineW(hinf, field, NULL, &context);
|
|
|
|
|
|
|
|
for (; ok; ok = SetupFindNextLine(&context, &context))
|
|
|
|
{
|
|
|
|
WCHAR directory[MAX_INF_STRING_LENGTH];
|
|
|
|
|
|
|
|
if (!SetupGetLineTextW(&context, NULL, NULL, NULL, directory,
|
|
|
|
MAX_INF_STRING_LENGTH, &size))
|
|
|
|
continue;
|
|
|
|
|
2008-09-12 14:00:55 +02:00
|
|
|
if (DelNodeW(directory, ADN_DEL_IF_EMPTY) != S_OK)
|
2006-04-29 03:09:08 +02:00
|
|
|
hr = E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2007-04-02 23:49:59 +02:00
|
|
|
static HRESULT per_user_install_callback(HINF hinf, PCWSTR field, const void *arg)
|
2006-04-29 03:06:34 +02:00
|
|
|
{
|
|
|
|
PERUSERSECTIONW per_user;
|
|
|
|
INFCONTEXT context;
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
static const WCHAR disp_name[] = {'D','i','s','p','l','a','y','N','a','m','e',0};
|
|
|
|
static const WCHAR version[] = {'V','e','r','s','i','o','n',0};
|
|
|
|
static const WCHAR is_installed[] = {'I','s','I','n','s','t','a','l','l','e','d',0};
|
|
|
|
static const WCHAR comp_id[] = {'C','o','m','p','o','n','e','n','t','I','D',0};
|
|
|
|
static const WCHAR guid[] = {'G','U','I','D',0};
|
|
|
|
static const WCHAR locale[] = {'L','o','c','a','l','e',0};
|
|
|
|
static const WCHAR stub_path[] = {'S','t','u','b','P','a','t','h',0};
|
|
|
|
|
|
|
|
per_user.bRollback = FALSE;
|
|
|
|
per_user.dwIsInstalled = 0;
|
|
|
|
|
2018-06-11 21:22:35 +02:00
|
|
|
SetupGetLineTextW(NULL, hinf, field, disp_name, per_user.szDispName, ARRAY_SIZE(per_user.szDispName), &size);
|
2006-04-29 03:06:34 +02:00
|
|
|
|
2018-06-11 21:22:35 +02:00
|
|
|
SetupGetLineTextW(NULL, hinf, field, version, per_user.szVersion, ARRAY_SIZE(per_user.szVersion), &size);
|
2006-04-29 03:06:34 +02:00
|
|
|
|
|
|
|
if (SetupFindFirstLineW(hinf, field, is_installed, &context))
|
|
|
|
{
|
|
|
|
SetupGetIntField(&context, 1, (PINT)&per_user.dwIsInstalled);
|
|
|
|
}
|
|
|
|
|
2018-06-11 21:22:35 +02:00
|
|
|
SetupGetLineTextW(NULL, hinf, field, comp_id, per_user.szCompID, ARRAY_SIZE(per_user.szCompID), &size);
|
2006-04-29 03:06:34 +02:00
|
|
|
|
2018-06-11 21:22:35 +02:00
|
|
|
SetupGetLineTextW(NULL, hinf, field, guid, per_user.szGUID, ARRAY_SIZE(per_user.szGUID), &size);
|
2006-04-29 03:06:34 +02:00
|
|
|
|
2018-06-11 21:22:35 +02:00
|
|
|
SetupGetLineTextW(NULL, hinf, field, locale, per_user.szLocale, ARRAY_SIZE(per_user.szLocale), &size);
|
2006-04-29 03:06:34 +02:00
|
|
|
|
2018-06-11 21:22:35 +02:00
|
|
|
SetupGetLineTextW(NULL, hinf, field, stub_path, per_user.szStub, ARRAY_SIZE(per_user.szStub), &size);
|
2006-04-29 03:06:34 +02:00
|
|
|
|
|
|
|
return SetPerUserSecValuesW(&per_user);
|
|
|
|
}
|
|
|
|
|
2007-04-02 23:49:59 +02:00
|
|
|
static HRESULT register_ocxs_callback(HINF hinf, PCWSTR field, const void *arg)
|
2006-04-20 08:36:26 +02:00
|
|
|
{
|
2006-04-20 17:08:44 +02:00
|
|
|
HMODULE hm;
|
|
|
|
INFCONTEXT context;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
BOOL ok = SetupFindFirstLineW(hinf, field, NULL, &context);
|
|
|
|
|
|
|
|
for (; ok; ok = SetupFindNextLine(&context, &context))
|
|
|
|
{
|
|
|
|
WCHAR buffer[MAX_INF_STRING_LENGTH];
|
|
|
|
|
|
|
|
/* get OCX filename */
|
2018-06-11 21:22:35 +02:00
|
|
|
if (!SetupGetStringFieldW(&context, 1, buffer, ARRAY_SIZE(buffer), NULL))
|
2006-04-20 17:08:44 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
hm = LoadLibraryExW(buffer, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
|
2007-04-01 14:45:00 +02:00
|
|
|
if (hm)
|
|
|
|
{
|
2011-11-07 11:45:18 +01:00
|
|
|
if (do_ocx_reg(hm, TRUE, NULL, NULL) != S_OK)
|
2007-04-01 14:45:00 +02:00
|
|
|
hr = E_FAIL;
|
|
|
|
|
|
|
|
FreeLibrary(hm);
|
|
|
|
}
|
|
|
|
else
|
2006-04-20 17:08:44 +02:00
|
|
|
hr = E_FAIL;
|
|
|
|
|
2007-04-01 14:45:00 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
/* FIXME: display a message box */
|
|
|
|
break;
|
|
|
|
}
|
2006-04-20 17:08:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2006-04-20 08:36:26 +02:00
|
|
|
}
|
|
|
|
|
2007-04-02 23:49:59 +02:00
|
|
|
static HRESULT run_setup_commands_callback(HINF hinf, PCWSTR field, const void *arg)
|
2006-04-20 17:09:00 +02:00
|
|
|
{
|
2007-04-02 23:49:59 +02:00
|
|
|
const ADVInfo *info = (const ADVInfo *)arg;
|
2006-04-20 17:09:00 +02:00
|
|
|
INFCONTEXT context;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
BOOL ok = SetupFindFirstLineW(hinf, field, NULL, &context);
|
|
|
|
|
|
|
|
for (; ok; ok = SetupFindNextLine(&context, &context))
|
|
|
|
{
|
|
|
|
WCHAR buffer[MAX_INF_STRING_LENGTH];
|
|
|
|
|
|
|
|
if (!SetupGetLineTextW(&context, NULL, NULL, NULL, buffer,
|
|
|
|
MAX_INF_STRING_LENGTH, &size))
|
|
|
|
continue;
|
|
|
|
|
2008-09-12 14:00:55 +02:00
|
|
|
if (launch_exe(buffer, info->working_dir, NULL) != S_OK)
|
2006-04-20 17:09:00 +02:00
|
|
|
hr = E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2006-04-11 07:17:36 +02:00
|
|
|
/* sequentially returns pointers to parameters in a parameter list
|
|
|
|
* returns NULL if the parameter is empty, e.g. one,,three */
|
2013-07-22 23:48:19 +02:00
|
|
|
LPWSTR get_parameter(LPWSTR *params, WCHAR separator, BOOL quoted)
|
2006-04-11 07:17:36 +02:00
|
|
|
{
|
|
|
|
LPWSTR token = *params;
|
|
|
|
|
|
|
|
if (!*params)
|
|
|
|
return NULL;
|
|
|
|
|
2013-07-22 23:48:19 +02:00
|
|
|
if (quoted && *token == '"')
|
|
|
|
{
|
2019-05-27 15:50:49 +02:00
|
|
|
WCHAR *end = wcschr(token + 1, '"');
|
2013-07-22 23:48:19 +02:00
|
|
|
if (end)
|
|
|
|
{
|
|
|
|
*end = 0;
|
|
|
|
*params = end + 1;
|
|
|
|
token = token + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-27 15:50:49 +02:00
|
|
|
*params = wcschr(*params, separator);
|
2006-04-11 07:17:36 +02:00
|
|
|
if (*params)
|
|
|
|
*(*params)++ = '\0';
|
|
|
|
|
|
|
|
if (!*token)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return token;
|
|
|
|
}
|
|
|
|
|
2007-03-12 21:49:29 +01:00
|
|
|
static BOOL is_full_path(LPCWSTR path)
|
2006-04-11 07:17:36 +02:00
|
|
|
{
|
|
|
|
const int MIN_PATH_LEN = 3;
|
|
|
|
|
|
|
|
if (!path || lstrlenW(path) < MIN_PATH_LEN)
|
|
|
|
return FALSE;
|
|
|
|
|
2006-10-24 03:44:59 +02:00
|
|
|
if ((path[1] == ':' && path[2] == '\\') || (path[0] == '\\' && path[1] == '\\'))
|
2006-04-11 07:17:36 +02:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2006-04-20 08:36:26 +02:00
|
|
|
/* retrieves the contents of a field, dynamically growing the buffer if necessary */
|
|
|
|
static WCHAR *get_field_string(INFCONTEXT *context, DWORD index, WCHAR *buffer,
|
2007-03-12 21:49:29 +01:00
|
|
|
const WCHAR *static_buffer, DWORD *size)
|
2006-04-20 08:36:26 +02:00
|
|
|
{
|
|
|
|
DWORD required;
|
|
|
|
|
|
|
|
if (SetupGetStringFieldW(context, index, buffer, *size, &required)) return buffer;
|
|
|
|
|
|
|
|
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
|
|
|
|
{
|
|
|
|
/* now grow the buffer */
|
|
|
|
if (buffer != static_buffer) HeapFree(GetProcessHeap(), 0, buffer);
|
|
|
|
if (!(buffer = HeapAlloc(GetProcessHeap(), 0, required*sizeof(WCHAR)))) return NULL;
|
|
|
|
*size = required;
|
|
|
|
if (SetupGetStringFieldW(context, index, buffer, *size, &required)) return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buffer != static_buffer) HeapFree(GetProcessHeap(), 0, buffer);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* iterates over all fields of a certain key of a certain section */
|
|
|
|
static HRESULT iterate_section_fields(HINF hinf, PCWSTR section, PCWSTR key,
|
|
|
|
iterate_fields_func callback, void *arg)
|
|
|
|
{
|
|
|
|
WCHAR static_buffer[200];
|
|
|
|
WCHAR *buffer = static_buffer;
|
2018-06-11 21:22:35 +02:00
|
|
|
DWORD size = ARRAY_SIZE(static_buffer);
|
2006-04-20 08:36:26 +02:00
|
|
|
INFCONTEXT context;
|
|
|
|
HRESULT hr = E_FAIL;
|
|
|
|
|
|
|
|
BOOL ok = SetupFindFirstLineW(hinf, section, key, &context);
|
|
|
|
while (ok)
|
|
|
|
{
|
|
|
|
UINT i, count = SetupGetFieldCount(&context);
|
|
|
|
|
|
|
|
for (i = 1; i <= count; i++)
|
|
|
|
{
|
|
|
|
if (!(buffer = get_field_string(&context, i, buffer, static_buffer, &size)))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if ((hr = callback(hinf, buffer, arg)) != S_OK)
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
ok = SetupFindNextMatchLineW(&context, key, &context);
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = S_OK;
|
|
|
|
|
|
|
|
done:
|
2006-06-07 10:55:33 +02:00
|
|
|
if (buffer != static_buffer) HeapFree(GetProcessHeap(), 0, buffer);
|
2006-04-20 08:36:26 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2007-04-02 23:49:59 +02:00
|
|
|
static HRESULT check_admin_rights(const ADVInfo *info)
|
2006-04-29 03:08:35 +02:00
|
|
|
{
|
|
|
|
INT check;
|
|
|
|
INFCONTEXT context;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
if (!SetupFindFirstLineW(info->hinf, info->install_sec,
|
|
|
|
CheckAdminRights, &context))
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
if (!SetupGetIntField(&context, 1, &check))
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
if (check == 1)
|
|
|
|
hr = IsNTAdmin(0, NULL) ? S_OK : E_FAIL;
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2006-04-11 07:18:49 +02:00
|
|
|
/* performs a setupapi-level install of the INF file */
|
2007-04-02 23:49:59 +02:00
|
|
|
static HRESULT spapi_install(const ADVInfo *info)
|
2006-04-11 07:18:49 +02:00
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
HRESULT res;
|
|
|
|
PVOID context;
|
|
|
|
|
|
|
|
context = SetupInitDefaultQueueCallbackEx(NULL, INVALID_HANDLE_VALUE, 0, 0, NULL);
|
|
|
|
if (!context)
|
|
|
|
return ADV_HRESULT(GetLastError());
|
|
|
|
|
2006-04-17 08:51:06 +02:00
|
|
|
ret = SetupInstallFromInfSectionW(NULL, info->hinf, info->install_sec,
|
|
|
|
SPINST_FILES, NULL, info->working_dir,
|
|
|
|
SP_COPY_NEWER, SetupDefaultQueueCallbackW,
|
2006-04-17 08:49:12 +02:00
|
|
|
context, NULL, NULL);
|
2006-04-11 07:18:49 +02:00
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
res = ADV_HRESULT(GetLastError());
|
|
|
|
SetupTermDefaultQueueCallback(context);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetupTermDefaultQueueCallback(context);
|
|
|
|
|
2006-04-17 08:51:06 +02:00
|
|
|
ret = SetupInstallFromInfSectionW(NULL, info->hinf, info->install_sec,
|
2006-08-30 00:12:39 +02:00
|
|
|
SPINST_INIFILES | SPINST_REGISTRY | SPINST_REGSVR,
|
2006-04-11 07:18:49 +02:00
|
|
|
HKEY_LOCAL_MACHINE, NULL, 0,
|
|
|
|
NULL, NULL, NULL, NULL);
|
|
|
|
if (!ret)
|
|
|
|
return ADV_HRESULT(GetLastError());
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2006-04-20 08:36:26 +02:00
|
|
|
/* processes the Advanced INF commands */
|
|
|
|
static HRESULT adv_install(ADVInfo *info)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
2006-04-29 03:08:35 +02:00
|
|
|
hr = check_admin_rights(info);
|
|
|
|
if (hr != S_OK)
|
|
|
|
return hr;
|
|
|
|
|
2006-04-29 03:08:10 +02:00
|
|
|
hr = iterate_section_fields(info->hinf, info->install_sec, RunPreSetupCommands,
|
|
|
|
run_setup_commands_callback, info);
|
|
|
|
if (hr != S_OK)
|
|
|
|
return hr;
|
|
|
|
|
2007-04-01 14:44:18 +02:00
|
|
|
OleInitialize(NULL);
|
2006-04-20 08:36:26 +02:00
|
|
|
hr = iterate_section_fields(info->hinf, info->install_sec,
|
|
|
|
RegisterOCXs, register_ocxs_callback, NULL);
|
2007-04-01 14:44:18 +02:00
|
|
|
OleUninitialize();
|
2006-04-20 17:09:00 +02:00
|
|
|
if (hr != S_OK)
|
|
|
|
return hr;
|
|
|
|
|
2006-04-29 03:06:34 +02:00
|
|
|
hr = iterate_section_fields(info->hinf, info->install_sec,
|
|
|
|
PerUserInstall, per_user_install_callback, info);
|
|
|
|
if (hr != S_OK)
|
|
|
|
return hr;
|
|
|
|
|
2006-04-20 17:09:00 +02:00
|
|
|
hr = iterate_section_fields(info->hinf, info->install_sec, RunPostSetupCommands,
|
2006-04-29 03:08:10 +02:00
|
|
|
run_setup_commands_callback, info);
|
2006-04-20 17:09:00 +02:00
|
|
|
if (hr != S_OK)
|
|
|
|
return hr;
|
2006-04-20 08:36:26 +02:00
|
|
|
|
2006-04-29 03:09:08 +02:00
|
|
|
hr = iterate_section_fields(info->hinf, info->install_sec,
|
|
|
|
DelDirs, del_dirs_callback, info);
|
|
|
|
if (hr != S_OK)
|
|
|
|
return hr;
|
|
|
|
|
2006-04-20 08:36:26 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2006-08-30 00:12:22 +02:00
|
|
|
/* determines the proper working directory for the INF file */
|
|
|
|
static HRESULT get_working_dir(ADVInfo *info, LPCWSTR inf_filename, LPCWSTR working_dir)
|
|
|
|
{
|
|
|
|
WCHAR path[MAX_PATH];
|
|
|
|
LPCWSTR ptr;
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
static const WCHAR backslash[] = {'\\',0};
|
|
|
|
static const WCHAR inf_dir[] = {'\\','I','N','F',0};
|
|
|
|
|
2019-05-27 15:50:49 +02:00
|
|
|
if ((ptr = wcsrchr(inf_filename, '\\')))
|
2006-08-30 00:12:22 +02:00
|
|
|
{
|
|
|
|
len = ptr - inf_filename + 1;
|
|
|
|
ptr = inf_filename;
|
|
|
|
}
|
|
|
|
else if (working_dir && *working_dir)
|
|
|
|
{
|
|
|
|
len = lstrlenW(working_dir) + 1;
|
|
|
|
ptr = working_dir;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GetCurrentDirectoryW(MAX_PATH, path);
|
|
|
|
lstrcatW(path, backslash);
|
|
|
|
lstrcatW(path, inf_filename);
|
|
|
|
|
|
|
|
/* check if the INF file is in the current directory */
|
|
|
|
if (GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
|
|
|
|
{
|
|
|
|
GetCurrentDirectoryW(MAX_PATH, path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* default to the windows\inf directory if all else fails */
|
|
|
|
GetWindowsDirectoryW(path, MAX_PATH);
|
|
|
|
lstrcatW(path, inf_dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
len = lstrlenW(path) + 1;
|
|
|
|
ptr = path;
|
|
|
|
}
|
|
|
|
|
|
|
|
info->working_dir = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
if (!info->working_dir)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
lstrcpynW(info->working_dir, ptr, len);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2006-04-17 08:51:06 +02:00
|
|
|
/* loads the INF file and performs checks on it */
|
2006-10-09 09:04:08 +02:00
|
|
|
static HRESULT install_init(LPCWSTR inf_filename, LPCWSTR install_sec,
|
|
|
|
LPCWSTR working_dir, DWORD flags, ADVInfo *info)
|
2006-04-17 08:51:06 +02:00
|
|
|
{
|
|
|
|
DWORD len;
|
2006-08-30 00:12:22 +02:00
|
|
|
HRESULT hr;
|
|
|
|
LPCWSTR ptr, path;
|
2006-04-17 08:51:06 +02:00
|
|
|
|
2006-08-30 00:12:22 +02:00
|
|
|
static const WCHAR backslash[] = {'\\',0};
|
2006-04-17 08:51:06 +02:00
|
|
|
static const WCHAR default_install[] = {
|
|
|
|
'D','e','f','a','u','l','t','I','n','s','t','a','l','l',0
|
|
|
|
};
|
|
|
|
|
2019-05-27 15:50:49 +02:00
|
|
|
if (!(ptr = wcsrchr(inf_filename, '\\')))
|
2006-08-30 00:12:22 +02:00
|
|
|
ptr = inf_filename;
|
|
|
|
|
|
|
|
len = lstrlenW(ptr);
|
2006-04-17 08:51:06 +02:00
|
|
|
|
|
|
|
info->inf_filename = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
|
|
|
|
if (!info->inf_filename)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2006-08-30 00:12:22 +02:00
|
|
|
lstrcpyW(info->inf_filename, ptr);
|
2006-04-17 08:51:06 +02:00
|
|
|
|
|
|
|
/* FIXME: determine the proper platform to install (NTx86, etc) */
|
|
|
|
if (!install_sec || !*install_sec)
|
|
|
|
{
|
|
|
|
len = sizeof(default_install) - 1;
|
|
|
|
ptr = default_install;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
len = lstrlenW(install_sec);
|
|
|
|
ptr = install_sec;
|
|
|
|
}
|
|
|
|
|
|
|
|
info->install_sec = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
|
|
|
|
if (!info->install_sec)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
lstrcpyW(info->install_sec, ptr);
|
|
|
|
|
2006-08-30 00:12:22 +02:00
|
|
|
hr = get_working_dir(info, inf_filename, working_dir);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
2006-04-17 08:51:06 +02:00
|
|
|
|
2006-08-30 00:12:22 +02:00
|
|
|
len = lstrlenW(info->working_dir) + lstrlenW(info->inf_filename) + 2;
|
|
|
|
info->inf_path = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
if (!info->inf_path)
|
2006-04-17 08:51:06 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2006-08-30 00:12:22 +02:00
|
|
|
lstrcpyW(info->inf_path, info->working_dir);
|
|
|
|
lstrcatW(info->inf_path, backslash);
|
|
|
|
lstrcatW(info->inf_path, info->inf_filename);
|
|
|
|
|
2019-08-08 15:21:32 +02:00
|
|
|
/* RunSetupCommand opens unmodified filename parameter */
|
2006-08-30 00:12:22 +02:00
|
|
|
if (flags & RSC_FLAG_INF)
|
|
|
|
path = inf_filename;
|
|
|
|
else
|
|
|
|
path = info->inf_path;
|
2006-04-17 08:51:06 +02:00
|
|
|
|
2006-08-30 00:12:22 +02:00
|
|
|
info->hinf = SetupOpenInfFileW(path, NULL, INF_STYLE_WIN4, NULL);
|
2006-04-17 08:51:06 +02:00
|
|
|
if (info->hinf == INVALID_HANDLE_VALUE)
|
|
|
|
return ADV_HRESULT(GetLastError());
|
|
|
|
|
2006-04-20 08:36:39 +02:00
|
|
|
set_ldids(info->hinf, info->install_sec, info->working_dir);
|
|
|
|
|
2006-04-17 08:51:06 +02:00
|
|
|
/* FIXME: check that the INF is advanced */
|
|
|
|
|
|
|
|
info->flags = flags;
|
|
|
|
info->need_reboot = FALSE;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* release the install instance information */
|
2007-04-02 23:49:59 +02:00
|
|
|
static void install_release(const ADVInfo *info)
|
2006-04-17 08:51:06 +02:00
|
|
|
{
|
2007-07-09 19:38:59 +02:00
|
|
|
SetupCloseInfFile(info->hinf);
|
2006-04-17 08:51:06 +02:00
|
|
|
|
2006-08-30 00:12:22 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, info->inf_path);
|
2006-04-17 08:51:06 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, info->inf_filename);
|
|
|
|
HeapFree(GetProcessHeap(), 0, info->install_sec);
|
|
|
|
HeapFree(GetProcessHeap(), 0, info->working_dir);
|
|
|
|
}
|
|
|
|
|
2006-02-21 04:44:03 +01:00
|
|
|
/* this structure very closely resembles parameters of RunSetupCommand() */
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
HWND hwnd;
|
|
|
|
LPCSTR title;
|
|
|
|
LPCSTR inf_name;
|
|
|
|
LPCSTR dir;
|
|
|
|
LPCSTR section_name;
|
|
|
|
} SETUPCOMMAND_PARAMS;
|
|
|
|
|
2006-06-20 23:31:01 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
HWND hwnd;
|
|
|
|
LPCWSTR title;
|
|
|
|
LPCWSTR inf_name;
|
|
|
|
LPCWSTR dir;
|
|
|
|
LPCWSTR section_name;
|
|
|
|
} SETUPCOMMAND_PARAMSW;
|
|
|
|
|
|
|
|
/* internal: see DoInfInstall */
|
|
|
|
static HRESULT DoInfInstallW(const SETUPCOMMAND_PARAMSW *setup)
|
|
|
|
{
|
|
|
|
ADVInfo info;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", setup);
|
|
|
|
|
|
|
|
ZeroMemory(&info, sizeof(ADVInfo));
|
|
|
|
|
|
|
|
hr = install_init(setup->inf_name, setup->section_name, setup->dir, 0, &info);
|
|
|
|
if (hr != S_OK)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
hr = spapi_install(&info);
|
|
|
|
if (hr != S_OK)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
hr = adv_install(&info);
|
|
|
|
|
|
|
|
done:
|
|
|
|
install_release(&info);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2006-02-21 04:44:03 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* DoInfInstall (ADVPACK.@)
|
|
|
|
*
|
|
|
|
* Install an INF section.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* setup [I] Structure containing install information.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* S_OK Everything OK
|
|
|
|
* HRESULT_FROM_WIN32(GetLastError()) Some other error
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI DoInfInstall(const SETUPCOMMAND_PARAMS *setup)
|
|
|
|
{
|
2006-06-20 23:31:01 +02:00
|
|
|
UNICODE_STRING title, inf, section, dir;
|
|
|
|
SETUPCOMMAND_PARAMSW params;
|
|
|
|
HRESULT hr;
|
2006-02-21 04:44:03 +01:00
|
|
|
|
2006-06-20 23:31:01 +02:00
|
|
|
if (!setup)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
RtlCreateUnicodeStringFromAsciiz(&title, setup->title);
|
|
|
|
RtlCreateUnicodeStringFromAsciiz(&inf, setup->inf_name);
|
|
|
|
RtlCreateUnicodeStringFromAsciiz(§ion, setup->section_name);
|
|
|
|
RtlCreateUnicodeStringFromAsciiz(&dir, setup->dir);
|
2006-02-21 04:44:03 +01:00
|
|
|
|
2006-06-20 23:31:01 +02:00
|
|
|
params.title = title.Buffer;
|
|
|
|
params.inf_name = inf.Buffer;
|
|
|
|
params.section_name = section.Buffer;
|
|
|
|
params.dir = dir.Buffer;
|
|
|
|
params.hwnd = setup->hwnd;
|
2006-02-21 04:44:03 +01:00
|
|
|
|
2006-06-20 23:31:01 +02:00
|
|
|
hr = DoInfInstallW(¶ms);
|
2006-02-21 04:44:03 +01:00
|
|
|
|
2006-06-20 23:31:01 +02:00
|
|
|
RtlFreeUnicodeString(&title);
|
|
|
|
RtlFreeUnicodeString(&inf);
|
|
|
|
RtlFreeUnicodeString(§ion);
|
|
|
|
RtlFreeUnicodeString(&dir);
|
2006-02-21 04:44:03 +01:00
|
|
|
|
2006-06-20 23:31:01 +02:00
|
|
|
return hr;
|
2006-02-21 04:44:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2006-02-24 16:09:42 +01:00
|
|
|
* ExecuteCabA (ADVPACK.@)
|
2006-03-30 20:26:59 +02:00
|
|
|
*
|
|
|
|
* See ExecuteCabW.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI ExecuteCabA(HWND hwnd, CABINFOA* pCab, LPVOID pReserved)
|
|
|
|
{
|
|
|
|
UNICODE_STRING cab, inf, section;
|
|
|
|
CABINFOW cabinfo;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p, %p, %p)\n", hwnd, pCab, pReserved);
|
|
|
|
|
|
|
|
if (!pCab)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (pCab->pszCab)
|
|
|
|
{
|
|
|
|
RtlCreateUnicodeStringFromAsciiz(&cab, pCab->pszCab);
|
|
|
|
cabinfo.pszCab = cab.Buffer;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cabinfo.pszCab = NULL;
|
|
|
|
|
|
|
|
RtlCreateUnicodeStringFromAsciiz(&inf, pCab->pszInf);
|
|
|
|
RtlCreateUnicodeStringFromAsciiz(§ion, pCab->pszSection);
|
|
|
|
|
2018-06-11 21:22:35 +02:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, pCab->szSrcPath, -1, cabinfo.szSrcPath, ARRAY_SIZE(cabinfo.szSrcPath));
|
2006-03-30 20:26:59 +02:00
|
|
|
|
|
|
|
cabinfo.pszInf = inf.Buffer;
|
|
|
|
cabinfo.pszSection = section.Buffer;
|
|
|
|
cabinfo.dwFlags = pCab->dwFlags;
|
|
|
|
|
|
|
|
hr = ExecuteCabW(hwnd, &cabinfo, pReserved);
|
|
|
|
|
|
|
|
if (pCab->pszCab)
|
|
|
|
RtlFreeUnicodeString(&cab);
|
|
|
|
|
|
|
|
RtlFreeUnicodeString(&inf);
|
|
|
|
RtlFreeUnicodeString(§ion);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ExecuteCabW (ADVPACK.@)
|
2006-02-21 04:44:03 +01:00
|
|
|
*
|
|
|
|
* Installs the INF file extracted from a specified cabinet file.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hwnd [I] Handle to the window used for the display.
|
|
|
|
* pCab [I] Information about the cabinet file.
|
|
|
|
* pReserved [I] Reserved. Must be NULL.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK.
|
|
|
|
* Failure: E_FAIL.
|
|
|
|
*/
|
2006-03-30 20:26:59 +02:00
|
|
|
HRESULT WINAPI ExecuteCabW(HWND hwnd, CABINFOW* pCab, LPVOID pReserved)
|
2006-02-21 04:44:03 +01:00
|
|
|
{
|
2006-04-20 17:09:16 +02:00
|
|
|
ADVInfo info;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p, %p, %p)\n", hwnd, pCab, pReserved);
|
|
|
|
|
|
|
|
ZeroMemory(&info, sizeof(ADVInfo));
|
|
|
|
|
2020-05-11 00:10:57 +02:00
|
|
|
if ((pCab->pszCab && *pCab->pszCab) && (pCab->pszInf && *pCab->pszInf) && *pCab->szSrcPath)
|
|
|
|
{
|
|
|
|
TRACE("pszCab: %s, pszInf: %s, szSrcPath: %s\n", debugstr_w(pCab->pszCab), debugstr_w(pCab->pszInf),
|
|
|
|
debugstr_w(pCab->szSrcPath));
|
|
|
|
|
|
|
|
hr = ExtractFilesW(pCab->pszCab, pCab->szSrcPath, 0, pCab->pszInf, NULL, 0);
|
|
|
|
if (FAILED(hr))
|
|
|
|
ERR("Failed to extract .inf file!\n");
|
|
|
|
}
|
2006-04-20 17:09:16 +02:00
|
|
|
|
|
|
|
hr = install_init(pCab->pszInf, pCab->pszSection, pCab->szSrcPath, pCab->dwFlags, &info);
|
|
|
|
if (hr != S_OK)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
hr = spapi_install(&info);
|
|
|
|
if (hr != S_OK)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
hr = adv_install(&info);
|
|
|
|
|
|
|
|
done:
|
|
|
|
install_release(&info);
|
|
|
|
|
2006-04-29 02:59:31 +02:00
|
|
|
return hr;
|
2006-02-21 04:44:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2006-02-24 16:09:42 +01:00
|
|
|
* LaunchINFSectionA (ADVPACK.@)
|
2006-02-21 04:44:03 +01:00
|
|
|
*
|
2006-04-03 19:04:59 +02:00
|
|
|
* See LaunchINFSectionW.
|
|
|
|
*/
|
|
|
|
INT WINAPI LaunchINFSectionA(HWND hWnd, HINSTANCE hInst, LPSTR cmdline, INT show)
|
|
|
|
{
|
|
|
|
UNICODE_STRING cmd;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2006-04-11 07:17:13 +02:00
|
|
|
TRACE("(%p, %p, %s, %i)\n", hWnd, hInst, debugstr_a(cmdline), show);
|
2006-04-03 19:04:59 +02:00
|
|
|
|
2006-07-08 03:30:46 +02:00
|
|
|
if (!cmdline)
|
|
|
|
return ADV_FAILURE;
|
|
|
|
|
2006-04-03 19:04:59 +02:00
|
|
|
RtlCreateUnicodeStringFromAsciiz(&cmd, cmdline);
|
|
|
|
|
|
|
|
hr = LaunchINFSectionW(hWnd, hInst, cmd.Buffer, show);
|
|
|
|
|
|
|
|
RtlFreeUnicodeString(&cmd);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* LaunchINFSectionW (ADVPACK.@)
|
|
|
|
*
|
2006-02-21 04:44:03 +01:00
|
|
|
* Installs an INF section without BACKUP/ROLLBACK capabilities.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hWnd [I] Handle to parent window, NULL for desktop.
|
|
|
|
* hInst [I] Instance of the process.
|
2006-03-30 11:52:17 +02:00
|
|
|
* cmdline [I] Contains parameters in the order INF,section,flags,reboot.
|
|
|
|
* show [I] How the window should be shown.
|
2006-02-21 04:44:03 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
2006-07-08 03:30:46 +02:00
|
|
|
* Success: ADV_SUCCESS.
|
|
|
|
* Failure: ADV_FAILURE.
|
2006-02-21 04:44:03 +01:00
|
|
|
*
|
2006-03-30 11:52:17 +02:00
|
|
|
* NOTES
|
|
|
|
* INF - Filename of the INF to launch.
|
|
|
|
* section - INF section to install.
|
|
|
|
* flags - see advpub.h.
|
|
|
|
* reboot - smart reboot behavior
|
|
|
|
* 'A' Always reboot.
|
|
|
|
* 'I' Reboot if needed (default).
|
|
|
|
* 'N' No reboot.
|
2006-02-21 04:44:03 +01:00
|
|
|
*/
|
2006-04-03 19:04:59 +02:00
|
|
|
INT WINAPI LaunchINFSectionW(HWND hWnd, HINSTANCE hInst, LPWSTR cmdline, INT show)
|
2006-02-21 04:44:03 +01:00
|
|
|
{
|
2006-04-20 17:09:44 +02:00
|
|
|
ADVInfo info;
|
|
|
|
LPWSTR cmdline_copy, cmdline_ptr;
|
|
|
|
LPWSTR inf_filename, install_sec;
|
|
|
|
LPWSTR str_flags;
|
|
|
|
DWORD flags = 0;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
TRACE("(%p, %p, %s, %d)\n", hWnd, hInst, debugstr_w(cmdline), show);
|
|
|
|
|
|
|
|
if (!cmdline)
|
2006-07-08 03:30:46 +02:00
|
|
|
return ADV_FAILURE;
|
2006-04-20 17:09:44 +02:00
|
|
|
|
|
|
|
cmdline_copy = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(cmdline) + 1) * sizeof(WCHAR));
|
|
|
|
cmdline_ptr = cmdline_copy;
|
|
|
|
lstrcpyW(cmdline_copy, cmdline);
|
|
|
|
|
2013-07-22 23:48:19 +02:00
|
|
|
inf_filename = get_parameter(&cmdline_ptr, ',', TRUE);
|
|
|
|
install_sec = get_parameter(&cmdline_ptr, ',', TRUE);
|
2006-04-20 17:09:44 +02:00
|
|
|
|
2013-07-22 23:48:19 +02:00
|
|
|
str_flags = get_parameter(&cmdline_ptr, ',', TRUE);
|
2006-04-20 17:09:44 +02:00
|
|
|
if (str_flags)
|
2015-10-09 08:07:14 +02:00
|
|
|
{
|
2019-05-27 15:50:49 +02:00
|
|
|
DWORD inf_flags = wcstol(str_flags, NULL, 10);
|
2015-10-09 08:07:14 +02:00
|
|
|
if (inf_flags & LIS_QUIET) flags |= RSC_FLAG_QUIET;
|
|
|
|
if (inf_flags & LIS_NOGRPCONV) flags |= RSC_FLAG_NGCONV;
|
|
|
|
}
|
2006-04-20 17:09:44 +02:00
|
|
|
|
|
|
|
ZeroMemory(&info, sizeof(ADVInfo));
|
|
|
|
|
|
|
|
hr = install_init(inf_filename, install_sec, NULL, flags, &info);
|
|
|
|
if (hr != S_OK)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
hr = spapi_install(&info);
|
|
|
|
if (hr != S_OK)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
hr = adv_install(&info);
|
|
|
|
|
|
|
|
done:
|
|
|
|
install_release(&info);
|
|
|
|
HeapFree(GetProcessHeap(), 0, cmdline_copy);
|
|
|
|
|
2006-07-08 03:30:46 +02:00
|
|
|
return SUCCEEDED(hr) ? ADV_SUCCESS : ADV_FAILURE;
|
2006-02-21 04:44:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2006-02-24 16:09:42 +01:00
|
|
|
* LaunchINFSectionExA (ADVPACK.@)
|
2006-02-21 04:44:03 +01:00
|
|
|
*
|
2006-03-30 12:05:27 +02:00
|
|
|
* See LaunchINFSectionExW.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI LaunchINFSectionExA(HWND hWnd, HINSTANCE hInst, LPSTR cmdline, INT show)
|
|
|
|
{
|
|
|
|
UNICODE_STRING cmd;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2006-04-20 08:35:40 +02:00
|
|
|
TRACE("(%p, %p, %s, %i)\n", hWnd, hInst, debugstr_a(cmdline), show);
|
2006-03-30 12:05:27 +02:00
|
|
|
|
2006-07-08 03:30:46 +02:00
|
|
|
if (!cmdline)
|
|
|
|
return ADV_FAILURE;
|
|
|
|
|
2006-03-30 12:05:27 +02:00
|
|
|
RtlCreateUnicodeStringFromAsciiz(&cmd, cmdline);
|
|
|
|
|
|
|
|
hr = LaunchINFSectionExW(hWnd, hInst, cmd.Buffer, show);
|
|
|
|
|
|
|
|
RtlFreeUnicodeString(&cmd);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* LaunchINFSectionExW (ADVPACK.@)
|
|
|
|
*
|
2006-02-21 04:44:03 +01:00
|
|
|
* Installs an INF section with BACKUP/ROLLBACK capabilities.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hWnd [I] Handle to parent window, NULL for desktop.
|
|
|
|
* hInst [I] Instance of the process.
|
2006-03-30 11:52:17 +02:00
|
|
|
* cmdline [I] Contains parameters in the order INF,section,CAB,flags,reboot.
|
|
|
|
* show [I] How the window should be shown.
|
2006-02-21 04:44:03 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
2006-07-08 03:30:46 +02:00
|
|
|
* Success: ADV_SUCCESS.
|
|
|
|
* Failure: ADV_FAILURE.
|
2006-02-21 04:44:03 +01:00
|
|
|
*
|
2006-03-30 11:52:17 +02:00
|
|
|
* NOTES
|
|
|
|
* INF - Filename of the INF to launch.
|
|
|
|
* section - INF section to install.
|
|
|
|
* flags - see advpub.h.
|
|
|
|
* reboot - smart reboot behavior
|
|
|
|
* 'A' Always reboot.
|
|
|
|
* 'I' Reboot if needed (default).
|
|
|
|
* 'N' No reboot.
|
2006-04-11 07:17:36 +02:00
|
|
|
*
|
2006-02-21 04:44:03 +01:00
|
|
|
* BUGS
|
2006-04-11 07:17:36 +02:00
|
|
|
* Doesn't handle the reboot flag.
|
2006-02-21 04:44:03 +01:00
|
|
|
*/
|
2006-03-30 12:05:27 +02:00
|
|
|
HRESULT WINAPI LaunchINFSectionExW(HWND hWnd, HINSTANCE hInst, LPWSTR cmdline, INT show)
|
2006-02-21 04:44:03 +01:00
|
|
|
{
|
2006-04-11 07:17:36 +02:00
|
|
|
LPWSTR cmdline_copy, cmdline_ptr;
|
|
|
|
LPWSTR flags, ptr;
|
|
|
|
CABINFOW cabinfo;
|
2006-11-01 20:52:58 +01:00
|
|
|
HRESULT hr;
|
2006-04-11 07:17:36 +02:00
|
|
|
|
|
|
|
TRACE("(%p, %p, %s, %d)\n", hWnd, hInst, debugstr_w(cmdline), show);
|
|
|
|
|
|
|
|
if (!cmdline)
|
2006-07-08 03:30:46 +02:00
|
|
|
return ADV_FAILURE;
|
2006-04-11 07:17:36 +02:00
|
|
|
|
|
|
|
cmdline_copy = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(cmdline) + 1) * sizeof(WCHAR));
|
|
|
|
cmdline_ptr = cmdline_copy;
|
|
|
|
lstrcpyW(cmdline_copy, cmdline);
|
|
|
|
|
2013-07-22 23:48:19 +02:00
|
|
|
cabinfo.pszInf = get_parameter(&cmdline_ptr, ',', TRUE);
|
|
|
|
cabinfo.pszSection = get_parameter(&cmdline_ptr, ',', TRUE);
|
|
|
|
cabinfo.pszCab = get_parameter(&cmdline_ptr, ',', TRUE);
|
2006-04-29 03:00:59 +02:00
|
|
|
*cabinfo.szSrcPath = '\0';
|
2006-04-11 07:17:36 +02:00
|
|
|
|
2013-07-22 23:48:19 +02:00
|
|
|
flags = get_parameter(&cmdline_ptr, ',', TRUE);
|
2006-04-11 07:17:36 +02:00
|
|
|
if (flags)
|
2019-05-27 15:50:49 +02:00
|
|
|
cabinfo.dwFlags = wcstol(flags, NULL, 10);
|
2006-04-11 07:17:36 +02:00
|
|
|
|
2006-11-01 20:52:58 +01:00
|
|
|
if (!is_full_path(cabinfo.pszCab) && !is_full_path(cabinfo.pszInf))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, cmdline_copy);
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2006-04-11 07:17:36 +02:00
|
|
|
/* get the source path from the cab filename */
|
|
|
|
if (cabinfo.pszCab && *cabinfo.pszCab)
|
|
|
|
{
|
|
|
|
if (!is_full_path(cabinfo.pszCab))
|
2006-11-01 20:52:58 +01:00
|
|
|
lstrcpyW(cabinfo.szSrcPath, cabinfo.pszInf);
|
|
|
|
else
|
|
|
|
lstrcpyW(cabinfo.szSrcPath, cabinfo.pszCab);
|
2006-04-11 07:17:36 +02:00
|
|
|
|
2019-05-27 15:50:49 +02:00
|
|
|
ptr = wcsrchr(cabinfo.szSrcPath, '\\');
|
2006-04-11 07:17:36 +02:00
|
|
|
*(++ptr) = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = ExecuteCabW(hWnd, &cabinfo, NULL);
|
|
|
|
HeapFree(GetProcessHeap(), 0, cmdline_copy);
|
2006-07-08 03:30:46 +02:00
|
|
|
return SUCCEEDED(hr) ? ADV_SUCCESS : ADV_FAILURE;
|
2006-02-21 04:44:03 +01:00
|
|
|
}
|
|
|
|
|
2006-04-11 08:26:44 +02:00
|
|
|
HRESULT launch_exe(LPCWSTR cmd, LPCWSTR dir, HANDLE *phEXE)
|
2006-03-27 06:05:58 +02:00
|
|
|
{
|
|
|
|
STARTUPINFOW si;
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
|
|
|
|
if (phEXE) *phEXE = NULL;
|
|
|
|
|
|
|
|
ZeroMemory(&pi, sizeof(pi));
|
|
|
|
ZeroMemory(&si, sizeof(si));
|
|
|
|
si.cb = sizeof(si);
|
|
|
|
|
|
|
|
if (!CreateProcessW(NULL, (LPWSTR)cmd, NULL, NULL, FALSE,
|
|
|
|
CREATE_DEFAULT_ERROR_MODE | CREATE_NEW_PROCESS_GROUP,
|
|
|
|
NULL, dir, &si, &pi))
|
|
|
|
{
|
|
|
|
return HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
|
|
|
|
if (phEXE)
|
|
|
|
{
|
|
|
|
*phEXE = pi.hProcess;
|
|
|
|
return S_ASYNCHRONOUS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* wait for the child process to finish */
|
|
|
|
WaitForSingleObject(pi.hProcess, INFINITE);
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2006-02-21 04:44:03 +01:00
|
|
|
/***********************************************************************
|
2006-02-24 16:09:42 +01:00
|
|
|
* RunSetupCommandA (ADVPACK.@)
|
2006-02-21 04:44:03 +01:00
|
|
|
*
|
2006-03-24 06:11:15 +01:00
|
|
|
* See RunSetupCommandW.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI RunSetupCommandA(HWND hWnd, LPCSTR szCmdName,
|
|
|
|
LPCSTR szInfSection, LPCSTR szDir,
|
|
|
|
LPCSTR lpszTitle, HANDLE *phEXE,
|
2006-04-11 07:08:54 +02:00
|
|
|
DWORD dwFlags, LPVOID pvReserved)
|
2006-03-24 06:11:15 +01:00
|
|
|
{
|
|
|
|
UNICODE_STRING cmdname, infsec;
|
|
|
|
UNICODE_STRING dir, title;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2006-10-07 04:06:59 +02:00
|
|
|
TRACE("(%p, %s, %s, %s, %s, %p, %d, %p)\n",
|
2006-04-11 07:17:13 +02:00
|
|
|
hWnd, debugstr_a(szCmdName), debugstr_a(szInfSection),
|
|
|
|
debugstr_a(szDir), debugstr_a(lpszTitle),
|
|
|
|
phEXE, dwFlags, pvReserved);
|
2006-03-24 06:11:15 +01:00
|
|
|
|
|
|
|
if (!szCmdName || !szDir)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
RtlCreateUnicodeStringFromAsciiz(&cmdname, szCmdName);
|
|
|
|
RtlCreateUnicodeStringFromAsciiz(&infsec, szInfSection);
|
|
|
|
RtlCreateUnicodeStringFromAsciiz(&dir, szDir);
|
|
|
|
RtlCreateUnicodeStringFromAsciiz(&title, lpszTitle);
|
|
|
|
|
|
|
|
hr = RunSetupCommandW(hWnd, cmdname.Buffer, infsec.Buffer, dir.Buffer,
|
|
|
|
title.Buffer, phEXE, dwFlags, pvReserved);
|
|
|
|
|
|
|
|
RtlFreeUnicodeString(&cmdname);
|
|
|
|
RtlFreeUnicodeString(&infsec);
|
|
|
|
RtlFreeUnicodeString(&dir);
|
|
|
|
RtlFreeUnicodeString(&title);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RunSetupCommandW (ADVPACK.@)
|
|
|
|
*
|
2006-02-21 04:44:03 +01:00
|
|
|
* Executes an install section in an INF file or a program.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hWnd [I] Handle to parent window, NULL for quiet mode
|
|
|
|
* szCmdName [I] Inf or EXE filename to execute
|
|
|
|
* szInfSection [I] Inf section to install, NULL for DefaultInstall
|
|
|
|
* szDir [I] Path to extracted files
|
|
|
|
* szTitle [I] Title of all dialogs
|
|
|
|
* phEXE [O] Handle of EXE to wait for
|
|
|
|
* dwFlags [I] Flags; see include/advpub.h
|
|
|
|
* pvReserved [I] Reserved
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* S_OK Everything OK
|
|
|
|
* S_ASYNCHRONOUS OK, required to wait on phEXE
|
|
|
|
* ERROR_SUCCESS_REBOOT_REQUIRED Reboot required
|
|
|
|
* E_INVALIDARG Invalid argument given
|
|
|
|
* HRESULT_FROM_WIN32(ERROR_OLD_WIN_VERSION)
|
|
|
|
* Not supported on this Windows version
|
|
|
|
* E_UNEXPECTED Unexpected error
|
|
|
|
* HRESULT_FROM_WIN32(GetLastError()) Some other error
|
|
|
|
*/
|
2006-03-24 06:11:15 +01:00
|
|
|
HRESULT WINAPI RunSetupCommandW(HWND hWnd, LPCWSTR szCmdName,
|
|
|
|
LPCWSTR szInfSection, LPCWSTR szDir,
|
|
|
|
LPCWSTR lpszTitle, HANDLE *phEXE,
|
2006-04-11 07:08:54 +02:00
|
|
|
DWORD dwFlags, LPVOID pvReserved)
|
2006-02-21 04:44:03 +01:00
|
|
|
{
|
2006-04-17 08:51:06 +02:00
|
|
|
ADVInfo info;
|
2006-04-11 07:18:49 +02:00
|
|
|
HRESULT hr;
|
2006-03-29 19:36:04 +02:00
|
|
|
|
2006-10-07 04:06:59 +02:00
|
|
|
TRACE("(%p, %s, %s, %s, %s, %p, %d, %p)\n",
|
2006-04-11 07:17:13 +02:00
|
|
|
hWnd, debugstr_w(szCmdName), debugstr_w(szInfSection),
|
|
|
|
debugstr_w(szDir), debugstr_w(lpszTitle),
|
|
|
|
phEXE, dwFlags, pvReserved);
|
2006-03-27 05:38:40 +02:00
|
|
|
|
2006-05-04 07:22:45 +02:00
|
|
|
if (dwFlags & RSC_FLAG_UPDHLPDLLS)
|
|
|
|
FIXME("Unhandled flag: RSC_FLAG_UPDHLPDLLS\n");
|
2006-03-27 06:05:58 +02:00
|
|
|
|
2006-03-27 05:38:40 +02:00
|
|
|
if (!szCmdName || !szDir)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (!(dwFlags & RSC_FLAG_INF))
|
2006-03-27 06:05:58 +02:00
|
|
|
return launch_exe(szCmdName, szDir, phEXE);
|
2006-03-27 05:38:40 +02:00
|
|
|
|
2006-04-17 08:51:06 +02:00
|
|
|
ZeroMemory(&info, sizeof(ADVInfo));
|
2006-03-29 19:36:04 +02:00
|
|
|
|
2006-04-17 08:51:06 +02:00
|
|
|
hr = install_init(szCmdName, szInfSection, szDir, dwFlags, &info);
|
|
|
|
if (hr != S_OK)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
hr = spapi_install(&info);
|
2006-04-20 08:36:26 +02:00
|
|
|
if (hr != S_OK)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
hr = adv_install(&info);
|
2006-04-17 08:51:06 +02:00
|
|
|
|
|
|
|
done:
|
|
|
|
install_release(&info);
|
2006-04-11 07:18:49 +02:00
|
|
|
|
|
|
|
return hr;
|
2006-02-21 04:44:03 +01:00
|
|
|
}
|