wmic: Improve cmd line parser and add support for path command.
Sebastian Lackner
sebastian at fds-team.de
Thu Oct 13 22:58:17 CDT 2016
From: Michael Müller <michael at fds-team.de>
Signed-off-by: Michael Müller <michael at fds-team.de>
Signed-off-by: Sebastian Lackner <sebastian at fds-team.de>
---
This allows to use more complicated command line arguments like
"wmic path Win32_Processor get name".
programs/wmic/main.c | 71 +++++++++++++++++++++++++++++++++++++++++---------
programs/wmic/wmic.h | 1
programs/wmic/wmic.rc | 1
3 files changed, 61 insertions(+), 12 deletions(-)
diff --git a/programs/wmic/main.c b/programs/wmic/main.c
index 5aee4c1..ddd2aec 100644
--- a/programs/wmic/main.c
+++ b/programs/wmic/main.c
@@ -162,7 +162,7 @@ static int output_message( int msg )
return output_string( fmtW, buffer );
}
-static int query_prop( const WCHAR *alias, const WCHAR *propname )
+static int query_prop( const WCHAR *class, const WCHAR *propname )
{
static const WCHAR select_allW[] = {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',0};
static const WCHAR cimv2W[] = {'R','O','O','T','\\','C','I','M','V','2',0};
@@ -175,18 +175,12 @@ static int query_prop( const WCHAR *alias, const WCHAR *propname )
IEnumWbemClassObject *result = NULL;
LONG flags = WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_FORWARD_ONLY;
BSTR path = NULL, wql = NULL, query = NULL;
- const WCHAR *class;
WCHAR *prop = NULL;
BOOL first = TRUE;
int len, ret = -1;
- WINE_TRACE("%s, %s\n", debugstr_w(alias), debugstr_w(propname));
+ WINE_TRACE("%s, %s\n", debugstr_w(class), debugstr_w(propname));
- if (!(class = find_class( alias )))
- {
- output_message( STRING_ALIAS_NOT_FOUND );
- return -1;
- }
CoInitialize( NULL );
CoInitializeSecurity( NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT,
RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL );
@@ -253,11 +247,64 @@ done:
int wmain(int argc, WCHAR *argv[])
{
static const WCHAR getW[] = {'g','e','t',0};
+ static const WCHAR quitW[] = {'q','u','i','t',0};
+ static const WCHAR exitW[] = {'e','x','i','t',0};
+ static const WCHAR pathW[] = {'p','a','t','h',0};
+ static const WCHAR classW[] = {'c','l','a','s','s',0};
+ static const WCHAR contextW[] = {'c','o','n','t','e','x','t',0};
+ const WCHAR *class, *value;
+ int i;
+
+ for (i = 1; i < argc && argv[i][0] == '/'; i++)
+ WINE_FIXME( "command line switch %s not supported\n", debugstr_w(argv[i]) );
+
+ if (i >= argc)
+ goto not_supported;
+
+ if (!strcmpiW( argv[i], quitW ) ||
+ !strcmpiW( argv[i], exitW ))
+ {
+ return 0;
+ }
- if (argc != 4 || strcmpiW( argv[2], getW ))
+ if (!strcmpiW( argv[i], classW) ||
+ !strcmpiW( argv[i], contextW ))
{
- output_message( STRING_CMDLINE_NOT_SUPPORTED );
- return -1;
+ WINE_FIXME( "command %s not supported\n", debugstr_w(argv[i]) );
+ goto not_supported;
+ }
+
+ if (!strcmpiW( argv[i], pathW ))
+ {
+ if (++i >= argc)
+ {
+ output_message( STRING_INVALID_PATH );
+ return 1;
+ }
+ class = argv[i];
}
- return query_prop( argv[1], argv[3] );
+ else
+ {
+ class = find_class( argv[i] );
+ if (!class)
+ {
+ output_message( STRING_ALIAS_NOT_FOUND );
+ return 1;
+ }
+ }
+
+ if (++i >= argc)
+ goto not_supported;
+
+ if (!strcmpiW( argv[i], getW ))
+ {
+ if (++i >= argc)
+ goto not_supported;
+ value = argv[i];
+ return query_prop( class, value );
+ }
+
+not_supported:
+ output_message( STRING_CMDLINE_NOT_SUPPORTED );
+ return 1;
}
diff --git a/programs/wmic/wmic.h b/programs/wmic/wmic.h
index ee56d8e..2727270 100644
--- a/programs/wmic/wmic.h
+++ b/programs/wmic/wmic.h
@@ -21,3 +21,4 @@
#define STRING_CMDLINE_NOT_SUPPORTED 101
#define STRING_ALIAS_NOT_FOUND 102
#define STRING_INVALID_QUERY 103
+#define STRING_INVALID_PATH 104
diff --git a/programs/wmic/wmic.rc b/programs/wmic/wmic.rc
index 54384fb..0789ef3 100644
--- a/programs/wmic/wmic.rc
+++ b/programs/wmic/wmic.rc
@@ -27,4 +27,5 @@ STRINGTABLE
STRING_CMDLINE_NOT_SUPPORTED, "Error: Command line not supported\n"
STRING_ALIAS_NOT_FOUND, "Error: Alias not found\n"
STRING_INVALID_QUERY, "Error: Invalid query\n"
+ STRING_INVALID_PATH, "Error: Invalid syntax for PATH\n"
}
--
2.9.0
More information about the wine-patches
mailing list