1 | /* $Id: VBoxNetLwfUninstall.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * NetLwfUninstall - VBoxNetLwf uninstaller command line tool
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2014-2023 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 |
|
---|
43 | #include <iprt/initterm.h>
|
---|
44 | #include <iprt/message.h>
|
---|
45 | #include <iprt/utf16.h>
|
---|
46 |
|
---|
47 |
|
---|
48 | /*********************************************************************************************************************************
|
---|
49 | * Defined Constants And Macros *
|
---|
50 | *********************************************************************************************************************************/
|
---|
51 | #define VBOX_NETCFG_APP_NAME L"NetLwfUninstall"
|
---|
52 | #define VBOX_NETLWF_RETRIES 10
|
---|
53 |
|
---|
54 |
|
---|
55 | static DECLCALLBACK(void) winNetCfgLogger(const char *pszString)
|
---|
56 | {
|
---|
57 | RTMsgInfo("%s", pszString);
|
---|
58 | }
|
---|
59 |
|
---|
60 | static int VBoxNetLwfUninstall()
|
---|
61 | {
|
---|
62 | int rcExit = RTEXITCODE_FAILURE;
|
---|
63 |
|
---|
64 | VBoxNetCfgWinSetLogging(winNetCfgLogger);
|
---|
65 |
|
---|
66 | HRESULT hr = CoInitialize(NULL);
|
---|
67 | if (hr == S_OK)
|
---|
68 | {
|
---|
69 | for (int i = 0;; i++)
|
---|
70 | {
|
---|
71 | LPWSTR pwszLockedBy = NULL;
|
---|
72 | INetCfg *pnc = NULL;
|
---|
73 | hr = VBoxNetCfgWinQueryINetCfg(&pnc, TRUE, VBOX_NETCFG_APP_NAME, 10000, &pwszLockedBy);
|
---|
74 | if (hr == S_OK)
|
---|
75 | {
|
---|
76 | hr = VBoxNetCfgWinNetLwfUninstall(pnc);
|
---|
77 | if (hr == S_OK)
|
---|
78 | {
|
---|
79 | RTMsgInfo("uninstalled successfully!");
|
---|
80 | rcExit = RTEXITCODE_SUCCESS;
|
---|
81 | }
|
---|
82 | else
|
---|
83 | RTMsgError("error uninstalling VBoxNetLwf: %Rhrc");
|
---|
84 |
|
---|
85 | VBoxNetCfgWinReleaseINetCfg(pnc, TRUE);
|
---|
86 | break;
|
---|
87 | }
|
---|
88 |
|
---|
89 | if (hr == NETCFG_E_NO_WRITE_LOCK && pwszLockedBy)
|
---|
90 | {
|
---|
91 | if (i < VBOX_NETLWF_RETRIES && RTUtf16ICmpAscii(pwszLockedBy, "6to4svc.dll") == 0)
|
---|
92 | {
|
---|
93 | RTMsgInfo("6to4svc.dll is holding the lock - retry %d out of %d ...", i + 1, VBOX_NETLWF_RETRIES);
|
---|
94 | CoTaskMemFree(pwszLockedBy);
|
---|
95 | }
|
---|
96 | else
|
---|
97 | {
|
---|
98 | RTMsgError("Write lock is owned by another application (%ls), close the application and retry uninstalling",
|
---|
99 | pwszLockedBy);
|
---|
100 | CoTaskMemFree(pwszLockedBy);
|
---|
101 | break;
|
---|
102 | }
|
---|
103 | }
|
---|
104 | else
|
---|
105 | {
|
---|
106 | RTMsgError("Failed getting the INetCfg interface: %Rhrc", hr);
|
---|
107 | break;
|
---|
108 | }
|
---|
109 | }
|
---|
110 |
|
---|
111 | CoUninitialize();
|
---|
112 | }
|
---|
113 | else
|
---|
114 | RTMsgError("Failed initializing COM: %Rhrc", hr);
|
---|
115 |
|
---|
116 | VBoxNetCfgWinSetLogging(NULL);
|
---|
117 |
|
---|
118 | return rcExit;
|
---|
119 | }
|
---|
120 |
|
---|
121 | int __cdecl main(int argc, char **argv)
|
---|
122 | {
|
---|
123 | RTR3InitExeNoArguments(0);
|
---|
124 | if (argc != 1)
|
---|
125 | return RTMsgErrorExit(RTEXITCODE_SYNTAX, "This utility takes no arguments\n");
|
---|
126 | NOREF(argv);
|
---|
127 |
|
---|
128 | return VBoxNetLwfUninstall();
|
---|
129 | }
|
---|
130 |
|
---|