VBoxInstallHelper.cpp revision 1d5386c32e68116bca5e054dbef008b1f516bb25
3184fc1a3e65025cd55704cdb1629f4ab1f3ccd2vboxsync * VBoxInstallHelper - Various helper routines for Windows host installer.
6eb6d0439d67fd4833f1d058b63bc9a56277b0b2vboxsync * Copyright (C) 2008-2010 Oracle Corporation
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#endif /* VBOX_WITH_NETFLT */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncvoid LogString(MSIHANDLE hInstall, TCHAR* szString, ...)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync _vsntprintf(szBuffer, sizeof(szBuffer) / sizeof(TCHAR), szString, pArgList);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync MsiProcessMessage(hInstall, INSTALLMESSAGE(INSTALLMESSAGE_INFO), newHandle);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncstatic void LogStringW(MSIHANDLE hInstall, LPCWSTR szString, ...)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync _vsnwprintf(szBuffer, sizeof(szBuffer) / sizeof(TCHAR), szString, pArgList);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync MsiProcessMessage(hInstall, INSTALLMESSAGE(INSTALLMESSAGE_INFO), newHandle);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncUINT __stdcall IsSerialCheckNeeded(MSIHANDLE a_hModule)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncDWORD Exec(MSIHANDLE hModule, TCHAR* szAppName, TCHAR* szCmdLine, TCHAR* szWorkDir, DWORD* dwExitCode)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync si.wShowWindow = SW_HIDE; /* For debugging: SW_SHOW; */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("Executing command line: %s %s (Working Dir: %s)"), szAppName, szCmdLine, szWorkDir == NULL ? L"Current" : szWorkDir);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync 0, /* No creation flags. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync &pi)) /* Pointer to PROCESS_INFORMATION structure. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("Executing command line: CreateProcess() failed! Error: %ld"), rc);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* Wait until child process exits. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (WAIT_FAILED == ::WaitForSingleObject(pi.hProcess, 30 * 1000 /* Wait 30 secs max. */))
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("Executing command line: WaitForSingleObject() failed! Error: %ld"), rc);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (0 == ::GetExitCodeProcess(pi.hProcess, dwExitCode))
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("Executing command line: GetExitCodeProcess() failed! Error: %ld"), rc);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* Close process and thread handles. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("Executing command returned: %ld (exit code %ld)"), rc, *dwExitCode);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("InstallPythonAPI: Checking for installed Python environment ..."));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LONG rc = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Python\\PythonCore", 0, KEY_READ, &hkPythonCore);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("InstallPythonAPI: No environment seems to be installed."));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync for (int i = 0;; ++i)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync rc = ::RegEnumKeyEx(hkPythonCore, i, szRoot, &dwLen, NULL, NULL, NULL, NULL);
1041613dd6ee5da259fa80b5555bb556f4dd8aafvboxsync _stprintf_s(szPath, sizeof(szPath) / sizeof(TCHAR), L"%s\\InstallPath", szRoot);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync rc = ::RegOpenKeyEx(hkPythonCore, szPath, 0, KEY_READ, &hkPythonInstPath);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync rc = ::RegQueryValueEx(hkPythonInstPath, L"", NULL, &dwKeyType, (LPBYTE)szVal, &dwLen);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("InstallPythonAPI: Path \"%s\" detected."), szVal);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* Python path found? */
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 if ( (0 == Exec(hModule, szExec, szCmdLine, NULL, &dwExitCode))
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* Did we get the correct error level (=0)? */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("InstallPythonAPI: Win32 extensions installed."));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else LogString(hModule, TEXT("InstallPythonAPI: Win32 extensions not found."));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (bInstalled) /* Is Python and all required stuff installed? */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* Get the VBoxAPI setup string. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync VBoxGetProperty(hModule, L"INSTALLDIR", szVBoxAPISetupPath, sizeof(szVBoxAPISetupPath));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* Set final path. */
1041613dd6ee5da259fa80b5555bb556f4dd8aafvboxsync _stprintf_s(szPath, sizeof(szPath) / sizeof(TCHAR), L"%s\\sdk\\install", szVBoxAPISetupPath);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* Install our API module. */
1041613dd6ee5da259fa80b5555bb556f4dd8aafvboxsync _stprintf_s(szCmdLine, sizeof(szCmdLine) / sizeof(TCHAR), L"%s\\python.exe vboxapisetup.py install", szVal);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* Set required environment variables. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (!SetEnvironmentVariable(L"VBOX_INSTALL_PATH", szVBoxAPISetupPath))
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("InstallPythonAPI: Cannot set environment variable VBOX_INSTALL_PATH!"));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if ( (0 == Exec(hModule, szExec, szCmdLine, szPath, &dwExitCode))
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* All done! */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("InstallPythonAPI: VBoxAPI for Python successfully installed."));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync else LogString(hModule, TEXT("InstallPythonAPI: Error while installing VBoxAPI: %ld"), dwExitCode);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("InstallPythonAPI: VBoxAPI not installed."));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (GetPrivateProfileString(pszSection, pszValue, NULL,
1041613dd6ee5da259fa80b5555bb556f4dd8aafvboxsync _stprintf_s(szKey, sizeof(szKey) / sizeof(TCHAR), L"SOFTWARE\\%s\\VirtualBox\\Branding\\", VBOX_VENDOR_SHORT, pszSection);
1041613dd6ee5da259fa80b5555bb556f4dd8aafvboxsync _stprintf_s(szKey, sizeof(szKey) / sizeof(TCHAR), L"SOFTWARE\\%s\\VirtualBox\\Branding", VBOX_VENDOR_SHORT);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("InstallBranding: Could not write value %s! Error %ld"), pszValue, rc);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncUINT CopyDir(MSIHANDLE hModule, const TCHAR *pszDestDir, const TCHAR *pszSourceDir)
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 LogString(hModule, TEXT("CopyDir: DestDir=%s, SourceDir=%s"),
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (r != 0)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("CopyDir: Copy operation returned status 0x%x"), r);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncUINT RemoveDir(MSIHANDLE hModule, const TCHAR *pszDestDir)
1041613dd6ee5da259fa80b5555bb556f4dd8aafvboxsync _stprintf_s(szDest, sizeof(szDest) / sizeof(TCHAR), L"%s%c", pszDestDir, '\0');
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("RemoveDir: DestDir=%s"), szDest);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (r != 0)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("RemoveDir: Remove operation returned status 0x%x"), r);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncUINT RenameDir(MSIHANDLE hModule, const TCHAR *pszDestDir, const TCHAR *pszSourceDir)
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 LogString(hModule, TEXT("RenameDir: DestDir=%s, SourceDir=%s"),
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (r != 0)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("RenameDir: Rename operation returned status 0x%x"), r);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("UninstallBranding: Handling branding file ..."));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync rc = VBoxGetProperty(hModule, L"INSTALLDIR", szPathTargetDir, sizeof(szPathTargetDir));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /** @todo Check trailing slash after %s. */
1041613dd6ee5da259fa80b5555bb556f4dd8aafvboxsync _stprintf_s(szPathDest, sizeof(szPathDest) / sizeof(TCHAR), L"%scustom", szPathTargetDir);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* Check for hidden .custom directory and remove it. */
1041613dd6ee5da259fa80b5555bb556f4dd8aafvboxsync _stprintf_s(szPathDest, sizeof(szPathDest) / sizeof(TCHAR), L"%s.custom", szPathTargetDir);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("UninstallBranding: Handling done."));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("InstallBranding: Handling branding file ..."));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync rc = VBoxGetProperty(hModule, L"SOURCEDIR", szPathMSI, sizeof(szPathMSI));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync rc = VBoxGetProperty(hModule, L"INSTALLDIR", szPathTargetDir, sizeof(szPathTargetDir));
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);
1041613dd6ee5da259fa80b5555bb556f4dd8aafvboxsync _stprintf_s(szPathDest, sizeof(szPathDest) / sizeof(TCHAR), L"%scustom", szPathTargetDir);
1041613dd6ee5da259fa80b5555bb556f4dd8aafvboxsync _stprintf_s(szPathSource, sizeof(szPathSource) / sizeof(TCHAR), L"%s.custom", szPathTargetDir);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("InstallBranding: Handling done."));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync/** @todo should use some real VBox app name */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#define VBOX_NETCFG_APP_NAME L"VirtualBox Installer"
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#define NETFLT_PT_INF_REL_PATH L"drivers\\network\\netflt\\VBoxNetFlt.inf"
be6a7ee8f237a71cf075c128e8e391e6c3654687vboxsync#define NETFLT_MP_INF_REL_PATH L"drivers\\network\\netflt\\VBoxNetFltM.inf"
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#define NETFLT_ID L"sun_VBoxNetFlt" /** @todo Needs to be changed (?). */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#define NETADP_ID L"sun_VBoxNetAdp" /** @todo Needs to be changed (?). */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync VBoxNetCfgWinSetLogging((LOG_ROUTINE)winNetCfgLogger);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncstatic UINT Hresult2Error(MSIHANDLE hModule, HRESULT hr)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("Reboot required, setting REBOOT property to Force"));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(MsiSetProperty(hModule, TEXT("REBOOT"), TEXT("Force")) != ERROR_SUCCESS)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("Failed to set REBOOT property"));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("converting hresult (0x%x) to ERROR_GEN_FAILURE"), hr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncstatic MSIHANDLE createNetCfgLockedMsgRecord(MSIHANDLE hModule)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("createNetCfgLockedMsgRecord: MsiRecordSetInteger failed, r (0x%x)"), r);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("createNetCfgLockedMsgRecord: failed to create a record"));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncstatic UINT doNetCfgInit(MSIHANDLE hModule, INetCfg **ppnc, BOOL bWrite)
be6a7ee8f237a71cf075c128e8e391e6c3654687vboxsync HRESULT hr = VBoxNetCfgWinQueryINetCfg(ppnc, bWrite, VBOX_NETCFG_APP_NAME, 10000, &lpszLockedBy);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("doNetCfgInit: VBoxNetCfgWinQueryINetCfg failed, hr (0x%x)"), hr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* hr == NETCFG_E_NO_WRITE_LOCK */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("doNetCfgInit: lpszLockedBy == NULL, breaking"));
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 LogString(hModule, TEXT("doNetCfgInit: lpszLockedBy is 6to4svc.dll, retrying %d out of %d"), cRetries, VBOX_NETCFG_MAX_RETRIES);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("doNetCfgInit: failed to create a message record, breaking"));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync UINT rTmp = MsiRecordSetStringW(hMsg, 2, lpszLockedBy);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("doNetCfgInit: MsiRecordSetStringW failed, r (0x%x)"), rTmp);
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);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncstatic UINT vboxNetFltQueryInfArray(MSIHANDLE hModule, OUT LPWSTR *apInfFullPaths, PUINT pcInfs, DWORD cSize)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync r = MsiGetPropertyW(hModule, L"CustomActionData", apInfFullPaths[0], &cSize);
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 LogString(hModule, TEXT("vboxNetFltQueryInfArray: MsiGetPropertyW failes, r (%d)"), r);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("vboxNetFltQueryInfArray: buffer array size is < 2 : (%d)"), *pcInfs);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#endif /*VBOX_WITH_NETFLT*/
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync BOOL bOldIntMode = SetupSetNonInteractiveMode(FALSE);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("UninstallNetFlt: VBoxNetCfgWinUninstallComponent failed, hr (0x%x)"), hr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* Never fail the uninstall */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("UninstallNetFlt: doNetCfgInit failed, r (0x%x)"), r);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("Uninstalling NetFlt done, r (0x%x)"), r);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* the prev mode != FALSE, i.e. non-interactive */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#else /* not defined VBOX_WITH_NETFLT */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#endif /* VBOX_WITH_NETFLT */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync BOOL bOldIntMode = SetupSetNonInteractiveMode(FALSE);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync r = vboxNetFltQueryInfArray(hModule, aInfs, &cInfs, sz);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync // HRESULT hr = VBoxNetCfgWinInstallSpecifiedComponent (
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync // (LPCWSTR*)aInfs,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync // NETFLT_ID,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync // &GUID_DEVCLASS_NETSERVICE,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync HRESULT hr = VBoxNetCfgWinNetFltInstall(pnc, (LPCWSTR*)aInfs, cInfs);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("InstallNetFlt: VBoxNetCfgWinInstallSpecifiedComponent failed, hr (0x%x)"), hr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("InstallNetFlt: vboxNetFltQueryInfArray failed, r (0x%x)"), r);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* Never fail the uninstall */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("InstallNetFlt: doNetCfgInit failed, r (0x%x)"), r);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("Installing NetFlt done, r (0x%x)"), r);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* the prev mode != FALSE, i.e. non-interactive */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#else /* not defined VBOX_WITH_NETFLT */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#endif /* VBOX_WITH_NETFLT */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncstatic BOOL RenameHostOnlyConnectionsCallback(HDEVINFO hDevInfo, PSP_DEVINFO_DATA pDev, PVOID pContext)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if(SetupDiGetDeviceRegistryPropertyW(hDevInfo, pDev,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync 0, /*IN DWORD HwProfile, */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync L"NetCfgInstanceId", /*__in_opt LPCTSTR lpValueName,*/
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync HRESULT hr = VBoxNetCfgWinGenHostonlyConnectionName (DevName, ConnectoinName, &cbName);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync hr = VBoxNetCfgWinRenameConnection (guid, ConnectoinName);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncUINT __stdcall CreateHostOnlyInterface(MSIHANDLE hModule)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync BOOL bPrevMode = SetupSetNonInteractiveMode(FALSE);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("Creating Host-Only Interface"));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync HRESULT hr = VBoxNetCfgWinRemoveAllNetDevicesOfId(NETADP_ID);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("CreateHostOnlyInterface: VBoxNetCfgWinRemoveAllNetDevicesOfId failed, hr (0x%x)"), hr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync bool bIsFile = false;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync UINT r = MsiGetPropertyW(hModule, L"CustomActionData", MpInf, &cSize);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("NetAdpDir property: (%s)"), MpInf);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync// wcscat(MpInf, L"VBoxNetFlt.inf");
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync wcscat(MpInf, L"drivers\\network\\netadp\\VBoxNetAdp.inf");
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("Resulting inf path is: (%s)"), pInfPath);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("CreateHostOnlyInterface: NetAdpDir property value is empty"));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("CreateHostOnlyInterface: failed to get NetAdpDir property, r(%d)"), r);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* make sure the inf file is installed */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync hr = VBoxNetCfgWinCreateHostOnlyNetworkInterface (pInfPath, bIsFile, &guid, NULL, NULL);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync hr = VBoxNetCfgWinEnableStaticIpConfig(&guid, ip, mask);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("CreateHostOnlyInterface: VBoxNetCfgWinEnableStaticIpConfig failed, hr (0x%x)"), hr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("CreateHostOnlyInterface: VBoxNetCfgWinCreateHostOnlyNetworkInterface failed, hr (0x%x)"), hr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* the prev mode != FALSE, i.e. non-interactive */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* never fail the install even if we are not succeeded */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#else /* not defined VBOX_WITH_NETFLT */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#endif /* VBOX_WITH_NETFLT */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncUINT __stdcall RemoveHostOnlyInterfaces(MSIHANDLE hModule)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("Removing All Host-Only Interface"));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync BOOL bPrevMode = SetupSetNonInteractiveMode(FALSE);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync HRESULT hr = VBoxNetCfgWinRemoveAllNetDevicesOfId(NETADP_ID);
be6a7ee8f237a71cf075c128e8e391e6c3654687vboxsync hr = VBoxNetCfgWinInfUninstallAll(&GUID_DEVCLASS_NET, NETADP_ID, L"Net", 0/* could be SUOI_FORCEDELETE */);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("NetAdp uninstalled successfully, but failed to remove infs\n"));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(hModule, TEXT("NetAdp uninstall failed, hr = 0x%x\n"), hr);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* the prev mode != FALSE, i.e. non-interactive */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#else /* not defined VBOX_WITH_NETFLT */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync#endif /* VBOX_WITH_NETFLT */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync bool ret = false;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TEXT("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}"),
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return false;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync while(true)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync status = RegEnumKeyEx (hNetcard, i, szEnumName, &len, NULL, NULL, NULL, NULL);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync status = RegOpenKeyEx (hNetcard, szEnumName, 0, KEY_READ, &hNetCardGUID);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync status = RegQueryValueEx (hNetCardGUID, TEXT("NetCfgInstanceId"), NULL, &dwKeyType, (LPBYTE)szNetCfgInstanceId, &len);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (status == ERROR_SUCCESS && dwKeyType == REG_SZ)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync status = RegQueryValueEx (hNetCardGUID, TEXT("ProductName"), NULL, &dwKeyType, (LPBYTE)szNetProductName, &len);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync status = RegQueryValueEx (hNetCardGUID, TEXT("ProviderName"), NULL, &dwKeyType, (LPBYTE)szNetProviderName, &len);
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 } else do {} while (0)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncint removeNetworkInterface (MSIHANDLE a_hModule, const TCHAR* pcGUID)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* We have to find the device instance ID through a registry search */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TEXT("SYSTEM\\CurrentControlSet\\Control\\Network\\")
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync TEXT("{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s"),
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync status = RegOpenKeyEx (HKEY_LOCAL_MACHINE, strRegLocation, 0,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync SetErrBreak ((TEXT("VBox HostInterfaces: Host interface network was not found in registry (%s)! [1]"), strRegLocation));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync status = RegOpenKeyExA (hkeyNetwork, "Connection", 0,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync SetErrBreak ((TEXT("VBox HostInterfaces: Host interface network was not found in registry (%s)! [2]"), strRegLocation));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync status = RegQueryValueExW (hkeyConnection, L"PnPInstanceID", NULL,
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 * Now we are going to enumerate all network devices and
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * wait until we encounter the right device instance ID
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* initialize the structure size */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* copy the net class GUID */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync memcpy (&netGuid, &GUID_DEVCLASS_NET, sizeof (GUID_DEVCLASS_NET));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* return a device info set contains all installed devices of the Net class */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync hDeviceInfo = SetupDiGetClassDevs (&netGuid, NULL, NULL, DIGCF_PRESENT);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString (a_hModule, TEXT("VBox HostInterfaces: SetupDiGetClassDevs failed (0x%08X)!"), GetLastError());
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync SetErrBreak (TEXT("VBox HostInterfaces: Uninstallation failed!"));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* enumerate the driver info list */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync ok = SetupDiEnumDeviceInfo (hDeviceInfo, index, &DeviceInfoData);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* try to get the hardware ID registry property */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync ok = SetupDiGetDeviceRegistryProperty (hDeviceInfo,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync ok = SetupDiGetDeviceRegistryProperty (hDeviceInfo,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* something is wrong. This shouldn't have worked with a NULL buffer */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* get the device instance ID */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* compare to what we determined before */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync SetErrBreak (TEXT("VBox HostInterfaces: Host Interface Network driver not found!"));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync ok = SetupDiSetSelectedDevice (hDeviceInfo, &DeviceInfoData);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString (a_hModule, TEXT("VBox HostInterfaces: SetupDiSetSelectedDevice failed (0x%08X)!"), GetLastError());
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync SetErrBreak (TEXT("VBox HostInterfaces: Uninstallation failed!"));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync ok = SetupDiCallClassInstaller (DIF_REMOVE, hDeviceInfo, &DeviceInfoData);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString (a_hModule, TEXT("VBox HostInterfaces: SetupDiCallClassInstaller (DIF_REMOVE) failed (0x%08X)!"), GetLastError());
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync SetErrBreak (TEXT("VBox HostInterfaces: Uninstallation failed!"));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* clean up the device info set */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncUINT __stdcall UninstallTAPInstances (MSIHANDLE a_hModule)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync static const TCHAR *NetworkKey = TEXT("SYSTEM\\CurrentControlSet\\Control\\Network\\")
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync status = RegOpenKeyEx (HKEY_LOCAL_MACHINE, NetworkKey, 0, KEY_READ, &hCtrlNet);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(a_hModule, TEXT("VBox HostInterfaces: Enumerating interfaces ..."));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync for (int i = 0;; ++ i)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync status = RegEnumKeyEx (hCtrlNet, i, szNetworkGUID, &len, NULL, NULL, NULL, NULL);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(a_hModule, TEXT("VBox HostInterfaces: No interfaces found."));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(a_hModule, TEXT("VBox HostInterfaces: Enumeration failed: %ld"), status);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(a_hModule, TEXT("VBox HostInterfaces: Removing interface \"%s\" ..."), szNetworkGUID);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogString(a_hModule, TEXT("VBox HostInterfaces: Removing interfaces done."));