SWbemObectEx:-2147217406 ERROR

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
theonex
Junior Coder
Posts: 44
Joined: Thu May 10, 2012 12:32 pm

SWbemObectEx:-2147217406 ERROR

Post by theonex » Tue Sep 19, 2017 10:08 pm

hello

i have fallen victim to the following error SWbemObectEx:-2147217406. I am not sure if it can be replicated but i get it quiet often when i run some of my scripts. I have attached a copy of a simplified script that also gives this error.

Code: Select all

VBSTART
Sub killProcess(pgm)
  set wmi = getobject("winmgmts:")
  sQuery = "select * from win32_process " & "where name='" & pgm & "'"
  set processes = wmi.execquery(sQuery)
  for each process in processes
    process.terminate
  next
End Sub
VBEND

//EventTimer part of the script
Let>timerFlag=0

Let>TimePeriod=20
Timer>StartTime
OnEvent>Custom,EventTimer,TimedOut,ResultEvent
SRT>EventTimer
  Timer>EndTime
  Let>TotalTime={(%EndTime%-%StartTime%)/1000}
  If>%TotalTime%>%TimePeriod%
    Let>TimedOut=True
  EndIf
END>EventTimer
SRT>ResultEvent
  //Start process that will wait for this script to exit
  //then restart this script
    
  //Do any closing processes needed before exit

ProcessExists>iexplore.exe,iexploreExists
If>iexploreExists=True
VBRun>Killprocess,iexplore.exe
WaitProcessTerminated>iexplore.exe
wait>2

Message>process not completed
wait>5

Endif
  Exit>0
END>ResultEvent



//Stuff in your current script
//RunProgram>C:\Windows\notepad.exe
IECreate>0,IE[0]
WindowAction>1,Internet Explorer*

IENavigate>%IE[0]%,http://help.mjtnet.com/,ie_res
IEWaitDocumentComplete>%IE[0]%,ie_res
IEWait>IE[0]
wait>2
IEWaitDocumentComplete>%IE[0]%,ie_res
IEWait>IE[0]
wait>2
Timer>StartTime

wait>1
Timer>StartTime


//Stuff in your current script
GetTextInit
GetWindowTextEx>Macro Scheduler Knowledge Base - Internet Explorer,result
WaitScreenText>Macro Scheduler is the best
wait>2
Timer>StartTime



//Stuff in your current script
Message>process completed!! :)
wait>5
Timer>StartTime
try running the code more than once if you don`t get the error first time.

or maybe i am doing something wrong.

please share. thank you

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: SWbemObectEx:-2147217406 ERROR

Post by Marcus Tettmar » Tue Sep 26, 2017 8:45 am

I think there's a chance your event subroutine is triggering while IE is still active but being killed, so then your vbscript which kills it will cause an error.

Any reason why you're using VBScript code to kill a process when you could just do:

KillProcess>iexplore.exe

https://www.mjtnet.com/manual/killprocess.htm

Also consider checking the process exists before calling KillProcess.

But if you must use VBScript you could ignore errors.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts