# Re: Killing Win32 process

**URL:** <https://www.ruby-forum.com/t/re-killing-win32-process/139561>\
**Category:** Ruby\
**Created:** [June 4, 2008, 11:34pm UTC](https://www.ruby-forum.com/t/re-killing-win32-process/139561 "2008-06-04T23:34:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![McLaughlinS\_James\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f04885/32.png) [@McLaughlinS\_James\_T](https://www.ruby-forum.com/u/McLaughlinS_James_T)\
**Post date:** [June 4, 2008, 11:34pm UTC](https://www.ruby-forum.com/t/re-killing-win32-process/139561/1 "2008-06-04T23:34:58Z")

</div>

Qq  
Jamie McLaughlin  
SAIC  
Office: 703-292-6307  
Mobile: 571-263-2528

----- Original Message -----  
From: removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: ruby-talk ML [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Sent: Tue Jun 03 05:46:19 2008  
Subject: Killing Win32 process

Hi,

I tried the following code snippet to kill a Win32 process:

def killQTP  
wmi = WIN32OLE.connect(“winmgmts://”)  
processes = wmi.ExecQuery(“select \* from Win32\_process”)  
for process in processes do  
if process.Name.include? “QTPro.exe” then  
puts “Name: #{process.Name}”  
puts “Process ID: #{process.Pid}”  
puts process.Terminate  
elsif process.Name.include? “star.exe” then  
puts “Name: #{process.Name}”  
puts “Process ID: #{process.Pid}”  
puts process.Terminate  
end  
end  
puts “done killing QTP”  
end

But the process is not getting killed when I execute the above and  
simply gives “exit code: 0”

Can anyone help in case I am missing anything to execute the above code  
or is there any other way of killing a Win32 process?

## Thanks, Anukul

Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
