VBoxInstallHelper.cpp revision 1041613dd6ee5da259fa80b5555bb556f4dd8aaf
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync/* $Id$ */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync/** @file
3184fc1a3e65025cd55704cdb1629f4ab1f3ccd2vboxsync * VBoxInstallHelper - Various helper routines for Windows host installer.
3184fc1a3e65025cd55704cdb1629f4ab1f3ccd2vboxsync */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync/*
6eb6d0439d67fd4833f1d058b63bc9a56277b0b2vboxsync * Copyright (C) 2008-2010 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
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#ifdef VBOX_WITH_NETFLT
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync# include "VBox/WinNetConfig.h"
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#endif /* VBOX_WITH_NETFLT */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#include <VBox/version.h>
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#include <windows.h>
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#include <tchar.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
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#ifdef DEBUG
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync# define Assert(_expr) assert(_expr)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#else
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync# define Assert(_expr) do{ }while(0)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#endif
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncBOOL APIENTRY DllMain(HANDLE hModule,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync DWORD ul_reason_for_call,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LPVOID lpReserved)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return TRUE;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncvoid LogString(MSIHANDLE hInstall, TCHAR* szString, ...)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync PMSIHANDLE newHandle = ::MsiCreateRecord(2);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TCHAR szBuffer[1024] = {0};
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync va_list pArgList;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync va_start(pArgList, szString);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync _vsntprintf(szBuffer, sizeof(szBuffer) / sizeof(TCHAR), szString, pArgList);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync va_end(pArgList);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync MsiRecordSetString(newHandle, 0, szBuffer);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync MsiProcessMessage(hInstall, INSTALLMESSAGE(INSTALLMESSAGE_INFO), newHandle);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync MsiCloseHandle(newHandle);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#ifdef DEBUG
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync _tprintf(_T("Debug: %s\n"), szBuffer);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#endif
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncstatic void LogStringW(MSIHANDLE hInstall, LPCWSTR szString, ...)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync PMSIHANDLE newHandle = ::MsiCreateRecord(2);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TCHAR szBuffer[1024] = {0};
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync va_list pArgList;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync va_start(pArgList, szString);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync _vsnwprintf(szBuffer, sizeof(szBuffer) / sizeof(TCHAR), szString, pArgList);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync va_end(pArgList);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync MsiRecordSetStringW(newHandle, 0, szBuffer);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync MsiProcessMessage(hInstall, INSTALLMESSAGE(INSTALLMESSAGE_INFO), newHandle);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync MsiCloseHandle(newHandle);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncUINT __stdcall IsSerialCheckNeeded(MSIHANDLE a_hModule)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#ifndef VBOX_OSE
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /*BOOL bRet =*/ serialCheckNeeded(a_hModule);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#endif
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return ERROR_SUCCESS;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncUINT __stdcall CheckSerial(MSIHANDLE a_hModule)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#ifndef VBOX_OSE
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /*BOOL bRet =*/ serialIsValid(a_hModule);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#endif
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return ERROR_SUCCESS;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncDWORD Exec(MSIHANDLE hModule, TCHAR* szAppName, TCHAR* szCmdLine, TCHAR* szWorkDir, DWORD* dwExitCode)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync STARTUPINFO si;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync PROCESS_INFORMATION pi;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync DWORD rc = ERROR_SUCCESS;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync ::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);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync ::ZeroMemory(&pi, sizeof(pi));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("Executing command line: %s %s (Working Dir: %s)"), szAppName, szCmdLine, szWorkDir == NULL ? L"Current" : szWorkDir);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync ::SetLastError(0);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (!::CreateProcess(szAppName, /* Module name. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync szCmdLine, /* Command line. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync NULL, /* Process handle not inheritable. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync NULL, /* Thread handle not inheritable. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync FALSE, /* Set handle inheritance to FALSE .*/
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync 0, /* No creation flags. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync NULL, /* Use parent's environment block. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync szWorkDir, /* Use parent's starting directory. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync &si, /* Pointer to STARTUPINFO structure. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync &pi)) /* Pointer to PROCESS_INFORMATION structure. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync rc = ::GetLastError();
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("Executing command line: CreateProcess() failed! Error: %ld"), rc);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return rc;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* Wait until child process exits. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (WAIT_FAILED == ::WaitForSingleObject(pi.hProcess, 30 * 1000 /* Wait 30 secs max. */))
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync rc = ::GetLastError();
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("Executing command line: WaitForSingleObject() failed! Error: %ld"), rc);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (0 == ::GetExitCodeProcess(pi.hProcess, dwExitCode))
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync rc = ::GetLastError();
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("Executing command line: GetExitCodeProcess() failed! Error: %ld"), rc);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* Close process and thread handles. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync ::CloseHandle(pi.hProcess);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync ::CloseHandle(pi.hThread);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("Executing command returned: %ld (exit code %ld)"), rc, *dwExitCode);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return rc;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncUINT __stdcall InstallPythonAPI(MSIHANDLE hModule)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("InstallPythonAPI: Checking for installed Python environment ..."));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync HKEY hkPythonCore = NULL;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync BOOL bInstalled = FALSE;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LONG rc = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Python\\PythonCore", 0, KEY_READ, &hkPythonCore);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (rc != ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("InstallPythonAPI: No environment seems to be installed."));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return ERROR_SUCCESS;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TCHAR szPath[MAX_PATH] = { 0 };
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TCHAR szVal[MAX_PATH] = { 0 };
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync for (int i = 0;; ++i)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TCHAR szRoot[MAX_PATH] = { 0 };
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync DWORD dwLen = sizeof (szPath);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync DWORD dwKeyType = REG_SZ;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync rc = ::RegEnumKeyEx(hkPythonCore, i, szRoot, &dwLen, NULL, NULL, NULL, NULL);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (rc != ERROR_SUCCESS || dwLen <= 0)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync break;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
1041613dd6ee5da259fa80b5555bb556f4dd8aafvboxsync _stprintf_s(szPath, sizeof(szPath) / sizeof(TCHAR), L"%s\\InstallPath", szRoot);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync dwLen = sizeof(szVal);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync HKEY hkPythonInstPath = NULL;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync rc = ::RegOpenKeyEx(hkPythonCore, szPath, 0, KEY_READ, &hkPythonInstPath);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (rc != ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync continue;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync rc = ::RegQueryValueEx(hkPythonInstPath, L"", NULL, &dwKeyType, (LPBYTE)szVal, &dwLen);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(rc == ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("InstallPythonAPI: Path \"%s\" detected."), szVal);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync ::RegCloseKey (hkPythonCore);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* Python path found? */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TCHAR szExec[MAX_PATH] = { 0 };
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TCHAR szCmdLine[MAX_PATH] = { 0 };
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync DWORD dwExitCode = 0;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (::_tcslen(szVal) > 0)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* Cool, check for installed Win32 extensions. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("InstallPythonAPI: Python installed. Checking for Win32 extensions ..."));
1041613dd6ee5da259fa80b5555bb556f4dd8aafvboxsync _stprintf_s(szExec, sizeof(szExec) / sizeof(TCHAR), L"%s\\python.exe", szVal);
1041613dd6ee5da259fa80b5555bb556f4dd8aafvboxsync _stprintf_s(szCmdLine, sizeof(szCmdLine) / sizeof(TCHAR), L"%s\\python.exe -c \"import win32api\"", szVal);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if ( (0 == Exec(hModule, szExec, szCmdLine, NULL, &dwExitCode))
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync && (0 == dwExitCode))
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* Did we get the correct error level (=0)? */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("InstallPythonAPI: Win32 extensions installed."));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync bInstalled = TRUE;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else LogString(hModule, TEXT("InstallPythonAPI: Win32 extensions not found."));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (bInstalled) /* Is Python and all required stuff installed? */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* Get the VBoxAPI setup string. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TCHAR szVBoxAPISetupPath[MAX_PATH] = {0};
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync VBoxGetProperty(hModule, L"INSTALLDIR", szVBoxAPISetupPath, sizeof(szVBoxAPISetupPath));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* Set final path. */
1041613dd6ee5da259fa80b5555bb556f4dd8aafvboxsync _stprintf_s(szPath, sizeof(szPath) / sizeof(TCHAR), L"%s\\sdk\\install", szVBoxAPISetupPath);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* Install our API module. */
1041613dd6ee5da259fa80b5555bb556f4dd8aafvboxsync _stprintf_s(szCmdLine, sizeof(szCmdLine) / sizeof(TCHAR), L"%s\\python.exe vboxapisetup.py install", szVal);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* Set required environment variables. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (!SetEnvironmentVariable(L"VBOX_INSTALL_PATH", szVBoxAPISetupPath))
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("InstallPythonAPI: Cannot set environment variable VBOX_INSTALL_PATH!"));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return FALSE;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if ( (0 == Exec(hModule, szExec, szCmdLine, szPath, &dwExitCode))
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync && (0 == dwExitCode))
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* All done! */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("InstallPythonAPI: VBoxAPI for Python successfully installed."));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return ERROR_SUCCESS;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else LogString(hModule, TEXT("InstallPythonAPI: Error while installing VBoxAPI: %ld"), dwExitCode);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("InstallPythonAPI: VBoxAPI not installed."));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return ERROR_SUCCESS; /* Do not fail here. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncstatic LONG InstallBrandingValue(MSIHANDLE hModule,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync const TCHAR* pszFileName,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync const TCHAR* pszSection,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync const TCHAR* pszValue)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LONG rc;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TCHAR szValue[_MAX_PATH];
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (GetPrivateProfileString(pszSection, pszValue, NULL,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync szValue, sizeof(szValue), pszFileName) > 0)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync HKEY hkBranding;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TCHAR szKey[_MAX_PATH];
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (wcsicmp(L"General", pszSection) != 0)
1041613dd6ee5da259fa80b5555bb556f4dd8aafvboxsync _stprintf_s(szKey, sizeof(szKey) / sizeof(TCHAR), L"SOFTWARE\\%s\\VirtualBox\\Branding\\", VBOX_VENDOR_SHORT, pszSection);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
1041613dd6ee5da259fa80b5555bb556f4dd8aafvboxsync _stprintf_s(szKey, sizeof(szKey) / sizeof(TCHAR), L"SOFTWARE\\%s\\VirtualBox\\Branding", VBOX_VENDOR_SHORT);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKey,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync 0, KEY_WRITE, &hkBranding);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (rc == ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync rc = RegSetValueEx(hkBranding,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync pszValue,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync NULL,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync REG_SZ,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync (BYTE*)szValue,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync (DWORD)wcslen(szValue));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (rc != ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("InstallBranding: Could not write value %s! Error %ld"), pszValue, rc);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync RegCloseKey (hkBranding);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync rc = ERROR_NOT_FOUND;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return rc;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncUINT CopyDir(MSIHANDLE hModule, const TCHAR *pszDestDir, const TCHAR *pszSourceDir)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync UINT rc;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TCHAR szDest[_MAX_PATH + 1];
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TCHAR szSource[_MAX_PATH + 1];
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
1041613dd6ee5da259fa80b5555bb556f4dd8aafvboxsync _stprintf_s(szDest, sizeof(szDest) / sizeof(TCHAR), L"%s%c", pszDestDir, '\0');
1041613dd6ee5da259fa80b5555bb556f4dd8aafvboxsync _stprintf_s(szSource, sizeof(szSource) / sizeof(TCHAR), L"%s%c", pszSourceDir, '\0');
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync SHFILEOPSTRUCT s = {0};
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync s.hwnd = NULL;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync s.wFunc = FO_COPY;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync s.pTo = szDest;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync s.pFrom = szSource;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync s.fFlags = FOF_SILENT |
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync FOF_NOCONFIRMATION |
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync FOF_NOCONFIRMMKDIR |
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync FOF_NOERRORUI;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("CopyDir: DestDir=%s, SourceDir=%s"),
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync szDest, szSource);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync int r = SHFileOperation(&s);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (r != 0)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("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
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncUINT RemoveDir(MSIHANDLE hModule, const TCHAR *pszDestDir)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync UINT rc;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TCHAR szDest[_MAX_PATH + 1];
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
1041613dd6ee5da259fa80b5555bb556f4dd8aafvboxsync _stprintf_s(szDest, sizeof(szDest) / sizeof(TCHAR), L"%s%c", pszDestDir, '\0');
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync SHFILEOPSTRUCT s = {0};
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync s.hwnd = NULL;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync s.wFunc = FO_DELETE;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync s.pFrom = szDest;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync s.fFlags = FOF_SILENT |
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync FOF_NOCONFIRMATION |
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync FOF_NOCONFIRMMKDIR |
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync FOF_NOERRORUI;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("RemoveDir: DestDir=%s"), szDest);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync int r = SHFileOperation(&s);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (r != 0)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("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
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncUINT RenameDir(MSIHANDLE hModule, const TCHAR *pszDestDir, const TCHAR *pszSourceDir)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync UINT rc;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TCHAR szDest[_MAX_PATH + 1];
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TCHAR szSource[_MAX_PATH + 1];
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
1041613dd6ee5da259fa80b5555bb556f4dd8aafvboxsync _stprintf_s(szDest, sizeof(szDest) / sizeof(TCHAR), L"%s%c", pszDestDir, '\0');
1041613dd6ee5da259fa80b5555bb556f4dd8aafvboxsync _stprintf_s(szSource, sizeof(szSource) / sizeof(TCHAR), L"%s%c", pszSourceDir, '\0');
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync SHFILEOPSTRUCT s = {0};
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync s.hwnd = NULL;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync s.wFunc = FO_RENAME;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync s.pTo = szDest;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync s.pFrom = szSource;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync s.fFlags = FOF_SILENT |
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync FOF_NOCONFIRMATION |
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync FOF_NOCONFIRMMKDIR |
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync FOF_NOERRORUI;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("RenameDir: DestDir=%s, SourceDir=%s"),
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync szDest, szSource);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync int r = SHFileOperation(&s);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (r != 0)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("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;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("UninstallBranding: Handling branding file ..."));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TCHAR szPathTargetDir[_MAX_PATH];
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TCHAR szPathDest[_MAX_PATH];
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync rc = VBoxGetProperty(hModule, L"INSTALLDIR", szPathTargetDir, sizeof(szPathTargetDir));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (rc == ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /** @todo Check trailing slash after %s. */
1041613dd6ee5da259fa80b5555bb556f4dd8aafvboxsync _stprintf_s(szPathDest, sizeof(szPathDest) / sizeof(TCHAR), L"%scustom", szPathTargetDir);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync rc = RemoveDir(hModule, szPathDest);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (rc != ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* Check for hidden .custom directory and remove it. */
1041613dd6ee5da259fa80b5555bb556f4dd8aafvboxsync _stprintf_s(szPathDest, sizeof(szPathDest) / sizeof(TCHAR), L"%s.custom", szPathTargetDir);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync rc = RemoveDir(hModule, szPathDest);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("UninstallBranding: Handling done."));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return ERROR_SUCCESS; /* Do not fail here. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncUINT __stdcall InstallBranding(MSIHANDLE hModule)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync UINT rc;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("InstallBranding: Handling branding file ..."));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TCHAR szPathMSI[_MAX_PATH];
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TCHAR szPathTargetDir[_MAX_PATH];
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TCHAR szPathSource[_MAX_PATH];
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TCHAR szPathDest[_MAX_PATH];
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync rc = VBoxGetProperty(hModule, L"SOURCEDIR", szPathMSI, sizeof(szPathMSI));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync rc = VBoxGetProperty(hModule, L"INSTALLDIR", szPathTargetDir, sizeof(szPathTargetDir));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (rc == ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /** @todo Check for trailing slash after %s. */
1041613dd6ee5da259fa80b5555bb556f4dd8aafvboxsync _stprintf_s(szPathDest, sizeof(szPathDest) / sizeof(TCHAR), L"%s", szPathTargetDir);
1041613dd6ee5da259fa80b5555bb556f4dd8aafvboxsync _stprintf_s(szPathSource, sizeof(szPathSource) / sizeof(TCHAR), L"%s.custom", szPathMSI);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync rc = CopyDir(hModule, szPathDest, szPathSource);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (rc == ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
1041613dd6ee5da259fa80b5555bb556f4dd8aafvboxsync _stprintf_s(szPathDest, sizeof(szPathDest) / sizeof(TCHAR), L"%scustom", szPathTargetDir);
1041613dd6ee5da259fa80b5555bb556f4dd8aafvboxsync _stprintf_s(szPathSource, sizeof(szPathSource) / sizeof(TCHAR), L"%s.custom", szPathTargetDir);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync rc = RenameDir(hModule, szPathDest, szPathSource);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("InstallBranding: Handling done."));
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"
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#define NETFLT_MP_INF_REL_PATH L"drivers\\network\\netflt\\VBoxNetFlt_m.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;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncstatic VOID winNetCfgLogger(LPCWSTR szString)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync Assert(g_hCurrentModule);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(g_hCurrentModule)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogStringW(g_hCurrentModule, szString);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncstatic VOID inintWinNetCfgLogger(MSIHANDLE hModule)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync Assert(!g_hCurrentModule);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync Assert(hModule);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync g_hCurrentModule = hModule;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync VBoxNetCfgWinSetLogging((LOG_ROUTINE)winNetCfgLogger);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncstatic VOID finiWinNetCfgLogger()
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync Assert(g_hCurrentModule);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync VBoxNetCfgWinSetLogging((LOG_ROUTINE)NULL);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync g_hCurrentModule = NULL;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncstatic UINT Hresult2Error(MSIHANDLE hModule, HRESULT hr)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync switch(hr)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync case S_OK:
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return ERROR_SUCCESS;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync case NETCFG_S_REBOOT:
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("Reboot required, setting REBOOT property to Force"));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(MsiSetProperty(hModule, TEXT("REBOOT"), TEXT("Force")) != ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("Failed to set REBOOT property"));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return ERROR_GEN_FAILURE;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return ERROR_SUCCESS;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync default:
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("converting hresult (0x%x) to ERROR_GEN_FAILURE"), hr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return ERROR_GEN_FAILURE;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncstatic MSIHANDLE createNetCfgLockedMsgRecord(MSIHANDLE hModule)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync MSIHANDLE hRecord = MsiCreateRecord(2);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync Assert(hRecord);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(hRecord)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync do
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync UINT r = MsiRecordSetInteger(hRecord, 1, 25001);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync Assert(r == ERROR_SUCCESS);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(r != ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("createNetCfgLockedMsgRecord: MsiRecordSetInteger failed, r (0x%x)"), r);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync MsiCloseHandle(hRecord);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync hRecord = NULL;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync break;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }while(0);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("createNetCfgLockedMsgRecord: failed to create a record"));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return hRecord;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncstatic UINT doNetCfgInit(MSIHANDLE hModule, INetCfg **ppnc, BOOL bWrite)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync MSIHANDLE hMsg = NULL;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync UINT r = ERROR_GEN_FAILURE;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync int MsgResult;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync int cRetries = 0;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync do
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LPWSTR lpszLockedBy;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync HRESULT hr = VBoxNetCfgWinQueryINetCfg(bWrite, VBOX_NETCFG_APP_NAME, ppnc, &lpszLockedBy);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(hr != NETCFG_E_NO_WRITE_LOCK)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync Assert(hr == S_OK);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(hr != S_OK)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("doNetCfgInit: VBoxNetCfgWinQueryINetCfg failed, hr (0x%x)"), hr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync r = Hresult2Error(hModule, hr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync break;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* hr == NETCFG_E_NO_WRITE_LOCK */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync Assert(lpszLockedBy);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(!lpszLockedBy)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("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 */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(cRetries < VBOX_NETCFG_MAX_RETRIES
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync && !wcscmp(lpszLockedBy, L"6to4svc.dll"))
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync cRetries++;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("doNetCfgInit: lpszLockedBy is 6to4svc.dll, retrying %d out of %d"), cRetries, VBOX_NETCFG_MAX_RETRIES);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync MsgResult = IDRETRY;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(!hMsg)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync hMsg = createNetCfgLockedMsgRecord(hModule);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(!hMsg)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("doNetCfgInit: failed to create a message record, breaking"));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync CoTaskMemFree(lpszLockedBy);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync break;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync UINT rTmp = MsiRecordSetStringW(hMsg, 2, lpszLockedBy);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync Assert(rTmp == ERROR_SUCCESS);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(rTmp != ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("doNetCfgInit: MsiRecordSetStringW failed, r (0x%x)"), rTmp);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync CoTaskMemFree(lpszLockedBy);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync break;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync MsgResult = MsiProcessMessage(hModule, (INSTALLMESSAGE)(INSTALLMESSAGE_USER | MB_RETRYCANCEL), hMsg);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync Assert(MsgResult == IDRETRY || MsgResult == IDCANCEL);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("doNetCfgInit: MsiProcessMessage returned (0x%x)"), MsgResult);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync CoTaskMemFree(lpszLockedBy);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync } while(MsgResult == IDRETRY);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(hMsg)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync MsiCloseHandle(hMsg);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return r;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncstatic UINT vboxNetFltQueryInfArray(MSIHANDLE hModule, OUT LPWSTR *apInfFullPaths, PUINT pcInfs, DWORD cSize)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync UINT r;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync Assert(*pcInfs >= 2);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(*pcInfs >= 2)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync *pcInfs = 2;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync r = MsiGetPropertyW(hModule, L"CustomActionData", apInfFullPaths[0], &cSize);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync Assert(r == ERROR_SUCCESS);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(r == ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync wcscpy(apInfFullPaths[1], apInfFullPaths[0]);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync wcsncat(apInfFullPaths[0], NETFLT_PT_INF_REL_PATH, sizeof(NETFLT_PT_INF_REL_PATH));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync wcsncat(apInfFullPaths[1], NETFLT_MP_INF_REL_PATH, sizeof(NETFLT_MP_INF_REL_PATH));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("vboxNetFltQueryInfArray: MsiGetPropertyW failes, r (%d)"), r);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync r = ERROR_GEN_FAILURE;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("vboxNetFltQueryInfArray: buffer array size is < 2 : (%d)"), *pcInfs);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync *pcInfs = 2;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return r;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#endif /*VBOX_WITH_NETFLT*/
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncUINT __stdcall UninstallNetFlt(MSIHANDLE hModule)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#ifdef VBOX_WITH_NETFLT
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync INetCfg *pnc;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync UINT r;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync inintWinNetCfgLogger(hModule);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync BOOL bOldIntMode = SetupSetNonInteractiveMode(FALSE);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync __try
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("Uninstalling NetFlt"));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync r = doNetCfgInit(hModule, &pnc, TRUE);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync Assert(r == ERROR_SUCCESS);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(r == ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync HRESULT hr = VBoxNetCfgWinNetFltUninstall(pnc);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync Assert(hr == S_OK);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(hr != S_OK)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("UninstallNetFlt: VBoxNetCfgWinUninstallComponent failed, hr (0x%x)"), hr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync r = Hresult2Error(hModule, hr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync VBoxNetCfgWinReleaseINetCfg(pnc, TRUE);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* Never fail the uninstall */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync r = ERROR_SUCCESS;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("UninstallNetFlt: doNetCfgInit failed, r (0x%x)"), r);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("Uninstalling NetFlt done, r (0x%x)"), r);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync __finally
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(bOldIntMode)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* the prev mode != FALSE, i.e. non-interactive */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync SetupSetNonInteractiveMode(bOldIntMode);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync finiWinNetCfgLogger();
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return ERROR_SUCCESS;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#else /* not defined VBOX_WITH_NETFLT */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return ERROR_SUCCESS;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#endif /* VBOX_WITH_NETFLT */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncUINT __stdcall InstallNetFlt(MSIHANDLE hModule)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#ifdef VBOX_WITH_NETFLT
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync UINT r;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync INetCfg *pnc;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync inintWinNetCfgLogger(hModule);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync BOOL bOldIntMode = SetupSetNonInteractiveMode(FALSE);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync __try
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("Installing NetFlt"));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync r = doNetCfgInit(hModule, &pnc, TRUE);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync Assert(r == ERROR_SUCCESS);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(r == ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync WCHAR PtInf[MAX_PATH];
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync WCHAR MpInf[MAX_PATH];
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync DWORD sz = sizeof(PtInf);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LPWSTR aInfs[] = {PtInf, MpInf};
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync UINT cInfs = 2;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync r = vboxNetFltQueryInfArray(hModule, aInfs, &cInfs, sz);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync Assert(r == ERROR_SUCCESS);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync Assert(cInfs == 2);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(r == ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync // HRESULT hr = VBoxNetCfgWinInstallSpecifiedComponent (
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync // pnc,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync // (LPCWSTR*)aInfs,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync // cInfs,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync // NETFLT_ID,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync // &GUID_DEVCLASS_NETSERVICE,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync // true);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync HRESULT hr = VBoxNetCfgWinNetFltInstall(pnc, (LPCWSTR*)aInfs, cInfs);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync Assert(hr == S_OK);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(hr != S_OK)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("InstallNetFlt: VBoxNetCfgWinInstallSpecifiedComponent failed, hr (0x%x)"), hr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync r = Hresult2Error(hModule, hr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("InstallNetFlt: vboxNetFltQueryInfArray failed, r (0x%x)"), r);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync VBoxNetCfgWinReleaseINetCfg(pnc, TRUE);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* Never fail the uninstall */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync r = ERROR_SUCCESS;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("InstallNetFlt: doNetCfgInit failed, r (0x%x)"), r);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("Installing NetFlt done, r (0x%x)"), r);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync __finally
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(bOldIntMode)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* the prev mode != FALSE, i.e. non-interactive */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync SetupSetNonInteractiveMode(bOldIntMode);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync finiWinNetCfgLogger();
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return ERROR_SUCCESS;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#else /* not defined VBOX_WITH_NETFLT */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return ERROR_SUCCESS;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#endif /* VBOX_WITH_NETFLT */
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
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync 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 );
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync Assert(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 );
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync Assert(winEr == ERROR_SUCCESS);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(winEr == ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync WCHAR ConnectoinName[128];
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync ULONG cbName = sizeof(ConnectoinName);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync HRESULT hr = VBoxNetCfgWinGenHostonlyConnectionName (DevName, ConnectoinName, &cbName);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync Assert(hr == S_OK);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(hr == S_OK)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync hr = VBoxNetCfgWinRenameConnection (guid, ConnectoinName);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync Assert(hr == S_OK);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync RegCloseKey(hKey);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync Assert(0);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return TRUE;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#endif
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncUINT __stdcall CreateHostOnlyInterface(MSIHANDLE hModule)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#ifdef VBOX_WITH_NETFLT
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync inintWinNetCfgLogger(hModule);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync BOOL bPrevMode = SetupSetNonInteractiveMode(FALSE);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync bool bSetStaticIp = true;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("Creating Host-Only Interface"));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync HRESULT hr = VBoxNetCfgWinRemoveAllNetDevicesOfId(NETADP_ID);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync Assert(hr == S_OK);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(hr != S_OK)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("CreateHostOnlyInterface: VBoxNetCfgWinRemoveAllNetDevicesOfId failed, hr (0x%x)"), hr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync bSetStaticIp = false;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync GUID guid;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync WCHAR MpInf[MAX_PATH];
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync DWORD cSize = sizeof(MpInf)/sizeof(MpInf[0]);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LPCWSTR pInfPath = NULL;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync bool bIsFile = false;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync UINT r = MsiGetPropertyW(hModule, L"CustomActionData", MpInf, &cSize);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync Assert(r == ERROR_SUCCESS);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(r == ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("NetAdpDir property: (%s)"), MpInf);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(cSize)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(MpInf[cSize-1] != L'\\')
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync MpInf[cSize] = L'\\';
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync ++cSize;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync MpInf[cSize] = L'\0';
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync// wcscat(MpInf, L"VBoxNetFlt.inf");
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync wcscat(MpInf, L"drivers\\network\\netadp\\VBoxNetAdp.inf");
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync pInfPath = MpInf;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync bIsFile = true;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("Resulting inf path is: (%s)"), pInfPath);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("CreateHostOnlyInterface: NetAdpDir property value is empty"));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("CreateHostOnlyInterface: failed to get NetAdpDir property, r(%d)"), r);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* make sure the inf file is installed */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(!!pInfPath && bIsFile)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync HRESULT tmpHr = VBoxNetCfgWinInstallInf(pInfPath);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync Assert(tmpHr == S_OK);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync hr = VBoxNetCfgWinCreateHostOnlyNetworkInterface (pInfPath, bIsFile, &guid, NULL, NULL);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync Assert(hr == S_OK);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(hr == S_OK)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync ULONG ip = inet_addr("192.168.56.1");
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync ULONG mask = inet_addr("255.255.255.0");
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync hr = VBoxNetCfgWinEnableStaticIpConfig(&guid, ip, mask);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync Assert(hr == S_OK);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(hr != S_OK)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("CreateHostOnlyInterface: VBoxNetCfgWinEnableStaticIpConfig failed, hr (0x%x)"), hr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("CreateHostOnlyInterface: VBoxNetCfgWinCreateHostOnlyNetworkInterface failed, hr (0x%x)"), hr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(bPrevMode)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* the prev mode != FALSE, i.e. non-interactive */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync SetupSetNonInteractiveMode(bPrevMode);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync finiWinNetCfgLogger();
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* never fail the install even if we are not succeeded */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return ERROR_SUCCESS;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#else /* not defined VBOX_WITH_NETFLT */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return ERROR_SUCCESS;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#endif /* VBOX_WITH_NETFLT */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncUINT __stdcall RemoveHostOnlyInterfaces(MSIHANDLE hModule)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#ifdef VBOX_WITH_NETFLT
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync inintWinNetCfgLogger(hModule);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("Removing All Host-Only Interface"));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync BOOL bPrevMode = SetupSetNonInteractiveMode(FALSE);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync HRESULT hr = VBoxNetCfgWinRemoveAllNetDevicesOfId(NETADP_ID);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(hr == S_OK)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync hr = VBoxNetCfgWinUninstallInfs(&GUID_DEVCLASS_NET, NETADP_ID, 0/* could be SUOI_FORCEDELETE */);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(hr != S_OK)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("NetAdp uninstalled successfully, but failed to remove infs\n"));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("NetAdp uninstall failed, hr = 0x%x\n"), hr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(bPrevMode)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* the prev mode != FALSE, i.e. non-interactive */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync SetupSetNonInteractiveMode(bPrevMode);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync finiWinNetCfgLogger();
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return ERROR_SUCCESS;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#else /* not defined VBOX_WITH_NETFLT */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return ERROR_SUCCESS;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#endif /* VBOX_WITH_NETFLT */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncstatic bool IsTAPDevice (const TCHAR *a_pcGUID)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync HKEY hNetcard;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LONG status;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync DWORD len;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync int i = 0;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync bool ret = false;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync status = RegOpenKeyEx (HKEY_LOCAL_MACHINE,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TEXT("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}"),
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync 0, KEY_READ, &hNetcard);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (status != ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return false;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync while(true)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TCHAR szEnumName[256];
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TCHAR szNetCfgInstanceId[256];
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync DWORD dwKeyType;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync HKEY hNetCardGUID;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync len = sizeof(szEnumName);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync status = RegEnumKeyEx (hNetcard, i, szEnumName, &len, NULL, NULL, NULL, NULL);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (status != ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync break;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync status = RegOpenKeyEx (hNetcard, szEnumName, 0, KEY_READ, &hNetCardGUID);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (status == ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync len = sizeof (szNetCfgInstanceId);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync status = RegQueryValueEx (hNetCardGUID, TEXT("NetCfgInstanceId"), NULL, &dwKeyType, (LPBYTE)szNetCfgInstanceId, &len);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (status == ERROR_SUCCESS && dwKeyType == REG_SZ)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TCHAR szNetProductName[256];
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TCHAR szNetProviderName[256];
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync szNetProductName[0] = 0;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync len = sizeof(szNetProductName);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync status = RegQueryValueEx (hNetCardGUID, TEXT("ProductName"), NULL, &dwKeyType, (LPBYTE)szNetProductName, &len);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync szNetProviderName[0] = 0;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync len = sizeof(szNetProviderName);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync status = RegQueryValueEx (hNetCardGUID, TEXT("ProviderName"), NULL, &dwKeyType, (LPBYTE)szNetProviderName, &len);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if ( !wcscmp(szNetCfgInstanceId, a_pcGUID)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync && !wcscmp(szNetProductName, TEXT("VirtualBox TAP Adapter"))
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync && ( (!wcscmp(szNetProviderName, TEXT("innotek GmbH"))) /* Legacy stuff. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync || (!wcscmp(szNetProviderName, TEXT("Sun Microsystems, Inc."))) /* Legacy stuff. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync || (!wcscmp(szNetProviderName, TEXT(VBOX_VENDOR))) /* Reflects current vendor string. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync )
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync )
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync ret = true;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync RegCloseKey(hNetCardGUID);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync break;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync RegCloseKey(hNetCardGUID);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync ++i;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync RegCloseKey (hNetcard);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return ret;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#define VBOX_TAP_HWID _T("vboxtap")
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#define SetErrBreak(strAndArgs) \
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (1) { \
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync rc = 0; \
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString (a_hModule, strAndArgs); \
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync break; \
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync } else do {} while (0)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncint removeNetworkInterface (MSIHANDLE a_hModule, const TCHAR* pcGUID)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync int rc = 1;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync do
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TCHAR lszPnPInstanceId [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
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync do
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TCHAR strRegLocation [256];
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync swprintf (strRegLocation,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TEXT("SYSTEM\\CurrentControlSet\\Control\\Network\\")
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TEXT("{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s"),
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync pcGUID);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LONG status;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync status = RegOpenKeyEx (HKEY_LOCAL_MACHINE, strRegLocation, 0,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync KEY_READ, &hkeyNetwork);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if ((status != ERROR_SUCCESS) || !hkeyNetwork)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync SetErrBreak ((TEXT("VBox HostInterfaces: Host interface network was not found in registry (%s)! [1]"), strRegLocation));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync status = RegOpenKeyExA (hkeyNetwork, "Connection", 0,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync KEY_READ, &hkeyConnection);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if ((status != ERROR_SUCCESS) || !hkeyConnection)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync SetErrBreak ((TEXT("VBox HostInterfaces: Host interface network was not found in registry (%s)! [2]"), strRegLocation));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync DWORD len = sizeof (lszPnPInstanceId);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync DWORD dwKeyType;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync status = RegQueryValueExW (hkeyConnection, L"PnPInstanceID", NULL,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync &dwKeyType, (LPBYTE) lszPnPInstanceId, &len);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if ((status != ERROR_SUCCESS) || (dwKeyType != REG_SZ))
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync SetErrBreak ((TEXT("VBox HostInterfaces: Host interface network was not found in registry (%s)! [3]"), strRegLocation));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync while (0);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (hkeyConnection)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync RegCloseKey (hkeyConnection);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (hkeyNetwork)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync 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;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync do
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync BOOL ok;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync DWORD ret = 0;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync GUID netGuid;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync SP_DEVINFO_DATA DeviceInfoData;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync DWORD index = 0;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync BOOL found = FALSE;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync DWORD size = 0;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* initialize the structure size */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync DeviceInfoData.cbSize = sizeof (SP_DEVINFO_DATA);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* copy the net class GUID */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync memcpy (&netGuid, &GUID_DEVCLASS_NET, sizeof (GUID_DEVCLASS_NET));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* return a device info set contains all installed devices of the Net class */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync hDeviceInfo = SetupDiGetClassDevs (&netGuid, NULL, NULL, DIGCF_PRESENT);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (hDeviceInfo == INVALID_HANDLE_VALUE)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString (a_hModule, TEXT("VBox HostInterfaces: SetupDiGetClassDevs failed (0x%08X)!"), GetLastError());
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync SetErrBreak (TEXT("VBox HostInterfaces: Uninstallation failed!"));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* enumerate the driver info list */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync while (TRUE)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TCHAR *deviceHwid;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync ok = SetupDiEnumDeviceInfo (hDeviceInfo, index, &DeviceInfoData);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (!ok)
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 */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync ok = SetupDiGetDeviceRegistryProperty (hDeviceInfo,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync &DeviceInfoData,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync SPDRP_HARDWAREID,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync NULL,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync NULL,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync 0,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync &size);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (!ok)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync index++;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync continue;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync deviceHwid = (TCHAR *) malloc (size);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync ok = SetupDiGetDeviceRegistryProperty (hDeviceInfo,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync &DeviceInfoData,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync SPDRP_HARDWAREID,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync NULL,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync (PBYTE)deviceHwid,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync size,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync NULL);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (!ok)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync free (deviceHwid);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync deviceHwid = NULL;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync index++;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync continue;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* something is wrong. This shouldn't have worked with a NULL buffer */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync index++;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync continue;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync for (TCHAR *t = deviceHwid;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync t && *t && t < &deviceHwid[size / sizeof(TCHAR)];
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync t += _tcslen (t) + 1)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (!_tcsicmp (VBOX_TAP_HWID, t))
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* get the device instance ID */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TCHAR devID [MAX_DEVICE_ID_LEN];
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (CM_Get_Device_ID(DeviceInfoData.DevInst,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync devID, MAX_DEVICE_ID_LEN, 0) == CR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* compare to what we determined before */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (wcscmp(devID, lszPnPInstanceId) == 0)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync found = TRUE;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync break;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (deviceHwid)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync free (deviceHwid);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync deviceHwid = NULL;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (found)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync break;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync index++;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (found == FALSE)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync SetErrBreak (TEXT("VBox HostInterfaces: Host Interface Network driver not found!"));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync ok = SetupDiSetSelectedDevice (hDeviceInfo, &DeviceInfoData);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (!ok)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString (a_hModule, TEXT("VBox HostInterfaces: SetupDiSetSelectedDevice failed (0x%08X)!"), GetLastError());
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync SetErrBreak (TEXT("VBox HostInterfaces: Uninstallation failed!"));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync ok = SetupDiCallClassInstaller (DIF_REMOVE, hDeviceInfo, &DeviceInfoData);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (!ok)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString (a_hModule, TEXT("VBox HostInterfaces: SetupDiCallClassInstaller (DIF_REMOVE) failed (0x%08X)!"), GetLastError());
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync SetErrBreak (TEXT("VBox HostInterfaces: Uninstallation failed!"));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync while (0);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* clean up the device info set */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (hDeviceInfo != INVALID_HANDLE_VALUE)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync SetupDiDestroyDeviceInfoList (hDeviceInfo);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync while (0);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return rc;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncUINT __stdcall UninstallTAPInstances (MSIHANDLE a_hModule)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync{
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync static const TCHAR *NetworkKey = TEXT("SYSTEM\\CurrentControlSet\\Control\\Network\\")
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TEXT("{4D36E972-E325-11CE-BFC1-08002BE10318}");
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync HKEY hCtrlNet;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LONG status = 0;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync DWORD len = 0;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LONG cnt = 0;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync status = RegOpenKeyEx (HKEY_LOCAL_MACHINE, NetworkKey, 0, KEY_READ, &hCtrlNet);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (status == ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(a_hModule, TEXT("VBox HostInterfaces: Enumerating interfaces ..."));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync for (int i = 0;; ++ i)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TCHAR szNetworkGUID [256] = { 0 };
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TCHAR szNetworkConnection [256] = { 0 };
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync len = sizeof (szNetworkGUID);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync status = RegEnumKeyEx (hCtrlNet, i, szNetworkGUID, &len, NULL, NULL, NULL, NULL);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (status != ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync switch (status)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync case ERROR_NO_MORE_ITEMS:
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(a_hModule, TEXT("VBox HostInterfaces: No interfaces found."));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync break;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync default:
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(a_hModule, TEXT("VBox HostInterfaces: Enumeration failed: %ld"), status);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync break;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync };
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync break;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (IsTAPDevice(szNetworkGUID))
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync {
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(a_hModule, TEXT("VBox HostInterfaces: Removing interface \"%s\" ..."), szNetworkGUID);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync removeNetworkInterface (a_hModule, szNetworkGUID);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync status = RegDeleteKey (hCtrlNet, szNetworkGUID);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync RegCloseKey (hCtrlNet);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(a_hModule, TEXT("VBox HostInterfaces: Removing interfaces done."));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return ERROR_SUCCESS;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync}
3184fc1a3e65025cd55704cdb1629f4ab1f3ccd2vboxsync