I'm trying to execute a hidden process to retrieve the output.
For this task I'm trying to use Exec method but the problem that I see is that I can't hide the process window?.
I've seen an alternative way using Run method to start the process hidden, and then writting the output to a textfile, and then parsing the text content, but that It's not what I'm looking for 'cause I always try to avoid bad programming practices in other languages so I would like to know if this operation in VBS can be performed without managing the creation of external text files, just I want to simplify things and don't create textfiles.
Here is my code:
Response = CreateObject("WScript.Shell"). _
Exec("powercfg.exe /GetActiveScheme"). _
StdOut.ReadAll
PowerPlanName = Split(Split(Response, "(")(1), ")")(0)
PowerPlanGUID = Split(Split(Response, ":")(1))(1)
Msgbox "Information about the current energy scheme." & vbNewLine & vbNewLine & _
"Name: " & PowerPlanName & vbNewLine & _
"GUID: " & PowerPlanGUID, _
64, _
"Energy scheme (powercfg.exe)"
WScript.Quit(0)
Unlike Run, Exec does not allow you to hide the window.
Exec Method: http://msdn.microsoft.com/en-us/library/ateytk4a(v=vs.84).aspx
Run Method: http://msdn.microsoft.com/en-us/library/d5fk67ky(v=vs.84).aspx
However, capturing data in a temp file isn't a bad practice. In your case, using Run and dumping into a temp file is probably your best option with what you're trying to do.