Re: OLE error
- From: "Michael Harris \(MVP\)" <mikhar.at.mvps.dot.org>
- Date: Fri, 9 Mar 2007 17:21:28 -0800
? ---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
.
- Follow-Ups:
- Re: OLE error
- From: Michael Harris \(MVP\)
- Re: OLE error
- References:
- OLE error
- From: donald_woeltje
- OLE error
- Prev by Date: OLE error
- Next by Date: Re: OLE error
- Previous by thread: OLE error
- Next by thread: Re: OLE error
- Index(es):
Relevant Pages
|