-1

Okay here's the issue i want to call the wmic.exe that is found in \windows\system32\wbem execute a command and only read the output from there.

I don't want to use wmi using com as per msdn (http://msdn.microsoft.com/en-us/library/aa390423(v=vs.85).aspx) and i dont want to execute wmic through cmd.

And i can't get a way of making it work.I read this thread too but no one answered non-trivial use of `Console` by `wmic.exe`

I've tried something like this :

FILE* pipe = _popen("wmic.exe cpu get", "r"); 
if (!pipe) 
 throw std::exception("error"); 
char buffer[128]; 
std::string output; 
while(!feof(pipe)) 
{ 
 if(fgets(buffer, 128, pipe) != NULL) output += buffer; 
} 

_pclose(pipe); 
std::stringstream oss(output); 
std::vector<std::string> processor_description; 
std::string buffer; 
while (std::getline(oss, buffer)) 
  processor_description.push_back(buffer); 
Community
  • 1
  • 1
juniorcoder
  • 25
  • 2
  • 8

1 Answers1

0
Set WshShell = WScript.CreateObject("WScript.Shell")

Set wmic = WshShell.Exec("wmic cpu get")

Do While wmic.Status = 0

     WScript.Sleep 100

Loop



msgbox wmic.Status

     If Not wmic.StdOut.AtEndOfStream Then

          Msgbox wmic.StdOut.ReadAll

     End If

This is vbscript that works. You have access to same objects.

Remeber that wmic writes unicode nor OEM (cmd.exe) or ANSI (older GUI programs). If reading it as ansi there will probably be character conversions happening.

Noodles
  • 1,981
  • 1
  • 11
  • 4