View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
urkec urkec is offline
external usenet poster
 
Posts: 131
Default Cannot kill a WINWORD.EXE instanciation - Sorry for reposting

"Patrick Penet" wrote:

I tried your code because it looks
quite new to me. (And I'm out of idea).

But can you indicate how I should define
theses variables objSWbem, colProcesses and
colProcesses.

I drove some tests at several places :

Public objSWbem As Object
Public colProcesses As Object
Public objProcess As Object

And also I defined them as variant.

But no chance : no errors at all, and the
!!%('$;!+) WINWORD.EXE is still there.





If I want to use early binding, I add reference to "Microsoft WMI Scripting
V2.1 Library". Where did you put the code? This code is supposed to kill all
WINWORD.EXE processes, does it work if you put it in a standard module and
run the sub manually with a WINWORD.EXE process running?


Sub WMITest()

Dim objSWbem As SWbemServices
Dim colProcesses As SWbemObjectSet
Dim objProcess As SWbemObject

Set objSWbem = GetObject("winmgmts:root\cimv2")
Set colProcesses = objSWbem.ExecQuery _
("Select * From Win32_Process " & _
"Where Name='WINWORD.EXE'")

For Each objProcess In colProcesses
Debug.Print objProcess.CommandLine
Debug.Print objProcess.ExecutablePath
objProcess.Terminate
Next

End Sub


Maybe you could also try using Shell function with Taskkill command. I am
not very good with Command Prompt, but I think that would be the simplest way
to kill a process.


--
urkec