[Wtr-general] Killing several processes open?
Robert Gilmore
gilmore.robert at gmail.com
Mon Apr 10 00:31:37 EDT 2006
I'm far from an expert - but I've been using WMI a lot lately in the C#
world so figured I'd try using it via WIN32OLE - it seems to work. It's much
simpler than using Win32API.
require 'win32ole'
mgmt = WIN32OLE.connect('winmgmts:\\\\.')
mgmt.InstancesOf("win32_process").each{ |proc|
puts proc.name
}
mgmt.ExecQuery("Select * from Win32_Process Where Name = 'Notepad.exe'").each{
|item|
item.Terminate()
}
On 4/9/06, Rodrigo Julian Martin <rodrigo.martin at enratio.com> wrote:
>
> Hi!
>
> I'm trying to make a code for killing all running processes that i need to
> close.
> I've this function for javascript:
>
> [code]
> function KillProcess(PName)
> {
> var Count = 0;
> var p = Sys.WaitProcess(PName, 1000, 1);
>
> while (p.Exists) {
> Count++;
> p.Terminate();
> while (p.Exists) Delay(50);
> p = Sys.WaitProcess(PName, 1000, 1);
> }
> return Count;
> }
> ...
> KillProcess("Excel");
> ...
> [/code]
>
>
> Is there a way to do this in ruby+watir? I was reading about the
> Sys::Process, but I don't find the way. I'm running on a Windows 2000.
> I really don't want to end up making a bat file =(..
>
> any help would be really appreciated
>
> Cheers from Argentina, and Thanks in advance!
>
>
> Rodrigo Julian Martin
>
> _______________________________________________
> Wtr-general mailing list
> Wtr-general at rubyforge.org
> http://rubyforge.org/mailman/listinfo/wtr-general
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/wtr-general/attachments/20060409/9d7aed5d/attachment.html
More information about the Wtr-general
mailing list