VBoxInstallHelper.cpp revision 056add8311718c0166b7036b31fd581858a607b3
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync/* $Id$ */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync/** @file
3184fc1a3e65025cd55704cdb1629f4ab1f3ccd2vboxsync * VBoxInstallHelper - Various helper routines for Windows host installer.
3184fc1a3e65025cd55704cdb1629f4ab1f3ccd2vboxsync */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync/*
056add8311718c0166b7036b31fd581858a607b3vboxsync * Copyright (C) 2008-2014 Oracle Corporation
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync *
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * available from http://www.virtualbox.org. This file is free software;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * you can redistribute it and/or modify it under the terms of the GNU
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * General Public License (GPL) as published by the Free Software
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync/*******************************************************************************
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync* Header Files *
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync*******************************************************************************/
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#ifdef VBOX_WITH_NETFLT
be6a7ee8f237a71cf075c128e8e391e6c3654687vboxsync# include "VBox/VBoxNetCfg-win.h"
2fa05a4e777b070ba9bf01e3dd46434c99cd06a3vboxsync# include "VBox/VBoxDrvCfg-win.h"
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#endif /* VBOX_WITH_NETFLT */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#include <VBox/version.h>
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#include <windows.h>
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync#include <wchar.h>
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#include <stdio.h>
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#include <msi.h>
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#include <msiquery.h>
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#define _WIN32_DCOM
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#include <windows.h>
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#include <assert.h>
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#include <shellapi.h>
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#define INITGUID
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#include <guiddef.h>
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#include <devguid.h>
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#include <objbase.h>
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#include <setupapi.h>
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#include <shlobj.h>
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#include <cfgmgr32.h>
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#include "VBoxCommon.h"
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#ifndef VBOX_OSE
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync# include "internal/VBoxSerial.h"
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#endif
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync/*******************************************************************************
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync* Header Files *
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync*******************************************************************************/
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#ifdef DEBUG
1cede4c702f5b7f8734214a2a5d5bc516b47b330vboxsync# define NonStandardAssert(_expr) assert(_expr)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#else
1cede4c702f5b7f8734214a2a5d5bc516b47b330vboxsync# define NonStandardAssert(_expr) do{ }while(0)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#endif
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync#define MY_WTEXT_HLP(a_str) L##a_str
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync#define MY_WTEXT(a_str) MY_WTEXT_HLP(a_str)
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncBOOL APIENTRY DllMain(HANDLE hModule,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync DWORD ul_reason_for_call,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LPVOID lpReserved)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return TRUE;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsyncstatic void logString(MSIHANDLE hInstall, LPCSTR szString, ...)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync PMSIHANDLE newHandle = MsiCreateRecord(2);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync char szBuffer[1024];
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync va_list va;
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync va_start(va, szString);
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync _vsnprintf(szBuffer, sizeof(szBuffer), szString, va);
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync va_end(va);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync MsiRecordSetStringA(newHandle, 0, szBuffer);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync MsiProcessMessage(hInstall, INSTALLMESSAGE(INSTALLMESSAGE_INFO), newHandle);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync MsiCloseHandle(newHandle);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync#if 0/*def DEBUG - wrong? What does '%s' expect, wchar or char? */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync _tprintf(_T("Debug: %s\n"), szBuffer);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#endif
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsyncstatic void logStringW(MSIHANDLE hInstall, LPCWSTR pwszString, ...)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync PMSIHANDLE newHandle = MsiCreateRecord(2);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync WCHAR szBuffer[1024];
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync va_list va;
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync va_start(va, pwszString);
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync _vsnwprintf(szBuffer, RT_ELEMENTS(szBuffer), pwszString, va);
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync va_end(va);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync MsiRecordSetStringW(newHandle, 0, szBuffer);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync MsiProcessMessage(hInstall, INSTALLMESSAGE(INSTALLMESSAGE_INFO), newHandle);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync MsiCloseHandle(newHandle);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsyncUINT __stdcall IsSerialCheckNeeded(MSIHANDLE hModule)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#ifndef VBOX_OSE
d97357e2036109245c83ba553d0290212e28ea40vboxsync /*BOOL bRet =*/ serialCheckNeeded(hModule);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#endif
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return ERROR_SUCCESS;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsyncUINT __stdcall CheckSerial(MSIHANDLE hModule)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#ifndef VBOX_OSE
d97357e2036109245c83ba553d0290212e28ea40vboxsync /*BOOL bRet =*/ serialIsValid(hModule);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#endif
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return ERROR_SUCCESS;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
254e593d079dbddd48135ebe2893334eb36dcbafvboxsyncDWORD Exec(MSIHANDLE hModule,
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync const WCHAR *pwszAppName, WCHAR *pwszCmdLine, const WCHAR *pwszWorkDir,
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync DWORD *pdwExitCode)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
fba7ec2ca5a120ca53275eebdfa69425ce0e9829vboxsync STARTUPINFOW si;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync PROCESS_INFORMATION pi;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync DWORD rc = ERROR_SUCCESS;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync ZeroMemory(&si, sizeof(si));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync si.dwFlags = STARTF_USESHOWWINDOW;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#ifdef UNICODE
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync si.dwFlags |= CREATE_UNICODE_ENVIRONMENT;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#endif
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync si.wShowWindow = SW_HIDE; /* For debugging: SW_SHOW; */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync si.cb = sizeof(si);
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync ZeroMemory(&pi, sizeof(pi));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"Executing command line: %s %s (Working Dir: %s)",
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync pwszAppName, pwszCmdLine, pwszWorkDir == NULL ? L"Current" : pwszWorkDir);
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync SetLastError(0);
fba7ec2ca5a120ca53275eebdfa69425ce0e9829vboxsync if (!CreateProcessW(pwszAppName, /* Module name. */
fba7ec2ca5a120ca53275eebdfa69425ce0e9829vboxsync pwszCmdLine, /* Command line. */
fba7ec2ca5a120ca53275eebdfa69425ce0e9829vboxsync NULL, /* Process handle not inheritable. */
fba7ec2ca5a120ca53275eebdfa69425ce0e9829vboxsync NULL, /* Thread handle not inheritable. */
fba7ec2ca5a120ca53275eebdfa69425ce0e9829vboxsync FALSE, /* Set handle inheritance to FALSE .*/
fba7ec2ca5a120ca53275eebdfa69425ce0e9829vboxsync 0, /* No creation flags. */
fba7ec2ca5a120ca53275eebdfa69425ce0e9829vboxsync NULL, /* Use parent's environment block. */
fba7ec2ca5a120ca53275eebdfa69425ce0e9829vboxsync pwszWorkDir, /* Use parent's starting directory. */
fba7ec2ca5a120ca53275eebdfa69425ce0e9829vboxsync &si, /* Pointer to STARTUPINFO structure. */
fba7ec2ca5a120ca53275eebdfa69425ce0e9829vboxsync &pi)) /* Pointer to PROCESS_INFORMATION structure. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync rc = GetLastError();
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"Executing command line: CreateProcess() failed! Error: %ld", rc);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return rc;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* Wait until child process exits. */
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync if (WAIT_FAILED == WaitForSingleObject(pi.hProcess, 30 * 1000 /* Wait 30 secs max. */))
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync rc = GetLastError();
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"Executing command line: WaitForSingleObject() failed! Error: %u", rc);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync if (!GetExitCodeProcess(pi.hProcess, pdwExitCode))
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync rc = GetLastError();
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"Executing command line: GetExitCodeProcess() failed! Error: %u", rc);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* Close process and thread handles. */
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync CloseHandle(pi.hProcess);
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync CloseHandle(pi.hThread);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"Executing command returned: %u (exit code %u)", rc, *pdwExitCode);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return rc;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncUINT __stdcall InstallPythonAPI(MSIHANDLE hModule)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"InstallPythonAPI: Checking for installed Python environment ...");
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync HKEY hkPythonCore = NULL;
d97357e2036109245c83ba553d0290212e28ea40vboxsync BOOL bFound = FALSE;
fba7ec2ca5a120ca53275eebdfa69425ce0e9829vboxsync LONG rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Python\\PythonCore", 0, KEY_READ, &hkPythonCore);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (rc != ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"InstallPythonAPI: Python seems not to be installed.");
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return ERROR_SUCCESS;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync WCHAR wszPath[MAX_PATH] = { 0 };
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync WCHAR wszVal[MAX_PATH] = { 0 };
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync for (int i = 0;; ++i)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync WCHAR wszRoot[MAX_PATH] = { 0 };
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync DWORD dwLen = sizeof(wszPath);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync DWORD dwKeyType = REG_SZ;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
fba7ec2ca5a120ca53275eebdfa69425ce0e9829vboxsync rc = RegEnumKeyExW(hkPythonCore, i, wszRoot, &dwLen, NULL, NULL, NULL, NULL);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (rc != ERROR_SUCCESS || dwLen <= 0)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync break;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync swprintf_s(wszPath, RT_ELEMENTS(wszPath), L"%s\\InstallPath", wszRoot);
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync dwLen = sizeof(wszVal);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync HKEY hkPythonInstPath = NULL;
fba7ec2ca5a120ca53275eebdfa69425ce0e9829vboxsync rc = RegOpenKeyExW(hkPythonCore, wszPath, 0, KEY_READ, &hkPythonInstPath);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (rc != ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync continue;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
fba7ec2ca5a120ca53275eebdfa69425ce0e9829vboxsync rc = RegQueryValueExW(hkPythonInstPath, L"", NULL, &dwKeyType, (LPBYTE)wszVal, &dwLen);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (rc == ERROR_SUCCESS)
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"InstallPythonAPI: Path \"%s\" detected.", wszVal);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync RegCloseKey(hkPythonInstPath);
1d5386c32e68116bca5e054dbef008b1f516bb25vboxsync }
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync RegCloseKey(hkPythonCore);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* Python path found? */
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync WCHAR wszExec[MAX_PATH] = { 0 };
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync WCHAR wszCmdLine[MAX_PATH] = { 0 };
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync DWORD dwExitCode = 0;
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync if (wcslen(wszVal) > 0)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* Cool, check for installed Win32 extensions. */
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"InstallPythonAPI: Python installed. Checking for Win32 extensions ...");
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync swprintf_s(wszExec, RT_ELEMENTS(wszExec), L"%s\\python.exe", wszVal);
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync swprintf_s(wszCmdLine, RT_ELEMENTS(wszCmdLine), L"%s\\python.exe -c \"import win32api\"", wszVal);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync DWORD dwRetExec = Exec(hModule, wszExec, wszCmdLine, NULL, &dwExitCode);
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync if ( (ERROR_SUCCESS == dwRetExec)
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync && ( 0 == dwExitCode))
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* Did we get the correct error level (=0)? */
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"InstallPythonAPI: Win32 extensions installed.");
d97357e2036109245c83ba553d0290212e28ea40vboxsync bFound = TRUE;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync else
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"InstallPythonAPI: Win32 extensions not found.");
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync BOOL bInstalled = FALSE;
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (bFound) /* Is Python and all required stuff installed? */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* Get the VBoxAPI setup string. */
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync WCHAR wszPathTargetDir[MAX_PATH] = {0};
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync VBoxGetProperty(hModule, L"CustomActionData", wszPathTargetDir, sizeof(wszPathTargetDir));
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync if (wcslen(wszPathTargetDir))
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync /* Set final path. */
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync swprintf_s(wszPath, RT_ELEMENTS(wszPath), L"%s\\sdk\\install", wszPathTargetDir);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync /* Install our API module. */
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync swprintf_s(wszCmdLine, RT_ELEMENTS(wszCmdLine), L"%s\\python.exe vboxapisetup.py install", wszVal);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync /* Set required environment variables. */
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync if (!SetEnvironmentVariableW(L"VBOX_INSTALL_PATH", wszPathTargetDir))
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"InstallPythonAPI: Could set environment variable VBOX_INSTALL_PATH!");
d97357e2036109245c83ba553d0290212e28ea40vboxsync else
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync DWORD dwRetExec = Exec(hModule, wszExec, wszCmdLine, wszPath, &dwExitCode);
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync if ( (ERROR_SUCCESS == dwRetExec)
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync && ( 0 == dwExitCode))
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync {
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync /* All done! */
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"InstallPythonAPI: VBoxAPI for Python successfully installed.");
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync bInstalled = TRUE;
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync }
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync else
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync {
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync if (dwRetExec)
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"InstallPythonAPI: Error while executing installation of VBox API: %ld", dwRetExec);
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync else
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"InstallPythonAPI: Python reported an error while installing VBox API: %ld", dwExitCode);
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync }
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync else
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"InstallPythonAPI: Unable to retrieve VBox installation path!");
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
056add8311718c0166b7036b31fd581858a607b3vboxsync VBoxSetProperty(hModule, L"VBOX_PYTHON_IS_INSTALLED", bInstalled ? L"1" : L"0");
d97357e2036109245c83ba553d0290212e28ea40vboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (!bInstalled)
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"InstallPythonAPI: VBox API not installed.");
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return ERROR_SUCCESS; /* Do not fail here. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsyncstatic LONG installBrandingValue(MSIHANDLE hModule,
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync const WCHAR *pwszFileName,
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync const WCHAR *pwszSection,
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync const WCHAR *pwszValue)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LONG rc;
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync WCHAR wszValue[_MAX_PATH];
fba7ec2ca5a120ca53275eebdfa69425ce0e9829vboxsync if (GetPrivateProfileStringW(pwszSection, pwszValue, NULL,
fba7ec2ca5a120ca53275eebdfa69425ce0e9829vboxsync wszValue, sizeof(wszValue), pwszFileName) > 0)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync HKEY hkBranding;
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync WCHAR wszKey[_MAX_PATH];
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync if (wcsicmp(L"General", pwszSection) != 0)
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync swprintf_s(wszKey, RT_ELEMENTS(wszKey), L"SOFTWARE\\%s\\VirtualBox\\Branding\\", VBOX_VENDOR_SHORT, pwszSection);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync swprintf_s(wszKey, RT_ELEMENTS(wszKey), L"SOFTWARE\\%s\\VirtualBox\\Branding", VBOX_VENDOR_SHORT);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
fba7ec2ca5a120ca53275eebdfa69425ce0e9829vboxsync rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wszKey, 0, KEY_WRITE, &hkBranding);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (rc == ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync rc = RegSetValueExW(hkBranding,
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync pwszValue,
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync NULL,
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync REG_SZ,
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync (BYTE *)wszValue,
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync (DWORD)wcslen(wszValue));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (rc != ERROR_SUCCESS)
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"InstallBranding: Could not write value %s! Error %ld", pwszValue, rc);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync RegCloseKey (hkBranding);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync rc = ERROR_NOT_FOUND;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return rc;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsyncUINT CopyDir(MSIHANDLE hModule, const WCHAR *pwszDestDir, const WCHAR *pwszSourceDir)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync UINT rc;
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync WCHAR wszDest[_MAX_PATH + 1];
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync WCHAR wszSource[_MAX_PATH + 1];
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync swprintf_s(wszDest, RT_ELEMENTS(wszDest), L"%s%c", pwszDestDir, '\0');
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync swprintf_s(wszSource, RT_ELEMENTS(wszSource), L"%s%c", pwszSourceDir, '\0');
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
fba7ec2ca5a120ca53275eebdfa69425ce0e9829vboxsync SHFILEOPSTRUCTW s = {0};
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync s.hwnd = NULL;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync s.wFunc = FO_COPY;
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync s.pTo = wszDest;
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync s.pFrom = wszSource;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync s.fFlags = FOF_SILENT |
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync FOF_NOCONFIRMATION |
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync FOF_NOCONFIRMMKDIR |
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync FOF_NOERRORUI;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"CopyDir: DestDir=%s, SourceDir=%s", wszDest, wszSource);
fba7ec2ca5a120ca53275eebdfa69425ce0e9829vboxsync int r = SHFileOperationW(&s);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (r != 0)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"CopyDir: Copy operation returned status 0x%x", r);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync rc = ERROR_GEN_FAILURE;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync rc = ERROR_SUCCESS;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return rc;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsyncUINT RemoveDir(MSIHANDLE hModule, const WCHAR *pwszDestDir)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync UINT rc;
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync WCHAR wszDest[_MAX_PATH + 1];
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync swprintf_s(wszDest, RT_ELEMENTS(wszDest), L"%s%c", pwszDestDir, '\0');
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync SHFILEOPSTRUCTW s = {0};
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync s.hwnd = NULL;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync s.wFunc = FO_DELETE;
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync s.pFrom = wszDest;
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync s.fFlags = FOF_SILENT
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync | FOF_NOCONFIRMATION
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync | FOF_NOCONFIRMMKDIR
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync | FOF_NOERRORUI;
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"RemoveDir: DestDir=%s", wszDest);
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync int r = SHFileOperationW(&s);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (r != 0)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"RemoveDir: Remove operation returned status 0x%x", r);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync rc = ERROR_GEN_FAILURE;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync rc = ERROR_SUCCESS;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return rc;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsyncUINT RenameDir(MSIHANDLE hModule, const WCHAR *pwszDestDir, const WCHAR *pwszSourceDir)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync UINT rc;
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync WCHAR wszDest[_MAX_PATH + 1];
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync WCHAR wszSource[_MAX_PATH + 1];
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync swprintf_s(wszDest, RT_ELEMENTS(wszDest), L"%s%c", pwszDestDir, '\0');
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync swprintf_s(wszSource, RT_ELEMENTS(wszSource), L"%s%c", pwszSourceDir, '\0');
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync SHFILEOPSTRUCTW s = {0};
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync s.hwnd = NULL;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync s.wFunc = FO_RENAME;
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync s.pTo = wszDest;
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync s.pFrom = wszSource;
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync s.fFlags = FOF_SILENT
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync | FOF_NOCONFIRMATION
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync | FOF_NOCONFIRMMKDIR
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync | FOF_NOERRORUI;
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"RenameDir: DestDir=%s, SourceDir=%s", wszDest, wszSource);
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync int r = SHFileOperationW(&s);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (r != 0)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"RenameDir: Rename operation returned status 0x%x", r);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync rc = ERROR_GEN_FAILURE;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync rc = ERROR_SUCCESS;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return rc;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncUINT __stdcall UninstallBranding(MSIHANDLE hModule)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync UINT rc;
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"UninstallBranding: Handling branding file ...");
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync WCHAR wszPathTargetDir[_MAX_PATH];
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync WCHAR wszPathDest[_MAX_PATH];
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync rc = VBoxGetProperty(hModule, L"CustomActionData", wszPathTargetDir, sizeof(wszPathTargetDir));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (rc == ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /** @todo Check trailing slash after %s. */
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync/** @todo r=bird: using swprintf_s for formatting paths without checking for
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync * overflow not good. You're dodging the buffer overflow issue only to end up
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync * with incorrect behavior! (Truncated file/dir names)
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync *
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync * This applies almost to all swprintf_s calls in this file!!
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync */
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync swprintf_s(wszPathDest, RT_ELEMENTS(wszPathDest), L"%scustom", wszPathTargetDir);
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync rc = RemoveDir(hModule, wszPathDest);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (rc != ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* Check for hidden .custom directory and remove it. */
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync swprintf_s(wszPathDest, RT_ELEMENTS(wszPathDest), L"%s.custom", wszPathTargetDir);
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync rc = RemoveDir(hModule, wszPathDest);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"UninstallBranding: Handling done. (rc=%u (ignored))", rc);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return ERROR_SUCCESS; /* Do not fail here. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncUINT __stdcall InstallBranding(MSIHANDLE hModule)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync UINT rc;
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"InstallBranding: Handling branding file ...");
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync WCHAR wszPathMSI[_MAX_PATH];
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync rc = VBoxGetProperty(hModule, L"SOURCEDIR", wszPathMSI, sizeof(wszPathMSI));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (rc == ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync WCHAR wszPathTargetDir[_MAX_PATH];
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync rc = VBoxGetProperty(hModule, L"CustomActionData", wszPathTargetDir, sizeof(wszPathTargetDir));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (rc == ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync /** @todo Check for trailing slash after %s. */
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync WCHAR wszPathDest[_MAX_PATH];
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync swprintf_s(wszPathDest, RT_ELEMENTS(wszPathDest), L"%s", wszPathTargetDir);
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync WCHAR wszPathSource[_MAX_PATH];
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync swprintf_s(wszPathSource, RT_ELEMENTS(wszPathSource), L"%s.custom", wszPathMSI);
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync rc = CopyDir(hModule, wszPathDest, wszPathSource);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (rc == ERROR_SUCCESS)
d97357e2036109245c83ba553d0290212e28ea40vboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync swprintf_s(wszPathDest, RT_ELEMENTS(wszPathDest), L"%scustom", wszPathTargetDir);
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync swprintf_s(wszPathSource, RT_ELEMENTS(wszPathSource), L"%s.custom", wszPathTargetDir);
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync rc = RenameDir(hModule, wszPathDest, wszPathSource);
d97357e2036109245c83ba553d0290212e28ea40vboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"InstallBranding: Handling done. (rc=%u (ignored))", rc);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return ERROR_SUCCESS; /* Do not fail here. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#ifdef VBOX_WITH_NETFLT
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync/** @todo should use some real VBox app name */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#define VBOX_NETCFG_APP_NAME L"VirtualBox Installer"
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#define VBOX_NETCFG_MAX_RETRIES 10
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#define NETFLT_PT_INF_REL_PATH L"drivers\\network\\netflt\\VBoxNetFlt.inf"
be6a7ee8f237a71cf075c128e8e391e6c3654687vboxsync#define NETFLT_MP_INF_REL_PATH L"drivers\\network\\netflt\\VBoxNetFltM.inf"
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#define NETFLT_ID L"sun_VBoxNetFlt" /** @todo Needs to be changed (?). */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#define NETADP_ID L"sun_VBoxNetAdp" /** @todo Needs to be changed (?). */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncstatic MSIHANDLE g_hCurrentModule = NULL;
d97357e2036109245c83ba553d0290212e28ea40vboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsyncstatic VOID netCfgLoggerCallback(LPCSTR szString)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (g_hCurrentModule)
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logString(g_hCurrentModule, szString);
d97357e2036109245c83ba553d0290212e28ea40vboxsync}
d97357e2036109245c83ba553d0290212e28ea40vboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsyncstatic VOID netCfgLoggerDisable()
d97357e2036109245c83ba553d0290212e28ea40vboxsync{
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (g_hCurrentModule)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync VBoxNetCfgWinSetLogging((LOG_ROUTINE)NULL);
d97357e2036109245c83ba553d0290212e28ea40vboxsync g_hCurrentModule = NULL;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsyncstatic VOID netCfgLoggerEnable(MSIHANDLE hModule)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
1cede4c702f5b7f8734214a2a5d5bc516b47b330vboxsync NonStandardAssert(hModule);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (g_hCurrentModule)
d97357e2036109245c83ba553d0290212e28ea40vboxsync netCfgLoggerDisable();
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync g_hCurrentModule = hModule;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync VBoxNetCfgWinSetLogging((LOG_ROUTINE)netCfgLoggerCallback);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsyncstatic UINT errorConvertFromHResult(MSIHANDLE hModule, HRESULT hr)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
d97357e2036109245c83ba553d0290212e28ea40vboxsync UINT uRet;
d97357e2036109245c83ba553d0290212e28ea40vboxsync switch (hr)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync case S_OK:
d97357e2036109245c83ba553d0290212e28ea40vboxsync uRet = ERROR_SUCCESS;
d97357e2036109245c83ba553d0290212e28ea40vboxsync break;
d97357e2036109245c83ba553d0290212e28ea40vboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync case NETCFG_S_REBOOT:
d97357e2036109245c83ba553d0290212e28ea40vboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"Reboot required, setting REBOOT property to Force");
fba7ec2ca5a120ca53275eebdfa69425ce0e9829vboxsync HRESULT hr2 = MsiSetPropertyW(hModule, L"REBOOT", L"Force");
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (hr2 != ERROR_SUCCESS)
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"Failed to set REBOOT property, error = 0x%x", hr2);
d97357e2036109245c83ba553d0290212e28ea40vboxsync uRet = ERROR_SUCCESS; /* Never fail here. */
d97357e2036109245c83ba553d0290212e28ea40vboxsync break;
d97357e2036109245c83ba553d0290212e28ea40vboxsync }
d97357e2036109245c83ba553d0290212e28ea40vboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync default:
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"Converting unhandled HRESULT (0x%x) to ERROR_GEN_FAILURE", hr);
d97357e2036109245c83ba553d0290212e28ea40vboxsync uRet = ERROR_GEN_FAILURE;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
d97357e2036109245c83ba553d0290212e28ea40vboxsync return uRet;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncstatic MSIHANDLE createNetCfgLockedMsgRecord(MSIHANDLE hModule)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync MSIHANDLE hRecord = MsiCreateRecord(2);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (hRecord)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync UINT uErr = MsiRecordSetInteger(hRecord, 1, 25001);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (uErr != ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"createNetCfgLockedMsgRecord: MsiRecordSetInteger failed, error = 0x%x", uErr);
d97357e2036109245c83ba553d0290212e28ea40vboxsync MsiCloseHandle(hRecord);
d97357e2036109245c83ba553d0290212e28ea40vboxsync hRecord = NULL;
d97357e2036109245c83ba553d0290212e28ea40vboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"createNetCfgLockedMsgRecord: Failed to create a record");
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return hRecord;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncstatic UINT doNetCfgInit(MSIHANDLE hModule, INetCfg **ppnc, BOOL bWrite)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync MSIHANDLE hMsg = NULL;
d97357e2036109245c83ba553d0290212e28ea40vboxsync UINT uErr = ERROR_GEN_FAILURE;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync int MsgResult;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync int cRetries = 0;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync do
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LPWSTR lpszLockedBy;
be6a7ee8f237a71cf075c128e8e391e6c3654687vboxsync HRESULT hr = VBoxNetCfgWinQueryINetCfg(ppnc, bWrite, VBOX_NETCFG_APP_NAME, 10000, &lpszLockedBy);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (hr != NETCFG_E_NO_WRITE_LOCK)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (FAILED(hr))
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"doNetCfgInit: VBoxNetCfgWinQueryINetCfg failed, error = 0x%x", hr);
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync uErr = errorConvertFromHResult(hModule, hr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync break;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* hr == NETCFG_E_NO_WRITE_LOCK */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (!lpszLockedBy)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"doNetCfgInit: lpszLockedBy == NULL, breaking");
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync break;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* on vista the 6to4svc.dll periodically maintains the lock for some reason,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * if this is the case, increase the wait period by retrying multiple times
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * NOTE: we could alternatively increase the wait timeout,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * however it seems unneeded for most cases, e.g. in case some network connection property
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * dialog is opened, it would be better to post a notification to the user as soon as possible
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * rather than waiting for a longer period of time before displaying it */
d97357e2036109245c83ba553d0290212e28ea40vboxsync if ( cRetries < VBOX_NETCFG_MAX_RETRIES
d97357e2036109245c83ba553d0290212e28ea40vboxsync && !wcscmp(lpszLockedBy, L"6to4svc.dll"))
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync cRetries++;
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"doNetCfgInit: lpszLockedBy is 6to4svc.dll, retrying %d out of %d", cRetries, VBOX_NETCFG_MAX_RETRIES);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync MsgResult = IDRETRY;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (!hMsg)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync hMsg = createNetCfgLockedMsgRecord(hModule);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (!hMsg)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"doNetCfgInit: Failed to create a message record, breaking");
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync CoTaskMemFree(lpszLockedBy);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync break;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync UINT rTmp = MsiRecordSetStringW(hMsg, 2, lpszLockedBy);
1cede4c702f5b7f8734214a2a5d5bc516b47b330vboxsync NonStandardAssert(rTmp == ERROR_SUCCESS);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (rTmp != ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"doNetCfgInit: MsiRecordSetStringW failed, error = 0x%x", rTmp);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync CoTaskMemFree(lpszLockedBy);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync break;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync MsgResult = MsiProcessMessage(hModule, (INSTALLMESSAGE)(INSTALLMESSAGE_USER | MB_RETRYCANCEL), hMsg);
1cede4c702f5b7f8734214a2a5d5bc516b47b330vboxsync NonStandardAssert(MsgResult == IDRETRY || MsgResult == IDCANCEL);
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"doNetCfgInit: MsiProcessMessage returned (0x%x)", MsgResult);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync CoTaskMemFree(lpszLockedBy);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync } while(MsgResult == IDRETRY);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (hMsg)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync MsiCloseHandle(hMsg);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync return uErr;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsyncstatic UINT vboxNetFltQueryInfArray(MSIHANDLE hModule, OUT LPWSTR pwszPtInf, OUT LPWSTR pwszMpInf, DWORD dwSize)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync DWORD dwBuf = dwSize - RT_MAX(sizeof(NETFLT_PT_INF_REL_PATH), sizeof(NETFLT_MP_INF_REL_PATH));
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync UINT uErr = MsiGetPropertyW(hModule, L"CustomActionData", pwszPtInf, &dwBuf);
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync if ( uErr == ERROR_SUCCESS
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync && dwBuf)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync wcscpy(pwszMpInf, pwszPtInf);
d97357e2036109245c83ba553d0290212e28ea40vboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync wcsncat(pwszPtInf, NETFLT_PT_INF_REL_PATH, sizeof(NETFLT_PT_INF_REL_PATH));
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"vboxNetFltQueryInfArray: INF 1: %s", pwszPtInf);
d97357e2036109245c83ba553d0290212e28ea40vboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync wcsncat(pwszMpInf, NETFLT_MP_INF_REL_PATH, sizeof(NETFLT_MP_INF_REL_PATH));
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"vboxNetFltQueryInfArray: INF 2: %s", pwszMpInf);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync else if (uErr != ERROR_SUCCESS)
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"vboxNetFltQueryInfArray: MsiGetPropertyW failed, error = 0x%x", uErr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"vboxNetFltQueryInfArray: Empty installation directory");
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync uErr = ERROR_GEN_FAILURE;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync return uErr;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#endif /*VBOX_WITH_NETFLT*/
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncUINT __stdcall UninstallNetFlt(MSIHANDLE hModule)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#ifdef VBOX_WITH_NETFLT
d97357e2036109245c83ba553d0290212e28ea40vboxsync INetCfg *pNetCfg;
d97357e2036109245c83ba553d0290212e28ea40vboxsync UINT uErr;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync netCfgLoggerEnable(hModule);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync BOOL bOldIntMode = SetupSetNonInteractiveMode(FALSE);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync __try
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"Uninstalling NetFlt");
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync uErr = doNetCfgInit(hModule, &pNetCfg, TRUE);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (uErr == ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync HRESULT hr = VBoxNetCfgWinNetFltUninstall(pNetCfg);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (hr != S_OK)
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"UninstallNetFlt: VBoxNetCfgWinUninstallComponent failed, error = 0x%x", hr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync uErr = errorConvertFromHResult(hModule, hr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"Uninstalling NetFlt done, error = 0x%x", uErr);
d97357e2036109245c83ba553d0290212e28ea40vboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync /* Never fail on uninstall. */
d97357e2036109245c83ba553d0290212e28ea40vboxsync uErr = ERROR_SUCCESS;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"UninstallNetFlt: doNetCfgInit failed, error = 0x%x", uErr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync __finally
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (bOldIntMode)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync /* The prev mode != FALSE, i.e. non-interactive. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync SetupSetNonInteractiveMode(bOldIntMode);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
d97357e2036109245c83ba553d0290212e28ea40vboxsync netCfgLoggerDisable();
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
d97357e2036109245c83ba553d0290212e28ea40vboxsync#endif /* VBOX_WITH_NETFLT */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync /* Never fail the install even if we did not succeed. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return ERROR_SUCCESS;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncUINT __stdcall InstallNetFlt(MSIHANDLE hModule)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#ifdef VBOX_WITH_NETFLT
d97357e2036109245c83ba553d0290212e28ea40vboxsync UINT uErr;
d97357e2036109245c83ba553d0290212e28ea40vboxsync INetCfg *pNetCfg;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync netCfgLoggerEnable(hModule);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync BOOL bOldIntMode = SetupSetNonInteractiveMode(FALSE);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync __try
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync logStringW(hModule, L"InstallNetFlt: Installing NetFlt");
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync uErr = doNetCfgInit(hModule, &pNetCfg, TRUE);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (uErr == ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync WCHAR wszPtInf[MAX_PATH];
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync WCHAR wszMpInf[MAX_PATH];
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync uErr = vboxNetFltQueryInfArray(hModule, wszPtInf, wszMpInf, sizeof(wszMpInf));
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (uErr == ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync LPCWSTR const apwszInfs[] = { wszPtInf, wszMpInf };
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync HRESULT hr = VBoxNetCfgWinNetFltInstall(pNetCfg, &apwszInfs[0], RT_ELEMENTS(apwszInfs));
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (FAILED(hr))
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"InstallNetFlt: VBoxNetCfgWinNetFltInstall failed, error = 0x%x", hr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync uErr = errorConvertFromHResult(hModule, hr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"InstallNetFlt: vboxNetFltQueryInfArray failed, error = 0x%x", uErr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync logStringW(hModule, L"InstallNetFlt: Done");
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"InstallNetFlt: doNetCfgInit failed, error = 0x%x", uErr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync __finally
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (bOldIntMode)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync /* The prev mode != FALSE, i.e. non-interactive. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync SetupSetNonInteractiveMode(bOldIntMode);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
d97357e2036109245c83ba553d0290212e28ea40vboxsync netCfgLoggerDisable();
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
d97357e2036109245c83ba553d0290212e28ea40vboxsync#endif /* VBOX_WITH_NETFLT */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync /* Never fail the install even if we did not succeed. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return ERROR_SUCCESS;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#if 0
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncstatic BOOL RenameHostOnlyConnectionsCallback(HDEVINFO hDevInfo, PSP_DEVINFO_DATA pDev, PVOID pContext)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync WCHAR DevName[256];
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync DWORD winEr;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (SetupDiGetDeviceRegistryPropertyW(hDevInfo, pDev,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync SPDRP_FRIENDLYNAME , /* IN DWORD Property,*/
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync NULL, /*OUT PDWORD PropertyRegDataType, OPTIONAL*/
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync (PBYTE)DevName, /*OUT PBYTE PropertyBuffer,*/
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync sizeof(DevName), /* IN DWORD PropertyBufferSize,*/
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync NULL /*OUT PDWORD RequiredSize OPTIONAL*/
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync ))
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync HKEY hKey = SetupDiOpenDevRegKey(hDevInfo, pDev,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync DICS_FLAG_GLOBAL, /* IN DWORD Scope,*/
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync 0, /*IN DWORD HwProfile, */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync DIREG_DRV, /* IN DWORD KeyType, */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync KEY_READ /*IN REGSAM samDesired*/
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync );
1cede4c702f5b7f8734214a2a5d5bc516b47b330vboxsync NonStandardAssert(hKey != INVALID_HANDLE_VALUE);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (hKey != INVALID_HANDLE_VALUE)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync WCHAR guid[50];
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync DWORD cbGuid=sizeof(guid);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync winEr = RegQueryValueExW(hKey,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync L"NetCfgInstanceId", /*__in_opt LPCTSTR lpValueName,*/
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync NULL, /*__reserved LPDWORD lpReserved,*/
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync NULL, /*__out_opt LPDWORD lpType,*/
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync (LPBYTE)guid, /*__out_opt LPBYTE lpData,*/
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync &cbGuid /*guid__inout_opt LPDWORD lpcbData*/
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync );
1cede4c702f5b7f8734214a2a5d5bc516b47b330vboxsync NonStandardAssert(winEr == ERROR_SUCCESS);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (winEr == ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync WCHAR ConnectoinName[128];
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync ULONG cbName = sizeof(ConnectoinName);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync HRESULT hr = VBoxNetCfgWinGenHostonlyConnectionName (DevName, ConnectoinName, &cbName);
1cede4c702f5b7f8734214a2a5d5bc516b47b330vboxsync NonStandardAssert(hr == S_OK);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (SUCCEEDED(hr))
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync hr = VBoxNetCfgWinRenameConnection(guid, ConnectoinName);
1cede4c702f5b7f8734214a2a5d5bc516b47b330vboxsync NonStandardAssert(hr == S_OK);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync RegCloseKey(hKey);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
1cede4c702f5b7f8734214a2a5d5bc516b47b330vboxsync NonStandardAssert(0);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return TRUE;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#endif
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncUINT __stdcall CreateHostOnlyInterface(MSIHANDLE hModule)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#ifdef VBOX_WITH_NETFLT
d97357e2036109245c83ba553d0290212e28ea40vboxsync netCfgLoggerEnable(hModule);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync BOOL bSetupModeInteractive = SetupSetNonInteractiveMode(FALSE);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync bool bSetStaticIp = true;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync logStringW(hModule, L"CreateHostOnlyInterface: Creating host-only interface");
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync HRESULT hr = VBoxNetCfgWinRemoveAllNetDevicesOfId(NETADP_ID);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (FAILED(hr))
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinRemoveAllNetDevicesOfId failed, error = 0x%x", hr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync bSetStaticIp = false;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync GUID guid;
0824e642d6a2ba2cde6077003d9c99b0197eab34vboxsync WCHAR wszMpInf[MAX_PATH];
0824e642d6a2ba2cde6077003d9c99b0197eab34vboxsync DWORD cchMpInf = RT_ELEMENTS(wszMpInf) - sizeof("drivers\\network\\netadp\\VBoxNetAdp.inf") - 1;
0824e642d6a2ba2cde6077003d9c99b0197eab34vboxsync LPCWSTR pwszInfPath = NULL;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync bool bIsFile = false;
0824e642d6a2ba2cde6077003d9c99b0197eab34vboxsync UINT uErr = MsiGetPropertyW(hModule, L"CustomActionData", wszMpInf, &cchMpInf);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (uErr == ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
0824e642d6a2ba2cde6077003d9c99b0197eab34vboxsync if (cchMpInf)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
0824e642d6a2ba2cde6077003d9c99b0197eab34vboxsync logStringW(hModule, L"CreateHostOnlyInterface: NetAdpDir property = %s", wszMpInf);
0824e642d6a2ba2cde6077003d9c99b0197eab34vboxsync if (wszMpInf[cchMpInf - 1] != L'\\')
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
0824e642d6a2ba2cde6077003d9c99b0197eab34vboxsync wszMpInf[cchMpInf++] = L'\\';
0824e642d6a2ba2cde6077003d9c99b0197eab34vboxsync wszMpInf[cchMpInf] = L'\0';
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
d97357e2036109245c83ba553d0290212e28ea40vboxsync
0824e642d6a2ba2cde6077003d9c99b0197eab34vboxsync wcscat(wszMpInf, L"drivers\\network\\netadp\\VBoxNetAdp.inf");
0824e642d6a2ba2cde6077003d9c99b0197eab34vboxsync pwszInfPath = wszMpInf;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync bIsFile = true;
d97357e2036109245c83ba553d0290212e28ea40vboxsync
0824e642d6a2ba2cde6077003d9c99b0197eab34vboxsync logStringW(hModule, L"CreateHostOnlyInterface: Resulting INF path = %s", pwszInfPath);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"CreateHostOnlyInterface: NetAdpDir property value is empty");
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"CreateHostOnlyInterface: Failed to get NetAdpDir property, error = 0x%x", uErr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync /* Make sure the inf file is installed. */
0824e642d6a2ba2cde6077003d9c99b0197eab34vboxsync if (pwszInfPath != NULL && bIsFile)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync logStringW(hModule, L"CreateHostOnlyInterface: Calling VBoxDrvCfgInfInstall(%s)", pwszInfPath);
0824e642d6a2ba2cde6077003d9c99b0197eab34vboxsync hr = VBoxDrvCfgInfInstall(pwszInfPath);
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync logStringW(hModule, L"CreateHostOnlyInterface: VBoxDrvCfgInfInstall returns 0x%x", hr);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (FAILED(hr))
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"CreateHostOnlyInterface: Failed to install INF file, error = 0x%x", hr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (SUCCEEDED(hr))
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync logStringW(hModule, L"CreateHostOnlyInterface: calling VBoxNetCfgWinCreateHostOnlyNetworkInterface");
0824e642d6a2ba2cde6077003d9c99b0197eab34vboxsync hr = VBoxNetCfgWinCreateHostOnlyNetworkInterface(pwszInfPath, bIsFile, &guid, NULL, NULL);
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync logStringW(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinCreateHostOnlyNetworkInterface returns 0x%x", hr);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (SUCCEEDED(hr))
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync ULONG ip = inet_addr("192.168.56.1");
d97357e2036109245c83ba553d0290212e28ea40vboxsync ULONG mask = inet_addr("255.255.255.0");
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync logStringW(hModule, L"CreateHostOnlyInterface: calling VBoxNetCfgWinEnableStaticIpConfig");
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = VBoxNetCfgWinEnableStaticIpConfig(&guid, ip, mask);
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync logStringW(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinEnableStaticIpConfig returns 0x%x", hr);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (FAILED(hr))
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinEnableStaticIpConfig failed, error = 0x%x", hr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
d97357e2036109245c83ba553d0290212e28ea40vboxsync else
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinCreateHostOnlyNetworkInterface failed, error = 0x%x", hr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (SUCCEEDED(hr))
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync logStringW(hModule, L"CreateHostOnlyInterface: Creating host-only interface done");
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync /* Restore original setup mode. */
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync logStringW(hModule, L"CreateHostOnlyInterface: Almost done...");
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (bSetupModeInteractive)
d97357e2036109245c83ba553d0290212e28ea40vboxsync SetupSetNonInteractiveMode(bSetupModeInteractive);
d97357e2036109245c83ba553d0290212e28ea40vboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync netCfgLoggerDisable();
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#endif /* VBOX_WITH_NETFLT */
d97357e2036109245c83ba553d0290212e28ea40vboxsync
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync logStringW(hModule, L"CreateHostOnlyInterface: Returns success (ignoring all failures)");
d97357e2036109245c83ba553d0290212e28ea40vboxsync /* Never fail the install even if we did not succeed. */
d97357e2036109245c83ba553d0290212e28ea40vboxsync return ERROR_SUCCESS;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncUINT __stdcall RemoveHostOnlyInterfaces(MSIHANDLE hModule)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#ifdef VBOX_WITH_NETFLT
d97357e2036109245c83ba553d0290212e28ea40vboxsync netCfgLoggerEnable(hModule);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync logStringW(hModule, L"RemoveHostOnlyInterfaces: Removing all host-only interfaces");
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync BOOL bSetupModeInteractive = SetupSetNonInteractiveMode(FALSE);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync HRESULT hr = VBoxNetCfgWinRemoveAllNetDevicesOfId(NETADP_ID);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (SUCCEEDED(hr))
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
2fa05a4e777b070ba9bf01e3dd46434c99cd06a3vboxsync hr = VBoxDrvCfgInfUninstallAllSetupDi(&GUID_DEVCLASS_NET, NETADP_ID, L"Net", 0/* could be SUOI_FORCEDELETE */);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (FAILED(hr))
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
950867fcd91ff725bbcc44623ae3d8888ed32da2vboxsync logStringW(hModule, L"RemoveHostOnlyInterfaces: NetAdp uninstalled successfully, but failed to remove infs");
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
950867fcd91ff725bbcc44623ae3d8888ed32da2vboxsync logStringW(hModule, L"RemoveHostOnlyInterfaces: NetAdp uninstall failed, hr = 0x%x", hr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync /* Restore original setup mode. */
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (bSetupModeInteractive)
d97357e2036109245c83ba553d0290212e28ea40vboxsync SetupSetNonInteractiveMode(bSetupModeInteractive);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync netCfgLoggerDisable();
d97357e2036109245c83ba553d0290212e28ea40vboxsync#endif /* VBOX_WITH_NETFLT */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync /* Never fail the install even if we did not succeed. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return ERROR_SUCCESS;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsyncUINT __stdcall StopHostOnlyInterfaces(MSIHANDLE hModule)
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync{
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync#ifdef VBOX_WITH_NETFLT
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync netCfgLoggerEnable(hModule);
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync
950867fcd91ff725bbcc44623ae3d8888ed32da2vboxsync logStringW(hModule, L"StopHostOnlyInterfaces: Stopping all host-only interfaces");
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync
c42011aa94dc0c1fdd2acefda7a48c5c8cd23d10vboxsync BOOL bSetupModeInteractive = SetupSetNonInteractiveMode(FALSE);
c42011aa94dc0c1fdd2acefda7a48c5c8cd23d10vboxsync
c42011aa94dc0c1fdd2acefda7a48c5c8cd23d10vboxsync HRESULT hr = VBoxNetCfgWinPropChangeAllNetDevicesOfId(NETADP_ID, VBOXNECTFGWINPROPCHANGE_TYPE_DISABLE);
c42011aa94dc0c1fdd2acefda7a48c5c8cd23d10vboxsync if (SUCCEEDED(hr))
c42011aa94dc0c1fdd2acefda7a48c5c8cd23d10vboxsync {
c42011aa94dc0c1fdd2acefda7a48c5c8cd23d10vboxsync hr = VBoxDrvCfgInfUninstallAllSetupDi(&GUID_DEVCLASS_NET, NETADP_ID, L"Net", 0/* could be SUOI_FORCEDELETE */);
c42011aa94dc0c1fdd2acefda7a48c5c8cd23d10vboxsync if (FAILED(hr))
950867fcd91ff725bbcc44623ae3d8888ed32da2vboxsync logStringW(hModule, L"StopHostOnlyInterfaces: VBoxDrvCfgInfUninstallAllSetupDi failed, hr = 0x%x", hr);
c42011aa94dc0c1fdd2acefda7a48c5c8cd23d10vboxsync }
c42011aa94dc0c1fdd2acefda7a48c5c8cd23d10vboxsync else
950867fcd91ff725bbcc44623ae3d8888ed32da2vboxsync logStringW(hModule, L"StopHostOnlyInterfaces: Disabling host interfaces failed, hr = 0x%x", hr);
c42011aa94dc0c1fdd2acefda7a48c5c8cd23d10vboxsync
c42011aa94dc0c1fdd2acefda7a48c5c8cd23d10vboxsync /* Restore original setup mode. */
c42011aa94dc0c1fdd2acefda7a48c5c8cd23d10vboxsync if (bSetupModeInteractive)
c42011aa94dc0c1fdd2acefda7a48c5c8cd23d10vboxsync SetupSetNonInteractiveMode(bSetupModeInteractive);
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync netCfgLoggerDisable();
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync#endif /* VBOX_WITH_NETFLT */
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync /* Never fail the install even if we did not succeed. */
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync return ERROR_SUCCESS;
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync}
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsyncUINT __stdcall UpdateHostOnlyInterfaces(MSIHANDLE hModule)
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync{
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync#ifdef VBOX_WITH_NETFLT
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync netCfgLoggerEnable(hModule);
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync
950867fcd91ff725bbcc44623ae3d8888ed32da2vboxsync logStringW(hModule, L"UpdateHostOnlyInterfaces: Updating all host-only interfaces");
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync
c42011aa94dc0c1fdd2acefda7a48c5c8cd23d10vboxsync BOOL bSetupModeInteractive = SetupSetNonInteractiveMode(FALSE);
c42011aa94dc0c1fdd2acefda7a48c5c8cd23d10vboxsync
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync WCHAR wszMpInf[MAX_PATH];
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync DWORD cchMpInf = RT_ELEMENTS(wszMpInf) - sizeof("drivers\\network\\netadp\\VBoxNetAdp.inf") - 1;
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync LPCWSTR pwszInfPath = NULL;
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync bool bIsFile = false;
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync UINT uErr = MsiGetPropertyW(hModule, L"CustomActionData", wszMpInf, &cchMpInf);
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync if (uErr == ERROR_SUCCESS)
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync {
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync if (cchMpInf)
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync {
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync logStringW(hModule, L"UpdateHostOnlyInterfaces: NetAdpDir property = %s", wszMpInf);
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync if (wszMpInf[cchMpInf - 1] != L'\\')
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync {
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync wszMpInf[cchMpInf++] = L'\\';
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync wszMpInf[cchMpInf] = L'\0';
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync }
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync wcscat(wszMpInf, L"drivers\\network\\netadp\\VBoxNetAdp.inf");
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync pwszInfPath = wszMpInf;
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync bIsFile = true;
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync logStringW(hModule, L"UpdateHostOnlyInterfaces: Resulting INF path = %s", pwszInfPath);
c42011aa94dc0c1fdd2acefda7a48c5c8cd23d10vboxsync
950867fcd91ff725bbcc44623ae3d8888ed32da2vboxsync DWORD attrFile = GetFileAttributesW(pwszInfPath);
950867fcd91ff725bbcc44623ae3d8888ed32da2vboxsync if (attrFile == INVALID_FILE_ATTRIBUTES)
950867fcd91ff725bbcc44623ae3d8888ed32da2vboxsync {
950867fcd91ff725bbcc44623ae3d8888ed32da2vboxsync DWORD dwErr = GetLastError();
950867fcd91ff725bbcc44623ae3d8888ed32da2vboxsync logStringW(hModule, L"UpdateHostOnlyInterfaces: File \"%s\" not found, dwErr=%ld",
950867fcd91ff725bbcc44623ae3d8888ed32da2vboxsync pwszInfPath, dwErr);
950867fcd91ff725bbcc44623ae3d8888ed32da2vboxsync }
950867fcd91ff725bbcc44623ae3d8888ed32da2vboxsync else
c42011aa94dc0c1fdd2acefda7a48c5c8cd23d10vboxsync {
950867fcd91ff725bbcc44623ae3d8888ed32da2vboxsync logStringW(hModule, L"UpdateHostOnlyInterfaces: File \"%s\" exists",
950867fcd91ff725bbcc44623ae3d8888ed32da2vboxsync pwszInfPath);
950867fcd91ff725bbcc44623ae3d8888ed32da2vboxsync
950867fcd91ff725bbcc44623ae3d8888ed32da2vboxsync BOOL fRebootRequired = FALSE;
950867fcd91ff725bbcc44623ae3d8888ed32da2vboxsync HRESULT hr = VBoxNetCfgWinUpdateHostOnlyNetworkInterface(pwszInfPath, &fRebootRequired);
950867fcd91ff725bbcc44623ae3d8888ed32da2vboxsync if (SUCCEEDED(hr))
c42011aa94dc0c1fdd2acefda7a48c5c8cd23d10vboxsync {
950867fcd91ff725bbcc44623ae3d8888ed32da2vboxsync if (fRebootRequired)
950867fcd91ff725bbcc44623ae3d8888ed32da2vboxsync {
950867fcd91ff725bbcc44623ae3d8888ed32da2vboxsync logStringW(hModule, L"UpdateHostOnlyInterfaces: Reboot required, setting REBOOT property to force");
950867fcd91ff725bbcc44623ae3d8888ed32da2vboxsync HRESULT hr2 = MsiSetPropertyW(hModule, L"REBOOT", L"Force");
950867fcd91ff725bbcc44623ae3d8888ed32da2vboxsync if (hr2 != ERROR_SUCCESS)
950867fcd91ff725bbcc44623ae3d8888ed32da2vboxsync logStringW(hModule, L"UpdateHostOnlyInterfaces: Failed to set REBOOT property, error = 0x%x", hr2);
950867fcd91ff725bbcc44623ae3d8888ed32da2vboxsync }
c42011aa94dc0c1fdd2acefda7a48c5c8cd23d10vboxsync }
950867fcd91ff725bbcc44623ae3d8888ed32da2vboxsync else
950867fcd91ff725bbcc44623ae3d8888ed32da2vboxsync logStringW(hModule, L"UpdateHostOnlyInterfaces: VBoxNetCfgWinUpdateHostOnlyNetworkInterface failed, hr = 0x%x", hr);
c42011aa94dc0c1fdd2acefda7a48c5c8cd23d10vboxsync }
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync }
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync else
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync logStringW(hModule, L"UpdateHostOnlyInterfaces: NetAdpDir property value is empty");
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync }
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync else
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync logStringW(hModule, L"UpdateHostOnlyInterfaces: Failed to get NetAdpDir property, error = 0x%x", uErr);
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync
c42011aa94dc0c1fdd2acefda7a48c5c8cd23d10vboxsync /* Restore original setup mode. */
c42011aa94dc0c1fdd2acefda7a48c5c8cd23d10vboxsync if (bSetupModeInteractive)
c42011aa94dc0c1fdd2acefda7a48c5c8cd23d10vboxsync SetupSetNonInteractiveMode(bSetupModeInteractive);
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync netCfgLoggerDisable();
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync#endif /* VBOX_WITH_NETFLT */
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync /* Never fail the install even if we did not succeed. */
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync return ERROR_SUCCESS;
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync}
46c75ae905ff2f34982b5b2b9aafdf3b32644eb0vboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsyncstatic bool isTAPDevice(const WCHAR *pwszGUID)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync HKEY hNetcard;
d97357e2036109245c83ba553d0290212e28ea40vboxsync bool bIsTapDevice = false;
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync LONG lStatus = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync L"SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}",
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync 0, KEY_READ, &hNetcard);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (lStatus != ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return false;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync int i = 0;
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync for (;;)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync WCHAR wszEnumName[256];
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync WCHAR wszNetCfgInstanceId[256];
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync DWORD dwKeyType;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync HKEY hNetCardGUID;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync DWORD dwLen = sizeof(wszEnumName);
fba7ec2ca5a120ca53275eebdfa69425ce0e9829vboxsync lStatus = RegEnumKeyExW(hNetcard, i, wszEnumName, &dwLen, NULL, NULL, NULL, NULL);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (lStatus != ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync break;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
fba7ec2ca5a120ca53275eebdfa69425ce0e9829vboxsync lStatus = RegOpenKeyExW(hNetcard, wszEnumName, 0, KEY_READ, &hNetCardGUID);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (lStatus == ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync dwLen = sizeof(wszNetCfgInstanceId);
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync lStatus = RegQueryValueExW(hNetCardGUID, L"NetCfgInstanceId", NULL, &dwKeyType, (LPBYTE)wszNetCfgInstanceId, &dwLen);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if ( lStatus == ERROR_SUCCESS
d97357e2036109245c83ba553d0290212e28ea40vboxsync && dwKeyType == REG_SZ)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync WCHAR wszNetProductName[256];
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync WCHAR wszNetProviderName[256];
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync wszNetProductName[0] = 0;
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync dwLen = sizeof(wszNetProductName);
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync lStatus = RegQueryValueExW(hNetCardGUID, L"ProductName", NULL, &dwKeyType, (LPBYTE)wszNetProductName, &dwLen);
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync wszNetProviderName[0] = 0;
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync dwLen = sizeof(wszNetProviderName);
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync lStatus = RegQueryValueExW(hNetCardGUID, L"ProviderName", NULL, &dwKeyType, (LPBYTE)wszNetProviderName, &dwLen);
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync if ( !wcscmp(wszNetCfgInstanceId, pwszGUID)
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync && !wcscmp(wszNetProductName, L"VirtualBox TAP Adapter")
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync && ( (!wcscmp(wszNetProviderName, L"innotek GmbH")) /* Legacy stuff. */
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync || (!wcscmp(wszNetProviderName, L"Sun Microsystems, Inc.")) /* Legacy stuff. */
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync || (!wcscmp(wszNetProviderName, MY_WTEXT(VBOX_VENDOR))) /* Reflects current vendor string. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync )
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync )
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync bIsTapDevice = true;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync RegCloseKey(hNetCardGUID);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync break;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync RegCloseKey(hNetCardGUID);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync ++i;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync RegCloseKey(hNetcard);
d97357e2036109245c83ba553d0290212e28ea40vboxsync return bIsTapDevice;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#define SetErrBreak(strAndArgs) \
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (1) { \
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync rc = 0; \
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, strAndArgs); \
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync break; \
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync } else do {} while (0)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsyncint removeNetworkInterface(MSIHANDLE hModule, const WCHAR *pwszGUID)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync int rc = 1;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync do
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync WCHAR wszPnPInstanceId[512] = {0};
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* We have to find the device instance ID through a registry search */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync HKEY hkeyNetwork = 0;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync HKEY hkeyConnection = 0;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync do /* break-loop */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync WCHAR wszRegLocation[256];
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync swprintf(wszRegLocation,
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s",
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync pwszGUID);
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync LONG lStatus = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wszRegLocation, 0, KEY_READ, &hkeyNetwork);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if ((lStatus != ERROR_SUCCESS) || !hkeyNetwork)
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync SetErrBreak((L"VBox HostInterfaces: Host interface network was not found in registry (%s)! [1]", wszRegLocation));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync lStatus = RegOpenKeyExW(hkeyNetwork, L"Connection", 0, KEY_READ, &hkeyConnection);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if ((lStatus != ERROR_SUCCESS) || !hkeyConnection)
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync SetErrBreak((L"VBox HostInterfaces: Host interface network was not found in registry (%s)! [2]", wszRegLocation));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync DWORD len = sizeof(wszPnPInstanceId);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync DWORD dwKeyType;
d97357e2036109245c83ba553d0290212e28ea40vboxsync lStatus = RegQueryValueExW(hkeyConnection, L"PnPInstanceID", NULL,
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync &dwKeyType, (LPBYTE)&wszPnPInstanceId[0], &len);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if ((lStatus != ERROR_SUCCESS) || (dwKeyType != REG_SZ))
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync SetErrBreak((L"VBox HostInterfaces: Host interface network was not found in registry (%s)! [3]", wszRegLocation));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync while (0);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (hkeyConnection)
d97357e2036109245c83ba553d0290212e28ea40vboxsync RegCloseKey(hkeyConnection);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (hkeyNetwork)
d97357e2036109245c83ba553d0290212e28ea40vboxsync RegCloseKey(hkeyNetwork);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /*
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * Now we are going to enumerate all network devices and
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * wait until we encounter the right device instance ID
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync HDEVINFO hDeviceInfo = INVALID_HANDLE_VALUE;
d97357e2036109245c83ba553d0290212e28ea40vboxsync BOOL fResult;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync do
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync DWORD ret = 0;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync GUID netGuid;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync SP_DEVINFO_DATA DeviceInfoData;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync DWORD index = 0;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync DWORD size = 0;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* initialize the structure size */
d97357e2036109245c83ba553d0290212e28ea40vboxsync DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* copy the net class GUID */
d97357e2036109245c83ba553d0290212e28ea40vboxsync memcpy(&netGuid, &GUID_DEVCLASS_NET, sizeof (GUID_DEVCLASS_NET));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* return a device info set contains all installed devices of the Net class */
d97357e2036109245c83ba553d0290212e28ea40vboxsync hDeviceInfo = SetupDiGetClassDevs(&netGuid, NULL, NULL, DIGCF_PRESENT);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (hDeviceInfo == INVALID_HANDLE_VALUE)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"VBox HostInterfaces: SetupDiGetClassDevs failed (0x%08X)!", GetLastError());
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync SetErrBreak(L"VBox HostInterfaces: Uninstallation failed!");
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync BOOL fFoundDevice = FALSE;
d97357e2036109245c83ba553d0290212e28ea40vboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* enumerate the driver info list */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync while (TRUE)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync WCHAR *pwszDeviceHwid;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiEnumDeviceInfo(hDeviceInfo, index, &DeviceInfoData);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (!fResult)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (GetLastError() == ERROR_NO_MORE_ITEMS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync break;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync index++;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync continue;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* try to get the hardware ID registry property */
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiGetDeviceRegistryProperty(hDeviceInfo,
d97357e2036109245c83ba553d0290212e28ea40vboxsync &DeviceInfoData,
d97357e2036109245c83ba553d0290212e28ea40vboxsync SPDRP_HARDWAREID,
d97357e2036109245c83ba553d0290212e28ea40vboxsync NULL,
d97357e2036109245c83ba553d0290212e28ea40vboxsync NULL,
d97357e2036109245c83ba553d0290212e28ea40vboxsync 0,
d97357e2036109245c83ba553d0290212e28ea40vboxsync &size);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (!fResult)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync index++;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync continue;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync pwszDeviceHwid = (WCHAR *)malloc(size);
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync if (pwszDeviceHwid)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiGetDeviceRegistryProperty(hDeviceInfo,
d97357e2036109245c83ba553d0290212e28ea40vboxsync &DeviceInfoData,
d97357e2036109245c83ba553d0290212e28ea40vboxsync SPDRP_HARDWAREID,
d97357e2036109245c83ba553d0290212e28ea40vboxsync NULL,
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync (PBYTE)pwszDeviceHwid,
d97357e2036109245c83ba553d0290212e28ea40vboxsync size,
d97357e2036109245c83ba553d0290212e28ea40vboxsync NULL);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (!fResult)
d97357e2036109245c83ba553d0290212e28ea40vboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync free(pwszDeviceHwid);
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync pwszDeviceHwid = NULL;
d97357e2036109245c83ba553d0290212e28ea40vboxsync index++;
d97357e2036109245c83ba553d0290212e28ea40vboxsync continue;
d97357e2036109245c83ba553d0290212e28ea40vboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* something is wrong. This shouldn't have worked with a NULL buffer */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync index++;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync continue;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync for (WCHAR *t = pwszDeviceHwid;
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync t && *t && t < &pwszDeviceHwid[size / sizeof(WCHAR)];
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync t += wcslen(t) + 1)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync if (!_wcsicmp(L"vboxtap", t))
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* get the device instance ID */
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync WCHAR wszDevID[MAX_DEVICE_ID_LEN];
fba7ec2ca5a120ca53275eebdfa69425ce0e9829vboxsync if (CM_Get_Device_IDW(DeviceInfoData.DevInst,
fba7ec2ca5a120ca53275eebdfa69425ce0e9829vboxsync wszDevID, MAX_DEVICE_ID_LEN, 0) == CR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* compare to what we determined before */
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync if (!wcscmp(wszDevID, wszPnPInstanceId))
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync fFoundDevice = TRUE;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync break;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync if (pwszDeviceHwid)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync free(pwszDeviceHwid);
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync pwszDeviceHwid = NULL;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (fFoundDevice)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync break;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync index++;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (fFoundDevice)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiSetSelectedDevice(hDeviceInfo, &DeviceInfoData);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (!fResult)
d97357e2036109245c83ba553d0290212e28ea40vboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"VBox HostInterfaces: SetupDiSetSelectedDevice failed (0x%08X)!", GetLastError());
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync SetErrBreak(L"VBox HostInterfaces: Uninstallation failed!");
d97357e2036109245c83ba553d0290212e28ea40vboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiCallClassInstaller(DIF_REMOVE, hDeviceInfo, &DeviceInfoData);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (!fResult)
d97357e2036109245c83ba553d0290212e28ea40vboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"VBox HostInterfaces: SetupDiCallClassInstaller (DIF_REMOVE) failed (0x%08X)!", GetLastError());
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync SetErrBreak(L"VBox HostInterfaces: Uninstallation failed!");
d97357e2036109245c83ba553d0290212e28ea40vboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
d97357e2036109245c83ba553d0290212e28ea40vboxsync else
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync SetErrBreak(L"VBox HostInterfaces: Host interface network device not found!");
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync while (0);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* clean up the device info set */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (hDeviceInfo != INVALID_HANDLE_VALUE)
d97357e2036109245c83ba553d0290212e28ea40vboxsync SetupDiDestroyDeviceInfoList(hDeviceInfo);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync while (0);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return rc;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsyncUINT __stdcall UninstallTAPInstances(MSIHANDLE hModule)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync static const WCHAR *s_wszNetworkKey = L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}";
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync HKEY hCtrlNet;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync LONG lStatus = RegOpenKeyExW(HKEY_LOCAL_MACHINE, s_wszNetworkKey, 0, KEY_READ, &hCtrlNet);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (lStatus == ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"VBox HostInterfaces: Enumerating interfaces ...");
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync for (int i = 0; ; ++i)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync WCHAR wszNetworkGUID[256] = { 0 };
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync DWORD dwLen = (DWORD)sizeof(wszNetworkGUID);
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync lStatus = RegEnumKeyExW(hCtrlNet, i, wszNetworkGUID, &dwLen, NULL, NULL, NULL, NULL);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (lStatus != ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync switch (lStatus)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync case ERROR_NO_MORE_ITEMS:
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"VBox HostInterfaces: No interfaces found.");
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync break;
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync default:
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"VBox HostInterfaces: Enumeration failed: %ld", lStatus);
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync break;
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync break;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync if (isTAPDevice(wszNetworkGUID))
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"VBox HostInterfaces: Removing interface \"%s\" ...", wszNetworkGUID);
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync removeNetworkInterface(hModule, wszNetworkGUID);
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync lStatus = RegDeleteKeyW(hCtrlNet, wszNetworkGUID);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync RegCloseKey(hCtrlNet);
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync logStringW(hModule, L"VBox HostInterfaces: Removing interfaces done.");
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return ERROR_SUCCESS;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
3184fc1a3e65025cd55704cdb1629f4ab1f3ccd2vboxsync