static int VBoxNetAdpUninstall(void) { VBoxNetCfgWinSetLogging(winNetCfgLogger); printf("uninstalling all host-only interfaces..\n"); HRESULT hr = CoInitialize(NULL); if (SUCCEEDED(hr)) { hr = VBoxNetCfgWinRemoveAllNetDevicesOfId(VBOX_NETADP_HWID); if (SUCCEEDED(hr)) { hr = VBoxDrvCfgInfUninstallAllSetupDi(&GUID_DEVCLASS_NET, L"Net", VBOX_NETADP_HWID, 0/* could be SUOI_FORCEDELETE */); if (SUCCEEDED(hr)) { printf("uninstallation successful\n"); } else printf("uninstalled successfully, but failed to remove infs\n"); } else printf("uninstall failed, hr = 0x%x\n", hr); CoUninitialize(); } else printf("Error initializing COM (0x%x)\n", hr); VBoxNetCfgWinSetLogging(NULL); return SUCCEEDED(hr) ? 0 : 1; }
static int VBoxNetAdpEnable(void) { VBoxNetCfgWinSetLogging(winNetCfgLogger); printf("enabling all host-only interfaces..\n"); HRESULT hr = CoInitialize(NULL); if (SUCCEEDED(hr)) { hr = VBoxNetCfgWinPropChangeAllNetDevicesOfId(VBOX_NETADP_HWID, VBOXNECTFGWINPROPCHANGE_TYPE_ENABLE); if (SUCCEEDED(hr)) { printf("enabling successful\n"); } else printf("enabling failed, hr = 0x%x\n", hr); CoUninitialize(); } else printf("Error initializing COM (0x%x)\n", hr); VBoxNetCfgWinSetLogging(NULL); return SUCCEEDED(hr) ? 0 : 1; }
static VOID netCfgLoggerDisable() { if (g_hCurrentModule) { VBoxNetCfgWinSetLogging((LOG_ROUTINE)NULL); g_hCurrentModule = NULL; } }
static VOID netCfgLoggerEnable(MSIHANDLE hModule) { NonStandardAssert(hModule); if (g_hCurrentModule) netCfgLoggerDisable(); g_hCurrentModule = hModule; VBoxNetCfgWinSetLogging((LOG_ROUTINE)netCfgLoggerCallback); }
static int VBoxNetAdpUninstall() { int r = 1; VBoxNetCfgWinSetLogging(winNetCfgLogger); printf("uninstalling all Host-Only interfaces..\n"); HRESULT hr = CoInitialize(NULL); if(hr == S_OK) { hr = VBoxNetCfgWinRemoveAllNetDevicesOfId(L"sun_VBoxNetAdp"); if(hr == S_OK) { hr = VBoxDrvCfgInfUninstallAllSetupDi(&GUID_DEVCLASS_NET, L"Net", L"sun_VBoxNetAdp", 0/* could be SUOI_FORCEDELETE */); if(hr == S_OK) { printf("uninstalled successfully\n"); } else { printf("uninstalled successfully, but failed to remove infs\n"); } r = 0; } else { printf("uninstall failed, hr = 0x%x\n", hr); } CoUninitialize(); } else { wprintf(L"Error initializing COM (0x%x)\n", hr); } VBoxNetCfgWinSetLogging(NULL); return r; }
static VOID netCfgLoggerEnable(MSIHANDLE hModule) { NonStandardAssert(hModule); if (g_hCurrentModule) netCfgLoggerDisable(); g_hCurrentModule = hModule; VBoxNetCfgWinSetLogging((LOG_ROUTINE)netCfgLoggerCallback); /* uncomment next line if you want to add logging information from VBoxDrvCfg.cpp */ VBoxDrvCfgLoggerSet(vboxDrvLoggerCallback, NULL); }
static int VBoxNetAdpUpdate(void) { VBoxNetCfgWinSetLogging(winNetCfgLogger); printf("uninstalling all host-only interfaces..\n"); HRESULT hr = CoInitialize(NULL); if (SUCCEEDED(hr)) { BOOL fRebootRequired = FALSE; /* * Before we can update the driver for existing adapters we need to remove * all old driver packages from the driver cache. Otherwise we may end up * with both NDIS5 and NDIS6 versions of VBoxNetAdp in the cache which * will cause all sorts of trouble. */ VBoxDrvCfgInfUninstallAllF(L"Net", VBOX_NETADP_HWID, SUOI_FORCEDELETE); hr = VBoxNetCfgWinUpdateHostOnlyNetworkInterface(VBOX_NETADP_INF, &fRebootRequired, VBOX_NETADP_HWID); if (SUCCEEDED(hr)) { if (fRebootRequired) printf("!!REBOOT REQUIRED!!\n"); printf("updated successfully\n"); } else printf("update failed, hr = 0x%x\n", hr); CoUninitialize(); } else printf("Error initializing COM (0x%x)\n", hr); VBoxNetCfgWinSetLogging(NULL); return SUCCEEDED(hr) ? 0 : 1; }
static int VBoxNetLwfUninstall() { INetCfg *pnc; LPWSTR lpszLockedBy = NULL; int r; VBoxNetCfgWinSetLogging(winNetCfgLogger); HRESULT hr = CoInitialize(NULL); if (hr == S_OK) { int i = 0; do { hr = VBoxNetCfgWinQueryINetCfg(&pnc, TRUE, VBOX_NETCFG_APP_NAME, 10000, &lpszLockedBy); if (hr == S_OK) { hr = VBoxNetCfgWinNetLwfUninstall(pnc); if (hr != S_OK) { wprintf(L"error uninstalling VBoxNetLwf (0x%x)\n", hr); r = 1; } else { wprintf(L"uninstalled successfully\n"); r = 0; } VBoxNetCfgWinReleaseINetCfg(pnc, TRUE); break; } else if (hr == NETCFG_E_NO_WRITE_LOCK && lpszLockedBy) { if (i < VBOX_NETLWF_RETRIES && !wcscmp(lpszLockedBy, L"6to4svc.dll")) { wprintf(L"6to4svc.dll is holding the lock, retrying %d out of %d\n", ++i, VBOX_NETLWF_RETRIES); CoTaskMemFree(lpszLockedBy); } else { wprintf(L"Error: write lock is owned by another application (%s), close the application and retry uninstalling\n", lpszLockedBy); r = 1; CoTaskMemFree(lpszLockedBy); break; } } else { wprintf(L"Error getting the INetCfg interface (0x%x)\n", hr); r = 1; break; } } while (true); CoUninitialize(); } else { wprintf(L"Error initializing COM (0x%x)\n", hr); r = 1; } VBoxNetCfgWinSetLogging(NULL); return r; }
static int VBoxNetAdpInstall(void) { VBoxNetCfgWinSetLogging(winNetCfgLogger); HRESULT hr = CoInitialize(NULL); if (SUCCEEDED(hr)) { printf("adding host-only interface..\n"); DWORD dwErr = ERROR_SUCCESS; WCHAR MpInf[MAX_PATH]; if (!GetFullPathNameW(VBOX_NETADP_INF, sizeof(MpInf)/sizeof(MpInf[0]), MpInf, NULL)) dwErr = GetLastError(); if (dwErr == ERROR_SUCCESS) { hr = VBoxDrvCfgInfInstall(MpInf); if (FAILED(hr)) printf("VBoxDrvCfgInfInstall failed %#x\n", hr); GUID guid; BSTR name, errMsg; hr = VBoxNetCfgWinCreateHostOnlyNetworkInterface (MpInf, true, &guid, &name, &errMsg); if (SUCCEEDED(hr)) { ULONG ip, mask; hr = VBoxNetCfgWinGenHostOnlyNetworkNetworkIp(&ip, &mask); if (SUCCEEDED(hr)) { /* ip returned by VBoxNetCfgWinGenHostOnlyNetworkNetworkIp is a network ip, * i.e. 192.168.xxx.0, assign 192.168.xxx.1 for the hostonly adapter */ ip = ip | (1 << 24); hr = VBoxNetCfgWinEnableStaticIpConfig(&guid, ip, mask); if (SUCCEEDED(hr)) { printf("installation successful\n"); } else printf("VBoxNetCfgWinEnableStaticIpConfig failed: hr = 0x%x\n", hr); } else printf("VBoxNetCfgWinGenHostOnlyNetworkNetworkIp failed: hr = 0x%x\n", hr); } else printf("VBoxNetCfgWinCreateHostOnlyNetworkInterface failed: hr = 0x%x\n", hr); } else { printf("GetFullPathNameW failed: winEr = %d\n", dwErr); hr = HRESULT_FROM_WIN32(dwErr); } CoUninitialize(); } else printf("Error initializing COM (0x%x)\n", hr); VBoxNetCfgWinSetLogging(NULL); return SUCCEEDED(hr) ? 0 : 1; }
static int VBoxNetAdpInstall() { int r = 1; VBoxNetCfgWinSetLogging(winNetCfgLogger); HRESULT hr = CoInitialize(NULL); if(hr == S_OK) { #if 0 //ndef DEBUG_misha printf("not implemented yet, please use device manager for Host-Only net interface installation.. sorry :( \n"); #else GUID guid; BSTR name, errMsg; printf("adding host-only interface..\n"); DWORD WinEr; WCHAR MpInf[MAX_PATH]; GetFullPathNameW(VBOX_NETADP_INF, sizeof(MpInf)/sizeof(MpInf[0]), MpInf, NULL); WinEr = GetLastError(); if(WinEr == ERROR_SUCCESS) { hr = VBoxNetCfgWinCreateHostOnlyNetworkInterface (MpInf, true, &guid, &name, &errMsg); if(hr == S_OK) { ULONG ip, mask; hr = VBoxNetCfgWinGenHostOnlyNetworkNetworkIp(&ip, &mask); if(hr == S_OK) { /* ip returned by VBoxNetCfgWinGenHostOnlyNetworkNetworkIp is a network ip, * i.e. 192.168.xxx.0, assign 192.168.xxx.1 for the hostonly adapter */ ip = ip | (1 << 24); hr = VBoxNetCfgWinEnableStaticIpConfig(&guid, ip, mask); if(hr != S_OK) { printf("VBoxNetCfgWinEnableStaticIpConfig failed: hr = 0x%x\n", hr); } else { r = 0; } } else { printf("VBoxNetCfgWinGenHostOnlyNetworkNetworkIp failed: hr = 0x%x\n", hr); } } else { printf("VBoxNetCfgWinCreateHostOnlyNetworkInterface failed: hr = 0x%x\n", hr); } } else { printf("GetFullPathNameW failed: winEr = %d\n", WinEr); } #endif CoUninitialize(); } else { wprintf(L"Error initializing COM (0x%x)\n", hr); } VBoxNetCfgWinSetLogging(NULL); return r; }