ReactOS 0.4.16-dev-319-g6cf4263
main.c File Reference
#include <stdio.h>
#include "windows.h"
#include "ocidl.h"
#include "initguid.h"
#include "objidl.h"
#include "wbemcli.h"
#include "wmic.h"
#include "wine/debug.h"
#include "wine/unicode.h"
Include dependency graph for main.c:

Go to the source code of this file.

Macros

#define COBJMACROS
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (wmic)
 
static const WCHARfind_class (const WCHAR *alias)
 
static WCHARstrdupW (const WCHAR *src)
 
static WCHARfind_prop (IWbemClassObject *class, const WCHAR *prop)
 
static int output_string (HANDLE handle, const WCHAR *msg,...)
 
static int output_error (int msg)
 
static int output_header (const WCHAR *prop, ULONG column_width)
 
static int output_line (const WCHAR *str, ULONG column_width)
 
static int query_prop (const WCHAR *class, const WCHAR *propname)
 
int wmain (int argc, WCHAR *argv[])
 

Variables

static const WCHAR biosW []
 
static const WCHAR computersystemW []
 
static const WCHAR cpuW []
 
static const WCHAR logicaldiskW []
 
static const WCHAR nicW []
 
static const WCHAR osW []
 
static const WCHAR processW []
 
static const WCHAR win32_biosW []
 
static const WCHAR win32_computersystemW []
 
static const WCHAR win32_logicaldiskW []
 
static const WCHAR win32_networkadapterW []
 
static const WCHAR win32_operatingsystemW []
 
static const WCHAR win32_processW []
 
static const WCHAR win32_processorW []
 
struct {
   const WCHAR *   alias
 
   const WCHAR *   class
 
alias_map []
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 20 of file main.c.

Function Documentation

◆ find_class()

static const WCHAR * find_class ( const WCHAR alias)
static

Definition at line 81 of file main.c.

82{
83 unsigned int i;
84
85 for (i = 0; i < ARRAY_SIZE(alias_map); i++)
86 {
87 if (!strcmpiW( alias, alias_map[i].alias )) return alias_map[i].class;
88 }
89 return NULL;
90}
const WCHAR * alias
Definition: main.c:67
static const struct @5 alias_map[]
#define ARRAY_SIZE(A)
Definition: main.h:20
#define NULL
Definition: types.h:112
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define strcmpiW(s1, s2)
Definition: unicode.h:45

Referenced by wmain().

◆ find_prop()

static WCHAR * find_prop ( IWbemClassObject class,
const WCHAR prop 
)
static

Definition at line 101 of file main.c.

102{
103 SAFEARRAY *sa;
104 WCHAR *ret = NULL;
105 LONG i, last_index = 0;
106 BSTR str;
107
108 if (IWbemClassObject_GetNames( class, NULL, WBEM_FLAG_ALWAYS, NULL, &sa ) != S_OK) return NULL;
109
110 SafeArrayGetUBound( sa, 1, &last_index );
111 for (i = 0; i <= last_index; i++)
112 {
114 if (!strcmpiW( str, prop ))
115 {
116 ret = strdupW( str );
117 break;
118 }
119 }
121 return ret;
122}
static struct sockaddr_in sa
Definition: adnsresfilter.c:69
static WCHAR * strdupW(const WCHAR *src)
Definition: main.c:92
OLECHAR * BSTR
Definition: compat.h:2293
HRESULT WINAPI SafeArrayGetUBound(SAFEARRAY *psa, UINT nDim, LONG *plUbound)
Definition: safearray.c:1033
HRESULT WINAPI SafeArrayGetElement(SAFEARRAY *psa, LONG *rgIndices, void *pvData)
Definition: safearray.c:947
HRESULT WINAPI SafeArrayDestroy(SAFEARRAY *psa)
Definition: safearray.c:1347
#define S_OK
Definition: intsafe.h:52
long LONG
Definition: pedump.c:60
const WCHAR * str
@ WBEM_FLAG_ALWAYS
Definition: wbemcli.idl:194
int ret
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by query_prop().

◆ output_error()

static int output_error ( int  msg)
static

Definition at line 141 of file main.c.

142{
143 static const WCHAR fmtW[] = {'%','s',0};
144 WCHAR buffer[8192];
145
148}
#define msg(x)
Definition: auth_time.c:54
static int output_string(HANDLE handle, const WCHAR *msg,...)
Definition: main.c:124
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:203
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
GLuint buffer
Definition: glext.h:5915
#define STD_ERROR_HANDLE
Definition: winbase.h:295
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)

