Re: OLE error

Tech-Archive recommends: Fix windows errors by optimizing your registry



? ---snip---
I contacted the person that created the above user-defined function
but she said that she didn't know enough about Wscript to figure out
why trying to have it run wmic would cause this Ole exception error.

Does anyone know why this won't work and what I can do to get it
working?

It appears that executing WMIC via Exec causes the Exec method to behave
__very__ badly to the point of being unusable, even for a WSH hosted script.

I'd chalk it up as an unintentional limitation (aka a bug that unlikely to
ever be fixed :-)...

'this first one works fine, just to prove all the plumbing is generally
OK...
'
results = GetSTDOUT("cmd /c echo %date%")
wscript.echo "results:",results
'
'this one...well...I couldn't figure a way to make it work (YMMV)...
'
results = GetSTDOUT("WMIC SERVICE LIST BRIEF")
wscript.echo "results:",results

Function GetSTDOUT(cmd)
wscript.echo "exec of:", cmd
Set objShell = createobject("WScript.Shell")
Set objWshScriptExec = objShell.Exec(cmd)
Set objStdOut = objWshScriptExec.StdOut

n = 0
Do
WScript.Sleep 1000
n=n+1 : wscript.echo n, objWshScriptExec.Status
'
'no matter how long you wait for WMIC, Status never goes to 1
'so bail after 10 seconds so we don't hang forever :-)
'
If n > 9 Then Exit Do
Loop while objWshScriptExec.Status = 0
'
'if you *don't* terminate, the ReadAll hangs...
'
objWshScriptExec.Terminate
'
'...but it doesn't help - ReadAll returns nothing :-(
'
line = objStdOut.ReadAll
'
'don't think this will help...
' results = GetSTDOUT("cmd /c WMIC SERVICE LIST BRIEF")
'...it is even worse - even after the Terminate, the ReadAll hangs
'
GetSTDOUT = line
End Function


--
Michael Harris
Microsoft.MVP.Scripting


.



Relevant Pages

  • Re: [SLE] bash script
    ... Only a good habit to take: and this one saved my life a few times! ... someone said that "exec" was not needed. ... Yet, it is a tiny bit faster to use "exec", because the called program will then _replace_ the shell, and when the program will terminate, that will be the end of the story. ...
    (SuSE)
  • Re: Why I need to click twice to destroy a top level window?
    ... 'exec' in TCL does not terminate the current process ... like e.g. in sh or perl. ...
    (comp.lang.tcl)