I am having some problems in wmic tool. I need to use it a java script to run WShell.run("wmic process where name="ASDF.exe" get CommandLine,Processid,Caption,CSName and I need that the result will return back to my javascript where I ran it.

1) How can I make that ? 2) Is it a way to get it formatted or in a some kind of a collection ?

Thanks

link|improve this question
feedback

closed as off topic by ChrisF, grawity, random Jan 24 at 14:38

Questions on Super User are expected to generally relate to computer software or computer hardware, within the scope defined in the faq.

1 Answer

Do not use wmic for that. You can access WMI from wscript directly:

var computer = ".";
var wmi = GetObject("winmgmts:\\\\"+computer+"\\root\\CIMV2");

var wbemFlagReturnImmediately   = 0x10;
var wbemFlagForwardOnly     = 0x20;

var queryFlags = wbemFlagReturnImmediately | wbemFlagForwardOnly;
var items = wmi.ExecQuery("SELECT * \
            FROM Win32_Process \
            WHERE Name = 'notepad2.exe' \
            OR Name = 'cmd.exe'", "WQL", queryFlags);

var enumItems = new Enumerator(items);
for (; !enumItems.atEnd(); enumItems.moveNext()) {
    var item = enumItems.item();

    WScript.Echo("CommandLine: " + item.CommandLine);
    WScript.Echo("Description: " + item.Description);
    WScript.Echo("ExecutablePath: " + item.ExecutablePath);
    WScript.Echo("Name: " + item.Name);
    WScript.Echo("ProcessId: " + item.ProcessId);
    WScript.Echo("SessionId: " + item.SessionId);
    WScript.Echo("");
}
link|improve this answer
Yes, I had some problems in WMI on my system, this is the reason I can't use it, it doesn't update all parts of the tables – Big Leonardo Jan 26 at 8:53
So if you're saying you cannot use WMI, why are you trying to use wmic?? – grawity Jan 26 at 12:55
yes, this is right – Big Leonardo Feb 16 at 9:51
feedback

Not the answer you're looking for? Browse other questions tagged or ask your own question.