Referenced by query_prop(), and wmain().

◆ output_header()

static int output_header ( const WCHAR prop,
ULONG  column_width 
)
static

Definition at line 150 of file main.c.

151{
152 static const WCHAR bomW[] = {0xfeff}, fmtW[] = {'%','-','*','s','\r','\n',0};
153 int len;
154 DWORD count;
155 WCHAR buffer[8192];
156
157 len = snprintfW( buffer, ARRAY_SIZE(buffer), fmtW, column_width, prop );
158
159 if (!WriteConsoleW( GetStdHandle(STD_OUTPUT_HANDLE), buffer, len, &count, NULL )) /* redirected */
160 {
161 WriteFile( GetStdHandle(STD_OUTPUT_HANDLE), bomW, sizeof(bomW), &count, FALSE );
163 count += sizeof(bomW);
164 }
165
166 return count;
167}
#define FALSE
Definition: types.h:117
BOOL WINAPI DECLSPEC_HOTPATCH WriteConsoleW(IN HANDLE hConsoleOutput, IN CONST VOID *lpBuffer, IN DWORD nNumberOfCharsToWrite, OUT LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved)
Definition: readwrite.c:1447
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLenum GLsizei len
Definition: glext.h:6722
#define snprintfW
Definition: unicode.h:66
#define STD_OUTPUT_HANDLE
Definition: winbase.h:294

Referenced by query_prop(), and test_encode().

◆ output_line()

static int output_line ( const WCHAR str,
ULONG  column_width 
)
static

Definition at line 169 of file main.c.

170{
171 static const WCHAR fmtW[] = {'%','-','*','s','\r','\n',0};
172 return output_string( GetStdHandle(STD_OUTPUT_HANDLE), fmtW, column_width, str );
173}

Referenced by query_prop().

◆ output_string()

static int output_string ( HANDLE  handle,
const WCHAR msg,
  ... 
)
static

Definition at line 124 of file main.c.

125{
126 va_list va_args;
127 int len;
128 DWORD count;
129 WCHAR buffer[8192];
130
131 va_start( va_args, msg );
132 len = vsnprintfW( buffer, ARRAY_SIZE(buffer), msg, va_args );
133 va_end( va_args );
134
136 WriteFile( handle, buffer, len * sizeof(WCHAR), &count, FALSE );
137
138 return count;
139}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define vsnprintfW
Definition: unicode.h:67

Referenced by output_error(), and output_line().

◆ query_prop()

static int query_prop ( const WCHAR class,
const WCHAR propname 
)
static

Definition at line 175 of file main.c.

