No announcement yet.

How to capture wmic output

  • Filter
  • Time
  • Show
Clear All
new posts

  • How to capture wmic output

    I'd like to get the "wmic csproduct get name, identifyingnumber" and use the output as a variable
    What's the easiest way of getting that wmic output and being able to use it in AMS ?

  • #2
    The sample provided in my apz-demo (Unique Harware IDs via WMIC) at Post-5 in the "Creating a unique ID" thread which you initiated is probably the easiest way to do it.

    You could also do it via the LuaCOM plugin but is unnecessarily complicated. The only other way to pipe in an Std.Out string from the command-line, directly into AMS (ie. without writing to a temp file) is via Lua's IO library, using the io.popen() function. This function opens a pipe to the parent program and returns a file handle from which data can be read back into Lua. However there in no way to suppress the command window with this method and is therefore ill-advised.

    I can simplify my code in the aforementioned sample for you but you'll still need the CommandLine plugin. I'd also advise leaving in the StatusDialog code (or using a callback function for a ProgressObject) because if a prior WMIC query has never been run on the target-system, it can take quite some seconds for the Std.Out string to be returned.

    Anyway, to strip the function back to its absolute simplest form, this is the bare minimum you'd require:

    local sWMIC = ("wmic csproduct get name, identifyingnumber"); 
    local tWMIC = CommandLine.Execute(sWMIC, 0);
    Dialog.Message("Output", tWMIC.StdOut);
    Nb. Don't forget the plugin (or what I advised about the StatusDialog).