matthias
matthias

Reputation: 247

Check if WMIC is installed, writing data into files from batch file

I am using the Windows Management Instrumentation Command-line (WMIC) for reading data from a computer like it's Hardware components and IP settings.

As I am using a batch file (Windows) for filling files for each computer/node with data the query logic is implemented there. So far it has been working quite good on my computer and others I have tried on.

The problem is on computers where the WMIC has not been used before, it's neccessary to (automatically) be installed at the first query/execution. This is why the console program prints out "Please wait while WMIC is being installed".

As I am writing to my file this is a problem: I don't want to have this string in it. Another problem is, that if the string is output it crashes all my file. "Please wait while WMIC is being installed" is represented in ASCII, the results of the data queries are somehow written as ASCII characters with leading zeros (multi-byte character set? unicode? ...).

Does someone know how to check if WMIC is alread installed? Or: how to ignore the string? Or: do I really have to implement a converter in my file viewer which checks for the string/ character set?

Upvotes: 3

Views: 3100

Answers (1)

Joey
Joey

Reputation: 354694

Since that is only printed on the very first run of WMIC, you can just make two calls. One dummy one to eat away the string:

wmic foo >nul 2>&1

and after that what you actually wanted to execute.

Upvotes: 3

Related Questions