VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetFltUninstall.cpp@ 96572

Last change on this file since 96572 was 96572, checked in by vboxsync, 2 years ago

HostDrives,Installer/win: Reworked the windows installer related code for no-CRT mode, where applicable, and changed the XxxxInstall.exe/XxxxUninstall.exe utilities to link against VBoxRT.dll instead of being statically linked. Lot's of cleanup. The change is uncomfortably large, but difficult to detangle these things. bugref:10261

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.6 KB
Line 
1/* $Id: VBoxNetFltUninstall.cpp 96572 2022-09-01 20:36:22Z vboxsync $ */
2/** @file
3 * NetFltUninstall - VBoxNetFlt uninstaller command line tool
4 */
5
6/*
7 * Copyright (C) 2008-2022 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include <VBox/VBoxNetCfg-win.h>
42#include <stdio.h>
43
44#include <iprt/initterm.h>
45#include <iprt/message.h>
46
47
48/*********************************************************************************************************************************
49* Defined Constants And Macros *
50*********************************************************************************************************************************/
51#define NETFLT_ID L"sun_VBoxNetFlt"
52#define VBOX_NETCFG_APP_NAME L"NetFltUninstall"
53#define VBOX_NETFLT_PT_INF L".\\VBoxNetFlt.inf"
54#define VBOX_NETFLT_MP_INF L".\\VBoxNetFltM.inf"
55#define VBOX_NETFLT_RETRIES 10
56
57
58static DECLCALLBACK(void) winNetCfgLogger(const char *pszString)
59{
60 printf("%s", pszString);
61}
62
63static int VBoxNetFltUninstall()
64{
65 INetCfg *pnc;
66 int rcExit = RTEXITCODE_FAILURE;
67
68 VBoxNetCfgWinSetLogging(winNetCfgLogger);
69
70 HRESULT hr = CoInitialize(NULL);
71 if (hr == S_OK)
72 {
73 for (int i = 0;; i++)
74 {
75 LPWSTR pwszLockedBy = NULL;
76 hr = VBoxNetCfgWinQueryINetCfg(&pnc, TRUE, VBOX_NETCFG_APP_NAME, 10000, &pwszLockedBy);
77 if (hr == S_OK)
78 {
79 hr = VBoxNetCfgWinNetFltUninstall(pnc);
80 if (hr != S_OK && hr != S_FALSE)
81 wprintf(L"error uninstalling VBoxNetFlt (%#lx)\n", hr);
82 else
83 {
84 wprintf(L"uninstalled successfully\n");
85 rcExit = RTEXITCODE_SUCCESS;
86 }
87
88 VBoxNetCfgWinReleaseINetCfg(pnc, TRUE);
89 break;
90 }
91
92 if (hr == NETCFG_E_NO_WRITE_LOCK && pwszLockedBy)
93 {
94 if (i < VBOX_NETFLT_RETRIES && !wcscmp(pwszLockedBy, L"6to4svc.dll"))
95 {
96 wprintf(L"6to4svc.dll is holding the lock, retrying %d out of %d\n", i + 1, VBOX_NETFLT_RETRIES);
97 CoTaskMemFree(pwszLockedBy);
98 }
99 else
100 {
101 wprintf(L"Error: write lock is owned by another application (%s), close the application and retry uninstalling\n",
102 pwszLockedBy);
103 CoTaskMemFree(pwszLockedBy);
104 break;
105 }
106 }
107 else
108 {
109 wprintf(L"Error getting the INetCfg interface (%#lx)\n", hr);
110 break;
111 }
112 }
113
114 CoUninitialize();
115 }
116 else
117 wprintf(L"Error initializing COM (%#lx)\n", hr);
118
119 VBoxNetCfgWinSetLogging(NULL);
120
121 return rcExit;
122}
123
124int __cdecl main(int argc, char **argv)
125{
126 RTR3InitExeNoArguments(0);
127 if (argc != 1)
128 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "This utility takes no arguments\n");
129 NOREF(argv);
130
131 return VBoxNetFltUninstall();
132}
133
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette