VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxBugReport/VBoxBugReportWin.cpp@ 59628

Last change on this file since 59628 was 59628, checked in by vboxsync, 9 years ago

BugReportTool(bugref:8169): Added querying event log, driver services, update history, introduced time stamp into default output name, fixed stream init bug

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.3 KB
Line 
1/* $Id: VBoxBugReportWin.cpp 59628 2016-02-10 12:32:24Z vboxsync $ */
2/** @file
3 * VBoxBugReportWin - VirtualBox command-line diagnostics tool,
4 * Windows-specific part.
5 */
6
7/*
8 * Copyright (C) 2006-2016 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19#include <VBox/com/com.h>
20#include <VBox/com/string.h>
21
22#include <iprt/cpp/exception.h>
23
24#include "VBoxBugReport.h"
25
26#include <netcfgx.h>
27#include <devguid.h>
28
29
30#define ReleaseAndReset(obj) \
31 if (obj) \
32 obj->Release(); \
33 obj = NULL;
34
35
36class BugReportNetworkAdaptersWin : public BugReportStream
37{
38public:
39 BugReportNetworkAdaptersWin() : BugReportStream("NetworkAdapters") {};
40 virtual ~BugReportNetworkAdaptersWin() {};
41 virtual PRTSTREAM getStream(void) { collect(); return BugReportStream::getStream(); };
42private:
43 struct CharacteristicsName
44 {
45 DWORD dwChar;
46 const char *szName;
47 };
48 void printCharteristics(DWORD dwChars);
49 void collect();
50 void collectNetCfgComponentInfo(int ident, bool fEnabled, INetCfgComponent *pComponent);
51};
52
53
54
55void BugReportNetworkAdaptersWin::printCharteristics(DWORD dwChars)
56{
57 static CharacteristicsName cMap[] =
58 {
59 { NCF_VIRTUAL, "virtual" },
60 { NCF_SOFTWARE_ENUMERATED, "software_enumerated" },
61 { NCF_PHYSICAL, "physical" },
62 { NCF_HIDDEN, "hidden" },
63 { NCF_NO_SERVICE, "no_service" },
64 { NCF_NOT_USER_REMOVABLE, "not_user_removable" },
65 { NCF_MULTIPORT_INSTANCED_ADAPTER, "multiport_instanced_adapter" },
66 { NCF_HAS_UI, "has_ui" },
67 { NCF_SINGLE_INSTANCE, "single_instance" },
68 { NCF_FILTER, "filter" },
69 { NCF_DONTEXPOSELOWER, "dontexposelower" },
70 { NCF_HIDE_BINDING, "hide_binding" },
71 { NCF_NDIS_PROTOCOL, "ndis_protocol" },
72 { NCF_FIXED_BINDING, "fixed_binding" },
73 { NCF_LW_FILTER, "lw_filter" }
74 };
75 bool fPrintDelim = false;
76
77 for (int i = 0; i < RT_ELEMENTS(cMap); ++i)
78 {
79 if (dwChars & cMap[i].dwChar)
80 {
81 if (fPrintDelim)
82 {
83 putStr(", ");
84 fPrintDelim = false;
85 }
86 putStr(cMap[i].szName);
87 fPrintDelim = true;
88 }
89 }
90}
91
92void BugReportNetworkAdaptersWin::collectNetCfgComponentInfo(int ident, bool fEnabled, INetCfgComponent *pComponent)
93{
94 LPWSTR pwszName = NULL;
95 HRESULT hr = pComponent->GetDisplayName(&pwszName);
96 if (FAILED(hr))
97 throw RTCError(com::Utf8StrFmt("Failed to get component display name, hr=0x%x.\n", hr));
98 printf("%s%c %ls [", RTCString(ident, ' ').c_str(), fEnabled ? '+' : '-', pwszName);
99 if (pwszName)
100 CoTaskMemFree(pwszName);
101
102 DWORD dwChars = 0;
103 hr = pComponent->GetCharacteristics(&dwChars);
104 if (FAILED(hr))
105 throw RTCError(com::Utf8StrFmt("Failed to get component characteristics, hr=0x%x.\n", hr));
106 printCharteristics(dwChars);
107 putStr("]\n");
108}
109
110void BugReportNetworkAdaptersWin::collect(void)
111{
112 INetCfg *pNetCfg = NULL;
113 IEnumNetCfgComponent *pEnumAdapters = NULL;
114 INetCfgComponent *pNetCfgAdapter = NULL;
115 INetCfgComponentBindings *pAdapterBindings = NULL;
116 IEnumNetCfgBindingPath *pEnumBp = NULL;
117 INetCfgBindingPath *pBp = NULL;
118 IEnumNetCfgBindingInterface *pEnumBi = NULL;
119 INetCfgBindingInterface *pBi = NULL;
120 INetCfgComponent *pUpperComponent = NULL;
121
122 try
123 {
124 HRESULT hr = CoCreateInstance(CLSID_CNetCfg, NULL, CLSCTX_INPROC_SERVER, IID_INetCfg, (PVOID*)&pNetCfg);
125 if (FAILED(hr))
126 throw RTCError(com::Utf8StrFmt("Failed to create instance of INetCfg, hr=0x%x.\n", hr));
127 hr = pNetCfg->Initialize(NULL);
128 if (FAILED(hr))
129 throw RTCError(com::Utf8StrFmt("Failed to initialize instance of INetCfg, hr=0x%x.\n", hr));
130
131 hr = pNetCfg->EnumComponents(&GUID_DEVCLASS_NET, &pEnumAdapters);
132 if (FAILED(hr))
133 throw RTCError(com::Utf8StrFmt("Failed enumerate network adapters, hr=0x%x.\n", hr));
134
135 hr = pEnumAdapters->Reset();
136 Assert(SUCCEEDED(hr));
137 do
138 {
139 hr = pEnumAdapters->Next(1, &pNetCfgAdapter, NULL);
140 if (hr == S_FALSE)
141 break;
142 if (hr != S_OK)
143 throw RTCError(com::Utf8StrFmt("Failed to get next network adapter, hr=0x%x.\n", hr));
144 hr = pNetCfgAdapter->QueryInterface(IID_INetCfgComponentBindings, (PVOID*)&pAdapterBindings);
145 if (FAILED(hr))
146 throw RTCError(com::Utf8StrFmt("Failed to query INetCfgComponentBindings, hr=0x%x.\n", hr));
147 hr = pAdapterBindings->EnumBindingPaths(EBP_ABOVE, &pEnumBp);
148 if (FAILED(hr))
149 throw RTCError(com::Utf8StrFmt("Failed to enumerate binding paths, hr=0x%x.\n", hr));
150 hr = pEnumBp->Reset();
151 if (FAILED(hr))
152 throw RTCError(com::Utf8StrFmt("Failed to reset enumeration of binding paths (0x%x)\n", hr));
153 do
154 {
155 hr = pEnumBp->Next(1, &pBp, NULL);
156 if (hr == S_FALSE)
157 break;
158 if (hr != S_OK)
159 throw RTCError(com::Utf8StrFmt("Failed to get next network adapter, hr=0x%x.\n", hr));
160 bool fBpEnabled;
161 hr = pBp->IsEnabled();
162 if (hr == S_FALSE)
163 fBpEnabled = false;
164 else if (hr != S_OK)
165 throw RTCError(com::Utf8StrFmt("Failed to check if bind path is enabled, hr=0x%x.\n", hr));
166 else
167 fBpEnabled = true;
168 hr = pBp->EnumBindingInterfaces(&pEnumBi);
169 if (FAILED(hr))
170 throw RTCError(com::Utf8StrFmt("Failed to enumerate binding interfaces (0x%x)\n", hr));
171 hr = pEnumBi->Reset();
172 if (FAILED(hr))
173 throw RTCError(com::Utf8StrFmt("Failed to reset enumeration of binding interfaces (0x%x)\n", hr));
174 int ident;
175 for (ident = 0;; ++ident)
176 {
177 hr = pEnumBi->Next(1, &pBi, NULL);
178 if (hr == S_FALSE)
179 break;
180 if (hr != S_OK)
181 throw RTCError(com::Utf8StrFmt("Failed to get next binding interface, hr=0x%x.\n", hr));
182 hr = pBi->GetUpperComponent(&pUpperComponent);
183 if (FAILED(hr))
184 throw RTCError(com::Utf8StrFmt("Failed to get upper component, hr=0x%x.\n", hr));
185 collectNetCfgComponentInfo(ident, fBpEnabled, pUpperComponent);
186 ReleaseAndReset(pUpperComponent);
187 ReleaseAndReset(pBi);
188 }
189 collectNetCfgComponentInfo(ident, fBpEnabled, pNetCfgAdapter);
190 ReleaseAndReset(pEnumBi);
191 ReleaseAndReset(pBp);
192 } while (true);
193
194 ReleaseAndReset(pEnumBp);
195 ReleaseAndReset(pAdapterBindings);
196 ReleaseAndReset(pNetCfgAdapter);
197 } while (true);
198 ReleaseAndReset(pEnumAdapters);
199 ReleaseAndReset(pNetCfg);
200 }
201
202 catch (RTCError &e)
203 {
204 ReleaseAndReset(pUpperComponent);
205 ReleaseAndReset(pBi);
206 ReleaseAndReset(pEnumBi);
207 ReleaseAndReset(pBp);
208 ReleaseAndReset(pEnumBp);
209 ReleaseAndReset(pAdapterBindings);
210 ReleaseAndReset(pNetCfgAdapter);
211 ReleaseAndReset(pEnumAdapters);
212 ReleaseAndReset(pNetCfg);
213 RTPrintf("ERROR in osCollect: %s\n", e.what());
214 throw;
215 }
216
217}
218
219void createBugReportOsSpecific(BugReport* report, const char *pszHome)
220{
221 TCHAR szWinDir[MAX_PATH];
222
223 int cbNeeded = GetWindowsDirectory(szWinDir, RT_ELEMENTS(szWinDir));
224 if (cbNeeded == 0)
225 throw RTCError(RTCStringFmt("Failed to get Windows directory (err=%d)\n", GetLastError()));
226 if (cbNeeded > MAX_PATH)
227 throw RTCError(RTCStringFmt("Failed to get Windows directory (needed %d-byte buffer)\n", cbNeeded));
228 RTCStringFmt WinInfDir("%ls/inf", szWinDir);
229 report->addItem(new BugReportFile(PathJoin(WinInfDir.c_str(), "setupapi.app.log"), "setupapi.app.log"));
230 report->addItem(new BugReportFile(PathJoin(WinInfDir.c_str(), "setupapi.dev.log"), "setupapi.dev.log"));
231 report->addItem(new BugReportNetworkAdaptersWin);
232 RTCStringFmt WinSysDir("%ls/System32", szWinDir);
233 report->addItem(new BugReportCommand("SystemEvents", PathJoin(WinSysDir.c_str(), "wevtutil.exe"),
234 "qe", "System", "/f:text",
235 "/q:*[System[Provider[@Name='VBoxUSBMon']]]", NULL));
236 report->addItem(new BugReportCommand("UpdateHistory", PathJoin(WinSysDir.c_str(), "wbem/wmic.exe"),
237 "qfe", "list", "brief", NULL));
238 report->addItem(new BugReportCommand("DriverServices", PathJoin(WinSysDir.c_str(), "sc.exe"),
239 "query", "type=", "driver", "state=", "all", NULL));
240}
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