1 | /* $Id: VBoxNetLwfUninstall.cpp 53947 2015-01-23 10:18:45Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * NetLwfUninstall - VBoxNetLwf uninstaller command line tool
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2014 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 |
|
---|
18 | #include <VBox/VBoxNetCfg-win.h>
|
---|
19 | #include <stdio.h>
|
---|
20 |
|
---|
21 | #define VBOX_NETCFG_APP_NAME L"NetLwfUninstall"
|
---|
22 | #define VBOX_NETLWF_RETRIES 10
|
---|
23 |
|
---|
24 | static VOID winNetCfgLogger (LPCSTR szString)
|
---|
25 | {
|
---|
26 | printf("%s", szString);
|
---|
27 | }
|
---|
28 |
|
---|
29 | static int VBoxNetLwfUninstall()
|
---|
30 | {
|
---|
31 | INetCfg *pnc;
|
---|
32 | LPWSTR lpszLockedBy = NULL;
|
---|
33 | int r;
|
---|
34 |
|
---|
35 | VBoxNetCfgWinSetLogging(winNetCfgLogger);
|
---|
36 |
|
---|
37 | HRESULT hr = CoInitialize(NULL);
|
---|
38 | if(hr == S_OK)
|
---|
39 | {
|
---|
40 | int i = 0;
|
---|
41 | do
|
---|
42 | {
|
---|
43 | hr = VBoxNetCfgWinQueryINetCfg(&pnc, TRUE, VBOX_NETCFG_APP_NAME, 10000, &lpszLockedBy);
|
---|
44 | if(hr == S_OK)
|
---|
45 | {
|
---|
46 | hr = VBoxNetCfgWinNetLwfUninstall(pnc);
|
---|
47 | if(hr != S_OK)
|
---|
48 | {
|
---|
49 | wprintf(L"error uninstalling VBoxNetLwf (0x%x)\n", hr);
|
---|
50 | r = 1;
|
---|
51 | }
|
---|
52 | else
|
---|
53 | {
|
---|
54 | wprintf(L"uninstalled successfully\n");
|
---|
55 | r = 0;
|
---|
56 | }
|
---|
57 |
|
---|
58 | VBoxNetCfgWinReleaseINetCfg(pnc, TRUE);
|
---|
59 | break;
|
---|
60 | }
|
---|
61 | else if(hr == NETCFG_E_NO_WRITE_LOCK && lpszLockedBy)
|
---|
62 | {
|
---|
63 | if(i < VBOX_NETLWF_RETRIES && !wcscmp(lpszLockedBy, L"6to4svc.dll"))
|
---|
64 | {
|
---|
65 | wprintf(L"6to4svc.dll is holding the lock, retrying %d out of %d\n", ++i, VBOX_NETLWF_RETRIES);
|
---|
66 | CoTaskMemFree(lpszLockedBy);
|
---|
67 | }
|
---|
68 | else
|
---|
69 | {
|
---|
70 | wprintf(L"Error: write lock is owned by another application (%s), close the application and retry uninstalling\n", lpszLockedBy);
|
---|
71 | r = 1;
|
---|
72 | CoTaskMemFree(lpszLockedBy);
|
---|
73 | break;
|
---|
74 | }
|
---|
75 | }
|
---|
76 | else
|
---|
77 | {
|
---|
78 | wprintf(L"Error getting the INetCfg interface (0x%x)\n", hr);
|
---|
79 | r = 1;
|
---|
80 | break;
|
---|
81 | }
|
---|
82 | } while(true);
|
---|
83 |
|
---|
84 | CoUninitialize();
|
---|
85 | }
|
---|
86 | else
|
---|
87 | {
|
---|
88 | wprintf(L"Error initializing COM (0x%x)\n", hr);
|
---|
89 | r = 1;
|
---|
90 | }
|
---|
91 |
|
---|
92 | VBoxNetCfgWinSetLogging(NULL);
|
---|
93 |
|
---|
94 | return r;
|
---|
95 | }
|
---|
96 |
|
---|
97 | int __cdecl main(int argc, char **argv)
|
---|
98 | {
|
---|
99 | return VBoxNetLwfUninstall();
|
---|
100 | }
|
---|