I have a routine that will check to see if MS-Excel is running and if so, terminate it.
It works about 95% of the time but I get an intermittent error pop up every now and then.
Here is the code I use:
- Code: Select all Expand view
FUNCTION WMIService()
static oWMI
local oLoc
if oWMI == nil
oLoc := CREATEOBJECT( "wbemScripting.SwbemLocator" )
oWMI := oLoc:ConnectServer()
endif
return oWMI
FUNCTION KillExcel()
local oWmi, oList, oProc
IF UPPER(ALLTRIM( cWinVersion() )) = "VISTA"
Return Nil
ENDIF
Syswait(.01)
oWmi := WmiService()
oList := oWmi:ExecQuery( "select * from Win32_Process" )
for each oProc in oList
if oProc:Name = "EXCEL.EXE"
oProc:Terminate()
Syswait(1)
endif
next
return nil
The error that pops up is:
Error description: Error wbemScripting.SwbemLocator/16389 E_FAIL: CONNECTSERVER
Args:
Stack Calls
===========
Called from: win32ole.prg => TOLEAUTO:CONNECTSERVER(0)
Called from: EzSat.prg => WMISERVICE(20820)
Called from: EzSat.prg => KILLEXCEL(20831)
Anyone have any ideas as to why I get this error?