176{
177 static const WCHAR select_allW[] = {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',0};
178 static const WCHAR cimv2W[] = {'R','O','O','T','\\','C','I','M','V','2',0};
179 static const WCHAR wqlW[] = {'W','Q','L',0};
180 HRESULT hr;
185 BSTR path = NULL, wql = NULL, query = NULL;
186 WCHAR *prop = NULL;
187 BOOL first = TRUE;
188 int len, ret = -1;
190 ULONG count, width = 0;
191 VARIANT v;
192
193 WINE_TRACE("%s, %s\n", debugstr_w(class), debugstr_w(propname));
194
198
199 hr = CoCreateInstance( &CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemLocator,
200 (void **)&locator );
201 if (hr != S_OK) goto done;
202
203 if (!(path = SysAllocString( cimv2W ))) goto done;
204 hr = IWbemLocator_ConnectServer( locator, path, NULL, NULL, NULL, 0, NULL, NULL, &services );
205 if (hr != S_OK) goto done;
206
207 len = strlenW( class ) + ARRAY_SIZE(select_allW);
208 if (!(query = SysAllocStringLen( NULL, len ))) goto done;
209 strcpyW( query, select_allW );
210 strcatW( query, class );
211
212 if (!(wql = SysAllocString( wqlW ))) goto done;
213 hr = IWbemServices_ExecQuery( services, wql, query, flags, NULL, &result );
214 if (hr != S_OK) goto done;
215
216 for (;;) /* get column width */
217 {
218 IEnumWbemClassObject_Next( result, WBEM_INFINITE, 1, &obj, &count );
219 if (!count) break;
220
221 if (!prop && !(prop = find_prop( obj, propname )))
222 {
224 goto done;
225 }
226 if (IWbemClassObject_Get( obj, prop, 0, &v, NULL, NULL ) == WBEM_S_NO_ERROR)
227 {
228 VariantChangeType( &v, &v, 0, VT_BSTR );
229 width = max( strlenW( V_BSTR( &v ) ), width );
230 VariantClear( &v );
231 }
232 IWbemClassObject_Release( obj );
233 }
234 width += 2;
235
236 IEnumWbemClassObject_Reset( result );
237 for (;;)
238 {
239 IEnumWbemClassObject_Next( result, WBEM_INFINITE, 1, &obj, &count );
240 if (!count) break;
241
242 if (first)
243 {
244 output_header( prop, width );
245 first = FALSE;
246 }
247 if (IWbemClassObject_Get( obj, prop, 0, &v, NULL, NULL ) == WBEM_S_NO_ERROR)
248 {
249 VariantChangeType( &v, &v, 0, VT_BSTR );
250 output_line( V_BSTR( &v ), width );
251 VariantClear( &v );
252 }
253 IWbemClassObject_Release( obj );
254 }
255 ret = 0;
256
257done:
258 if (result) IEnumWbemClassObject_Release( result );
259 if (services) IWbemServices_Release( services );
260 if (locator) IWbemLocator_Release( locator );
263 SysFreeString( wql );
264 HeapFree( GetProcessHeap(), 0, prop );
266 return ret;
267}
static int output_error(int msg)
Definition: main.c:141
static int output_line(const WCHAR *str, ULONG column_width)
Definition: main.c:169
static WCHAR * find_prop(IWbemClassObject *class, const WCHAR *prop)
Definition: main.c:101
static int output_header(const WCHAR *prop, ULONG column_width)
Definition: main.c:150
#define TRUE
Definition: types.h:120
#define GetProcessHeap()
Definition: compat.h:736
#define HeapFree(x, y, z)
Definition: compat.h:735
@ VT_BSTR
Definition: compat.h:2303
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1964
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
HRESULT WINAPI CoInitializeSecurity(PSECURITY_DESCRIPTOR pSecDesc, LONG cAuthSvc, SOLE_AUTHENTICATION_SERVICE *asAuthSvc, void *pReserved1, DWORD dwAuthnLevel, DWORD dwImpLevel, void *pReserved2, DWORD dwCapabilities, void *pReserved3)
Definition: compobj.c:4122
unsigned int BOOL
Definition: ntddk_ex.h:94
const GLdouble * v
Definition: gl.h:2040
GLint GLint GLsizei width
Definition: gl.h:1546
GLbitfield flags
Definition: glext.h:7161
const GLint * first
Definition: glext.h:5794
GLuint64EXT * result
Definition: glext.h:11304
#define debugstr_w
Definition: kernel32.h:32
static const WCHAR wqlW[]
Definition: query.c:30
BSTR WINAPI SysAllocString(LPCOLESTR str)
Definition: oleaut.c:238
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:271
BSTR WINAPI SysAllocStringLen(const OLECHAR *str, unsigned int len)
Definition: oleaut.c:339
#define V_BSTR(A)
Definition: oleauto.h:226
#define strlenW(s)
Definition: unicode.h:34
#define strcatW(d, s)
Definition: unicode.h:36
#define strcpyW(d, s)
Definition: unicode.h:35
#define RPC_C_AUTHN_LEVEL_DEFAULT
Definition: rpcdce.h:145
#define RPC_C_IMP_LEVEL_IMPERSONATE
Definition: rpcdce.h:176
#define WINE_TRACE
Definition: debug.h:354
HRESULT hr
Definition: shlfolder.c:183
#define max(a, b)
Definition: svc.c:63
uint32_t ULONG
Definition: typedefs.h:59
HRESULT WINAPI DECLSPEC_HOTPATCH VariantChangeType(VARIANTARG *pvargDest, VARIANTARG *pvargSrc, USHORT wFlags, VARTYPE vt)
Definition: variant.c:962
HRESULT WINAPI DECLSPEC_HOTPATCH VariantClear(VARIANTARG *pVarg)
Definition: variant.c:648
@ WBEM_FLAG_RETURN_IMMEDIATELY
Definition: wbemcli.idl:325
@ WBEM_FLAG_FORWARD_ONLY
Definition: wbemcli.idl:326
@ WBEM_INFINITE
Definition: wbemcli.idl:189
@ WBEM_S_NO_ERROR
Definition: wbemcli.idl:37
#define STRING_INVALID_QUERY
Definition: wmic.h:23

Referenced by wmain().

◆ strdupW()

static WCHAR * strdupW ( const WCHAR src)
inlinestatic

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( wmic  )

◆ wmain()

int wmain ( int  argc,
WCHAR argv[] 
)

Definition at line 269 of file main.c.

270{
271 static const WCHAR getW[] = {'g','e','t',0};
272 static const WCHAR quitW[] = {'q','u','i','t',0};
273 static const WCHAR exitW[] = {'e','x','i','t',0};
274 static const WCHAR pathW[] = {'p','a','t','h',0};
275 static const WCHAR classW[] = {'c','l','a','s','s',0};
276 static const WCHAR contextW[] = {'c','o','n','t','e','x','t',0};
277 const WCHAR *class, *value;
278 int i;
279
280 for (i = 1; i < argc && argv[i][0] == '/'; i++)
281 WINE_FIXME( "command line switch %s not supported\n", debugstr_w(argv[i]) );
282
283 if (i >= argc)
284 goto not_supported;
285
286 if (!strcmpiW( argv[i], quitW ) ||
287 !strcmpiW( argv[i], exitW ))
288 {
289 return 0;
290 }
291
292 if (!strcmpiW( argv[i], classW) ||
293 !strcmpiW( argv[i], contextW ))
294 {
295 WINE_FIXME( "command %s not supported\n", debugstr_w(argv[i]) );
296 goto not_supported;
297 }
298
299 if (!strcmpiW( argv[i], pathW ))
300 {
301 if (++i >= argc)
302 {
304 return 1;
305 }
306 class = argv[i];
307 }
308 else
309 {
310 class = find_class( argv[i] );
311 if (!class)
312 {
314 return 1;
315 }
316 }
317
318 if (++i >= argc)
319 goto not_supported;
320
321 if (!strcmpiW( argv[i], getW ))
322 {
323 if (++i >= argc)
324 goto not_supported;
325 value = argv[i];
326 return query_prop( class, value );
327 }
328
329not_supported:
331 return 1;
332}
static int argc
Definition: ServiceArgs.c:12
static int query_prop(const WCHAR *class, const WCHAR *propname)
Definition: main.c:175
static const WCHAR * find_class(const WCHAR *alias)
Definition: main.c:81
static const WCHAR getW[]
Definition: object.c:50
#define argv
Definition: mplay32.c:18
#define WINE_FIXME
Definition: debug.h:366
Definition: pdh_main.c:94
static const WCHAR classW[]
Definition: lex.c:40
static const WCHAR exitW[]
Definition: lex.c:52
#define STRING_ALIAS_NOT_FOUND
Definition: wmic.h:22
#define STRING_CMDLINE_NOT_SUPPORTED
Definition: wmic.h:21
#define STRING_INVALID_PATH
Definition: wmic.h:24

Variable Documentation

◆ alias

◆ 

const struct { ... } alias_map[]
Initial value:
=
{
}
static const WCHAR win32_networkadapterW[]
Definition: main.c:56
static const WCHAR processW[]
Definition: main.c:47
static const WCHAR nicW[]
Definition: main.c:43
static const WCHAR win32_operatingsystemW[]
Definition: main.c:58
static const WCHAR computersystemW[]
Definition: main.c:37
static const WCHAR biosW[]
Definition: main.c:35
static const WCHAR win32_processW[]
Definition: main.c:60
static const WCHAR cpuW[]
Definition: main.c:39
static const WCHAR logicaldiskW[]
Definition: main.c:41
static const WCHAR win32_biosW[]
Definition: main.c:50
static const WCHAR win32_processorW[]
Definition: main.c:62
static const WCHAR win32_computersystemW[]
Definition: main.c:52
static const WCHAR win32_logicaldiskW[]
Definition: main.c:54
static const WCHAR osW[]
Definition: main.c:45

Referenced by find_class().

◆ biosW

const WCHAR biosW[]
static
Initial value:
=
{'b','i','o','s',0}

Definition at line 35 of file main.c.

Referenced by test_ParseDisplayName().

◆ class

◆ computersystemW

const WCHAR computersystemW[]
static
Initial value:
=
{'c','o','m','p','u','t','e','r','s','y','s','t','e','m',0}

Definition at line 37 of file main.c.

◆ cpuW

const WCHAR cpuW[]
static
Initial value:
=
{'c','p','u',0}

Definition at line 39 of file main.c.

◆ logicaldiskW

const WCHAR logicaldiskW[]
static
Initial value:
=
{'L','o','g','i','c','a','l','D','i','s','k',0}

Definition at line 41 of file main.c.

◆ nicW

const WCHAR nicW[]
static
Initial value:
=
{'n','i','c',0}

Definition at line 43 of file main.c.

◆ osW

const WCHAR osW[]
static
Initial value:
=
{'o','s',0}

Definition at line 45 of file main.c.

◆ processW

const WCHAR processW[]
static
Initial value:
=
{'p','r','o','c','e','s','s',0}

Definition at line 47 of file main.c.

Referenced by test_Win32_Process().

◆ win32_biosW

const WCHAR win32_biosW[]
static
Initial value:
=
{'W','i','n','3','2','_','B','I','O','S',0}

Definition at line 50 of file main.c.

◆ win32_computersystemW

const WCHAR win32_computersystemW[]
static
Initial value:
=
{'W','i','n','3','2','_','C','o','m','p','u','t','e','r','S','y','s','t','e','m',0}

Definition at line 52 of file main.c.

◆ win32_logicaldiskW

const WCHAR win32_logicaldiskW[]
static
Initial value:
=
{'W','i','n','3','2','_','L','o','g','i','c','a','l','D','i','s','k',0}

Definition at line 54 of file main.c.

◆ win32_networkadapterW

const WCHAR win32_networkadapterW[]
static
Initial value:
=
{'W','i','n','3','2','_','N','e','t','w','o','r','k','A','d','a','p','t','e','r',0}

Definition at line 56 of file main.c.

◆ win32_operatingsystemW

const WCHAR win32_operatingsystemW[]
static
Initial value:
=
{'W','i','n','3','2','_','O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0}

Definition at line 58 of file main.c.

◆ win32_processorW

const WCHAR win32_processorW[]
static
Initial value:
=
{'W','i','n','3','2','_','P','r','o','c','e','s','s','o','r',0}

Definition at line 62 of file main.c.

◆ win32_processW

const WCHAR win32_processW[]
static
Initial value:
=
{'W','i','n','3','2','_','P','r','o','c','e','s','s',0}

Definition at line 60 of file main.c.