ReactOS 0.4.17-dev-540-g8f54750
wmi.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS NetSh
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Network Shell WMI info functions
5 * COPYRIGHT: Copyright 2026 Eric Kohl <eric.kohl@reactos.org>
6 */
7
8/* INCLUDES *******************************************************************/
9
10#define COBJMACROS
11
12#include "precomp.h"
13
14#include <strsafe.h>
15#include <initguid.h>
16#include <objbase.h>
17#include <wbemcli.h>
18
19#define NDEBUG
20#include <debug.h>
21
22/* GLOBALS ********************************************************************/
23
31
32/* FUNCTIONS ******************************************************************/
33
34BOOL
36 _In_ PNS_OSVERSIONCHECK pfnOsVersionCheck)
37{
38 DPRINT("CheckOsVersion(%p)\n", pfnOsVersionCheck);
39
40 if (pfnOsVersionCheck == NULL)
41 return TRUE;
42
43 return pfnOsVersionCheck(VersionInfoOsType,
50 0);
51}
52
53static
57{
60 BSTR Wql = NULL;
61 BSTR Query = NULL;
62 BSTR Name;
66 HRESULT hr;
67
68 Wql = SysAllocString(L"WQL");
69 if (Wql == NULL)
70 return E_OUTOFMEMORY;
71
72 Query = SysAllocString(L"SELECT * FROM Win32_OperatingSystem");
73 if (Query == NULL)
74 {
76 goto done;
77 }
78
79 hr = IWbemServices_ExecQuery(Services, Wql, Query, 0, NULL, &Result);
80 if (hr != S_OK)
81 {
82 DPRINT1("IWbemServices_ExecQuery failed %08x\n", hr);
83 goto done;
84 }
85
86 hr = IEnumWbemClassObject_Next(Result, 10000, 1, &Object, &Count);
87 if (hr != S_OK)
88 {
89 DPRINT1("IEnumWbemClassObject_Next failed %08x\n", hr);
90 goto done;
91 }
92
93 hr = IWbemClassObject_BeginEnumeration(Object, 0);
94 if (hr != S_OK)
95 {
96 DPRINT1("IWbemClassObject_BeginEnumeration returned %08x\n", hr);
97 goto done;
98 }
99
100 while (IWbemClassObject_Next(Object, 0, &Name, &Value, &Type, NULL) == S_OK)
101 {
102 DPRINT("Name: %S\n", Name);
103 if (_wcsicmp(Name, L"BuildNumber") == 0)
104 {
105 DPRINT("BuildNumber %S\n", V_BSTR(&Value));
107 }
108 else if (_wcsicmp(Name, L"OSProductSuite") == 0)
109 {
110 DPRINT("OSProductSuite 0x%x\n", V_UINT(&Value));
112 }
113 else if (_wcsicmp(Name, L"OSType") == 0)
114 {
115 DPRINT("OSType %u\n", V_UINT(&Value));
117 }
118 else if (_wcsicmp(Name, L"ServicePackMajorVersion") == 0)
119 {
120 DPRINT("ServicePackMajorVersion %hu\n", V_UINT(&Value));
122 }
123 else if (_wcsicmp(Name, L"ServicePackMinorVersion") == 0)
124 {
125 DPRINT("ServicePackMinorVersion %hu\n", V_UINT(&Value));
127 }
128 else if (_wcsicmp(Name, L"Version") == 0)
129 {
130 DPRINT("Version %S\n", V_BSTR(&Value));
132 }
133
136 }
137
138 hr = IWbemClassObject_EndEnumeration(Object);
139 if (hr != S_OK)
140 {
141 DPRINT1("got %08x\n", hr);
142 goto done;
143 }
144
145done:
146 if (Object)
147 IWbemClassObject_Release(Object);
148
149 if (Result)
150 IEnumWbemClassObject_Release(Result);
151
152 if (Query)
154
155 if (Wql)
156 SysFreeString(Wql);
157
158 return hr;
159}
160
161
162static
166{
169 BSTR Wql = NULL;
170 BSTR Query = NULL;
171 BSTR Name;
173 ULONG Count;
175 HRESULT hr;
176
177 Wql = SysAllocString(L"WQL");
178 if (Wql == NULL)
179 return E_OUTOFMEMORY;
180
181 Query = SysAllocString(L"SELECT * FROM Win32_Processor");
182 if (Query == NULL)
183 {
185 goto done;
186 }
187
188 hr = IWbemServices_ExecQuery(Services, Wql, Query, 0, NULL, &Result);
189 if (hr != S_OK)
190 {
191 DPRINT1("IWbemServices_ExecQuery failed %08x\n", hr);
192 goto done;
193 }
194
195 hr = IEnumWbemClassObject_Next(Result, 10000, 1, &Object, &Count);
196 if (hr != S_OK)
197 {
198 DPRINT1("IEnumWbemClassObject_Next failed %08x\n", hr);
199 goto done;
200 }
201
202 hr = IWbemClassObject_BeginEnumeration(Object, 0);
203 if (hr != S_OK)
204 {
205 DPRINT1("IWbemClassObject_BeginEnumeration returned %08x\n", hr);
206 goto done;
207 }
208
209 while (IWbemClassObject_Next(Object, 0, &Name, &Value, &Type, NULL) == S_OK)
210 {
211 DPRINT("Name: %S\n", Name);
212 if (_wcsicmp(Name, L"Architecture") == 0)
213 {
214 DPRINT("Architecture %u\n", V_UINT(&Value));
216 }
217
220 }
221
222 hr = IWbemClassObject_EndEnumeration(Object);
223 if (hr != S_OK)
224 {
225 DPRINT1("got %08x\n", hr);
226 goto done;
227 }
228
229done:
230 if (Object)
231 IWbemClassObject_Release(Object);
232
233 if (Result)
234 IEnumWbemClassObject_Release(Result);
235
236 if (Query)
238
239 if (Wql)
240 SysFreeString(Wql);
241
242 return hr;
243}
244
247{
248 BSTR Path = NULL;
249 IWbemLocator *Locator = NULL;
251 HRESULT hr;
252
254
257 hr = CoCreateInstance(&CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER,
258 &IID_IWbemLocator, (void **)&Locator);
259 if (hr != S_OK)
260 {
261 DPRINT1("Can't create instance of WbemLocator\n");
262 return hr;
263 }
264
265 Path = SysAllocString(L"ROOT\\CIMV2");
266 if (Path == NULL)
267 {
269 goto done;
270 }
271
272 hr = IWbemLocator_ConnectServer(Locator, Path, NULL, NULL, NULL, 0, NULL, NULL, &Services);
273 if (hr != S_OK)
274 {
275 DPRINT1("Failed to get IWbemServices interface %08x\n", hr);
276 goto done;
277 }
278
281 if (hr != S_OK)
282 {
283 DPRINT1("Failed to set proxy blanket %08x\n", hr);
284 goto done;
285 }
286
288 if (hr == S_OK)
290
291done:
292 if (Path)
294
295 if (Services)
296 IWbemServices_Release(Services);
297
298 if (Locator)
299 IWbemLocator_Release(Locator);
300
302
303 return hr;
304}
PRTL_UNICODE_STRING_BUFFER Path
Type
Definition: Type.h:7
WCHAR VersionInfoBuildNumber[MAX_PATH]
Definition: wmi.c:28
static HRESULT QueryOperatingSystemInfo(_In_ IWbemServices *Services)
Definition: wmi.c:55
static HRESULT QueryProcessorInfo(_In_ IWbemServices *Services)
Definition: wmi.c:164
UINT VersionInfoArchitecture
Definition: wmi.c:24
WCHAR VersionInfoVersion[MAX_PATH]
Definition: wmi.c:27
WCHAR VersionInfoServicePackMinorVersion[MAX_PATH]
Definition: wmi.c:30
UINT VersionInfoOsProductSuite
Definition: wmi.c:25
BOOL CheckOsVersion(_In_ PNS_OSVERSIONCHECK pfnOsVersionCheck)
Definition: wmi.c:35
HRESULT GetWmiVersionInfo(VOID)
Definition: wmi.c:246
UINT VersionInfoOsType
Definition: wmi.c:26
WCHAR VersionInfoServicePackMajorVersion[MAX_PATH]
Definition: wmi.c:29
#define DPRINT1
Definition: precomp.h:8
BOOL Query(LPCTSTR *ServiceArgs, DWORD ArgCount, BOOL bExtended)
Definition: query.c:292
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
HRESULT hr
Definition: delayimp.cpp:582
LPWSTR Name
Definition: desk.c:124
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
HRESULT WINAPI CoSetProxyBlanket(IUnknown *proxy, DWORD authn_service, DWORD authz_service, OLECHAR *servername, DWORD authn_level, DWORD imp_level, void *auth_info, DWORD capabilities)
Definition: combase.c:1055
HRESULT WINAPI CoInitializeSecurity(PSECURITY_DESCRIPTOR sd, LONG cAuthSvc, SOLE_AUTHENTICATION_SERVICE *asAuthSvc, void *reserved1, DWORD authn_level, DWORD imp_level, void *reserved2, DWORD capabilities, void *reserved3)
Definition: combase.c:1163
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: combase.c:2842
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, IUnknown *outer, DWORD cls_context, REFIID riid, void **obj)
Definition: combase.c:1685
OLECHAR * BSTR
Definition: compat.h:2293
#define MAX_PATH
Definition: compat.h:34
_ACRTIMP int __cdecl _wcsicmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:164
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:531
#define L(x)
Definition: resources.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned int UINT
Definition: sysinfo.c:13
#define S_OK
Definition: intsafe.h:52
#define _swprintf(buf, format,...)
Definition: sprintf.c:56
NS_OSVERSIONCHECK * PNS_OSVERSIONCHECK
Definition: netsh.h:132
#define _In_
Definition: no_sal2.h:158
int Count
Definition: noreturn.cpp:7
BSTR WINAPI SysAllocString(LPCOLESTR str)
Definition: oleaut.c:240
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:273
#define V_BSTR(A)
Definition: oleauto.h:226
#define V_UINT(A)
Definition: oleauto.h:264
short WCHAR
Definition: pedump.c:58
#define RPC_C_AUTHZ_NONE
Definition: rpcdce.h:167
#define RPC_C_AUTHN_LEVEL_DEFAULT
Definition: rpcdce.h:145
#define RPC_C_AUTHN_LEVEL_CALL
Definition: rpcdce.h:148
#define RPC_C_IMP_LEVEL_IMPERSONATE
Definition: rpcdce.h:176
#define RPC_C_AUTHN_WINNT
Definition: rpcdce.h:158
#define DPRINT
Definition: sndvol32.h:73
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166
static SERVICES Services[NUM_SERVICES]
Definition: tcpsvcs.c:26
uint32_t ULONG
Definition: typedefs.h:59
HRESULT WINAPI DECLSPEC_HOTPATCH VariantClear(VARIANTARG *pVarg)
Definition: variant.c:626
long CIMTYPE
Definition: wbemcli.idl:258
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409