[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How do I find a Windows process with a specific Window Title?

Paul

3/5/2007 5:12:00 PM

Hi there. I'm still kind of new to scripting with Ruby. I have
written a small Ruby/Fox app that displays a message in a window at
regular intervals. The 'regular intervals' part is done using the
Windows Task Scheduler.

I'd like only one message window to appear at a time though. What I
am seeing is that if I step away from my computer for a few hours,
there can sometimes be several of these popup windows on the desktop.

I'd like the app to check (when it first starts up) to see if there
are any other instances of this popup window on the desktop, and if
so, just exit... or maybe kill the other window's process (I haven't
decided which yet).

I've found a few snippets of code that let me find the windows
processes and kill them (e.g. see below), but they don't work for me.
My popup window falls under the process name 'ruby.exe' even if the
window title says 'foo'.

Can someone please tell me if this is possible? How can I use Ruby to
find a specific window with a specific title? I don't want to just
kill all the ruby processes in case some other scripts are already
running that should be.

----
require 'win32ole'

mgmt = WIN32OLE.connect('winmgmts:\\\\.')
mgmt.InstancesOf("win32_process").each{ |proc|
puts proc.name
}

mgmt.ExecQuery("Select * from Win32_Process Where Name =
'ruby.exe'").each { |item|
# item.Terminate()
puts 'item = ' + item.to_s
}
----

4 Answers

Jano Svitok

3/5/2007 6:17:00 PM

0

On 3/5/07, Paul <tester.paul@gmail.com> wrote:
> Hi there. I'm still kind of new to scripting with Ruby. I have
> written a small Ruby/Fox app that displays a message in a window at
> regular intervals. The 'regular intervals' part is done using the
> Windows Task Scheduler.
>
> I'd like only one message window to appear at a time though. What I
> am seeing is that if I step away from my computer for a few hours,
> there can sometimes be several of these popup windows on the desktop.
>
> I'd like the app to check (when it first starts up) to see if there
> are any other instances of this popup window on the desktop, and if
> so, just exit... or maybe kill the other window's process (I haven't
> decided which yet).
>
> I've found a few snippets of code that let me find the windows
> processes and kill them (e.g. see below), but they don't work for me.
> My popup window falls under the process name 'ruby.exe' even if the
> window title says 'foo'.
>
> Can someone please tell me if this is possible? How can I use Ruby to
> find a specific window with a specific title? I don't want to just
> kill all the ruby processes in case some other scripts are already
> running that should be.
>
> ----
> require 'win32ole'
>
> mgmt = WIN32OLE.connect('winmgmts:\\\\.')
> mgmt.InstancesOf("win32_process").each{ |proc|
> puts proc.name
> }
>
> mgmt.ExecQuery("Select * from Win32_Process Where Name =
> 'ruby.exe'").each { |item|
> # item.Terminate()
> puts 'item = ' + item.to_s
> }

You can for sure use AutoIt or AutoIt's dll or AutoIt's COM object to
find & kill the window.
Although there should be a more straightforward way...

Daniel Berger

3/5/2007 6:18:00 PM

0

On Mar 5, 10:12 am, "Paul" <tester.p...@gmail.com> wrote:
> Hi there. I'm still kind of new to scripting with Ruby. I have
> written a small Ruby/Fox app that displays a message in a window at
> regular intervals. The 'regular intervals' part is done using the
> Windows Task Scheduler.
>
> I'd like only one message window to appear at a time though. What I
> am seeing is that if I step away from my computer for a few hours,
> there can sometimes be several of these popup windows on the desktop.
>
> I'd like the app to check (when it first starts up) to see if there
> are any other instances of this popup window on the desktop, and if
> so, just exit... or maybe kill the other window's process (I haven't
> decided which yet).
>
> I've found a few snippets of code that let me find the windows
> processes and kill them (e.g. see below), but they don't work for me.
> My popup window falls under the process name 'ruby.exe' even if the
> window title says 'foo'.
>
> Can someone please tell me if this is possible? How can I use Ruby to
> find a specific window with a specific title? I don't want to just
> kill all the ruby processes in case some other scripts are already
> running that should be.
>
> ----
> require 'win32ole'
>
> mgmt = WIN32OLE.connect('winmgmts:\\\\.')
> mgmt.InstancesOf("win32_process").each{ |proc|
> puts proc.name
>
> }
>
> mgmt.ExecQuery("Select * from Win32_Process Where Name =
> 'ruby.exe'").each { |item|
> # item.Terminate()
> puts 'item = ' + item.to_s}
>
> ----

There's no way to do that via Win32_Process that I can see. There may
be another WMI class that provides that information, but I don't know
what it is.

It's possible to get the information via GetWindowText(), which you'll
have to use in conjunction with other Windows functions.

Regards,

Dan

The Big Dog

12/11/2010 2:29:00 AM

0

In article
<7aae4a7b-f733-48ca-a103-ff12261be2d8@t8g2000prh.googlegroups.com>,
Siobhan Medeiros <sbm2010@telus.net> wrote:

> On Dec 9, 9:01?pm, Tracey12 <tracey12em...@gmail.com> wrote:
> > I am shocked. ?Bill O'Reilly trusts government will not step on the
> > First Amendment so much, he has now called for a federal police force
> > to patrol / control the Internet because of Julian Assange.
> >
> > This was announced on Dec. 9th, 2010 on Bill's Fox News evening
> > program.
> >
> > Is Bill O'Reilly working with the feds to promote the FCC's take-over
> > of the Internet?
>
> He's an idiot. The internet isn't just in America. Only a "global"
> police force could patrol it - and that would require a one-world
> government, something that rightards supposedly despise.

Have you heard of China?

Iran?

N. Korea?
--
Barack Obama: the first fictional character ever elected President of the USA.

Nobody

12/11/2010 7:24:00 AM

0

Shannon Mitchell wrote:

> On Dec 9, 9:01?pm, Tracey12 <tracey12em...@gmail.com> wrote:
>> I am shocked. ?Bill O'Reilly trusts government will not step on
>> the First Amendment so much, he has now called for a federal
>> police force to patrol / control the Internet because of Julian
>> Assange.
>>
>> This was announced on Dec. 9th, 2010 on Bill's Fox News evening
>> program.
>>
>> Is Bill O'Reilly working with the feds to promote the FCC's
>> take-over of the Internet?
>
> He's an idiot.

So are you it seems. Notice the repplies you get.