Skip to content

Commit d69f179

Browse files
committed
.
1 parent 3fc8a18 commit d69f179

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

BatteryQuery/DellBattery.hpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,24 @@ class DellBattery {
118118
std::wstring tagStr = devInstPath.substr(tagIdx + 1);
119119
m_battery_tag = _wtoi(tagStr.c_str());
120120
}
121+
}
121122

122-
m_wbem = ConnectToNamespace(L"root\\WMI");
123+
void Initialize(const std::wstring& devName) {
124+
if (!m_battery_tag)
125+
return;
123126

124-
const CComBSTR DellWMIClass = L"DDVWmiMethodFunction";
125-
if (IsUserAnAdmin())
126-
m_ddv_inst = GetInstanceReference(*m_wbem, DellWMIClass); // will fail unless running as Admin
127-
else
127+
if (devName.find(L"DELL") == std::wstring::npos)
128+
return; // not a Dell battery
129+
130+
if (!IsUserAnAdmin()) {
128131
wprintf(L"WARNING: Not running as Administrator. Some Dell battery parameters will not be available.\n");
132+
return; // not running as Admin
133+
}
134+
135+
m_wbem = ConnectToNamespace(L"root\\WMI");
129136

137+
const CComBSTR DellWMIClass = L"DDVWmiMethodFunction";
138+
m_ddv_inst = GetInstanceReference(*m_wbem, DellWMIClass); // will fail unless running as Admin
130139
if (m_ddv_inst)
131140
CHECK(m_wbem->GetObject(DellWMIClass, 0, NULL, &m_ddv_class, NULL));
132141
}

BatteryQuery/Main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ int AccessBattery(const std::wstring& devInstPath, bool verbose, unsigned int ne
116116
wprintf(L"\n");
117117
{
118118
BatteryParameters params(battery.Get());
119+
dellBatt.Initialize(params.DeviceName);
119120

120121
wprintf(L"Battery information fields:\n");
121122

0 commit comments

Comments
 (0)