1 | /* $Id: NetFltUninstall.cpp 21343 2009-07-07 15:30:08Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * NetFltUninstall - VBoxNetFlt uninstaller command line tool
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2008 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | * additional information or have any questions.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #include <vbox/WinNetConfig.h>
|
---|
23 | #include <stdio.h>
|
---|
24 |
|
---|
25 | #define NETFLT_ID L"sun_VBoxNetFlt"
|
---|
26 | #define VBOX_NETCFG_APP_NAME L"NetFltUninstall"
|
---|
27 | #define VBOX_NETFLT_PT_INF L".\\VBoxNetFlt.inf"
|
---|
28 | #define VBOX_NETFLT_MP_INF L".\\VBoxNetFlt_m.inf"
|
---|
29 | #define VBOX_NETFLT_RETRIES 10
|
---|
30 |
|
---|
31 | static VOID winNetCfgLogger (LPCWSTR szString)
|
---|
32 | {
|
---|
33 | wprintf(L"%s", szString);
|
---|
34 | }
|
---|
35 |
|
---|
36 | static int UninstallNetFlt()
|
---|
37 | {
|
---|
38 | INetCfg *pnc;
|
---|
39 | LPWSTR lpszLockedBy = NULL;
|
---|
40 | int r;
|
---|
41 |
|
---|
42 | VBoxNetCfgWinSetLogging(winNetCfgLogger);
|
---|
43 |
|
---|
44 | HRESULT hr = CoInitialize(NULL);
|
---|
45 | if(hr == S_OK)
|
---|
46 | {
|
---|
47 | int i = 0;
|
---|
48 | do
|
---|
49 | {
|
---|
50 | hr = VBoxNetCfgWinQueryINetCfg(TRUE, VBOX_NETCFG_APP_NAME, &pnc, &lpszLockedBy);
|
---|
51 | if(hr == S_OK)
|
---|
52 | {
|
---|
53 | hr = VBoxNetCfgWinNetFltUninstall(pnc);
|
---|
54 | if(hr != S_OK)
|
---|
55 | {
|
---|
56 | wprintf(L"error uninstalling VBoxNetFlt (0x%x)\n", hr);
|
---|
57 | r = 1;
|
---|
58 | }
|
---|
59 | else
|
---|
60 | {
|
---|
61 | wprintf(L"uninstalled successfully\n");
|
---|
62 | r = 0;
|
---|
63 | }
|
---|
64 |
|
---|
65 | VBoxNetCfgWinReleaseINetCfg(pnc, TRUE);
|
---|
66 | break;
|
---|
67 | }
|
---|
68 | else if(hr == NETCFG_E_NO_WRITE_LOCK && lpszLockedBy)
|
---|
69 | {
|
---|
70 | if(i < VBOX_NETFLT_RETRIES && !wcscmp(lpszLockedBy, L"6to4svc.dll"))
|
---|
71 | {
|
---|
72 | wprintf(L"6to4svc.dll is holding the lock, retrying %d out of %d\n", ++i, VBOX_NETFLT_RETRIES);
|
---|
73 | CoTaskMemFree(lpszLockedBy);
|
---|
74 | }
|
---|
75 | else
|
---|
76 | {
|
---|
77 | wprintf(L"Error: write lock is owned by another application (%s), close the application and retry uninstalling\n", lpszLockedBy);
|
---|
78 | r = 1;
|
---|
79 | CoTaskMemFree(lpszLockedBy);
|
---|
80 | break;
|
---|
81 | }
|
---|
82 | }
|
---|
83 | else
|
---|
84 | {
|
---|
85 | wprintf(L"Error getting the INetCfg interface (0x%x)\n", hr);
|
---|
86 | r = 1;
|
---|
87 | break;
|
---|
88 | }
|
---|
89 | } while(true);
|
---|
90 |
|
---|
91 | CoUninitialize();
|
---|
92 | }
|
---|
93 | else
|
---|
94 | {
|
---|
95 | wprintf(L"Error initializing COM (0x%x)\n", hr);
|
---|
96 | r = 1;
|
---|
97 | }
|
---|
98 |
|
---|
99 | VBoxNetCfgWinSetLogging(NULL);
|
---|
100 |
|
---|
101 | return r;
|
---|
102 | }
|
---|
103 |
|
---|
104 | int __cdecl main(int argc, char **argv)
|
---|
105 | {
|
---|
106 | return UninstallNetFlt();
|
---|
107 | }
|
---|