VirtualBox

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

Last change on this file since 69498 was 69498, checked in by vboxsync, 7 years ago

backed out r118835 as it incorrectly updated the 'This file is based on' file headers.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1/* $Id: VBoxNetFltUninstall.cpp 69498 2017-10-28 15:07:25Z vboxsync $ */
2/** @file
3 * NetFltUninstall - VBoxNetFlt uninstaller command line tool
4 */
5
6/*
7 * Copyright (C) 2008-2016 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27#include <VBox/VBoxNetCfg-win.h>
28#include <stdio.h>
29
30#define NETFLT_ID L"sun_VBoxNetFlt"
31#define VBOX_NETCFG_APP_NAME L"NetFltUninstall"
32#define VBOX_NETFLT_PT_INF L".\\VBoxNetFlt.inf"
33#define VBOX_NETFLT_MP_INF L".\\VBoxNetFltM.inf"
34#define VBOX_NETFLT_RETRIES 10
35
36static VOID winNetCfgLogger (LPCSTR szString)
37{
38 printf("%s", szString);
39}
40
41static int VBoxNetFltUninstall()
42{
43 INetCfg *pnc;
44 LPWSTR lpszLockedBy = NULL;
45 int r;
46
47 VBoxNetCfgWinSetLogging(winNetCfgLogger);
48
49 HRESULT hr = CoInitialize(NULL);
50 if (hr == S_OK)
51 {
52 int i = 0;
53 do
54 {
55 hr = VBoxNetCfgWinQueryINetCfg(&pnc, TRUE, VBOX_NETCFG_APP_NAME, 10000, &lpszLockedBy);
56 if (hr == S_OK)
57 {
58 hr = VBoxNetCfgWinNetFltUninstall(pnc);
59 if (hr != S_OK && hr != S_FALSE)
60 {
61 wprintf(L"error uninstalling VBoxNetFlt (0x%x)\n", hr);
62 r = 1;
63 }
64 else
65 {
66 wprintf(L"uninstalled successfully\n");
67 r = 0;
68 }
69
70 VBoxNetCfgWinReleaseINetCfg(pnc, TRUE);
71 break;
72 }
73 else if (hr == NETCFG_E_NO_WRITE_LOCK && lpszLockedBy)
74 {
75 if (i < VBOX_NETFLT_RETRIES && !wcscmp(lpszLockedBy, L"6to4svc.dll"))
76 {
77 wprintf(L"6to4svc.dll is holding the lock, retrying %d out of %d\n", ++i, VBOX_NETFLT_RETRIES);
78 CoTaskMemFree(lpszLockedBy);
79 }
80 else
81 {
82 wprintf(L"Error: write lock is owned by another application (%s), close the application and retry uninstalling\n", lpszLockedBy);
83 r = 1;
84 CoTaskMemFree(lpszLockedBy);
85 break;
86 }
87 }
88 else
89 {
90 wprintf(L"Error getting the INetCfg interface (0x%x)\n", hr);
91 r = 1;
92 break;
93 }
94 } while (true);
95
96 CoUninitialize();
97 }
98 else
99 {
100 wprintf(L"Error initializing COM (0x%x)\n", hr);
101 r = 1;
102 }
103
104 VBoxNetCfgWinSetLogging(NULL);
105
106 return r;
107}
108
109int __cdecl main(int argc, char **argv)
110{
111 RT_NOREF2(argc, argv);
112 return VBoxNetFltUninstall();
113}
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