Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > How do I find a Windows process with a specific Window Title?

Reply
Thread Tools

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

 
 
Paul
Guest
Posts: n/a
 
      03-05-2007
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
}
----

 
Reply With Quote
 
 
 
 
Jan Svitok
Guest
Posts: n/a
 
      03-05-2007
On 3/5/07, Paul <(E-Mail Removed)> 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...

 
Reply With Quote
 
 
 
 
Daniel Berger
Guest
Posts: n/a
 
      03-05-2007
On Mar 5, 10:12 am, "Paul" <(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
how can I find out the process ids with a process name herman Python 5 09-04-2007 11:05 PM
Opening a new browser window to a specific size without the menu bar and address window. UJ ASP .Net 2 06-27-2005 08:21 PM
redirect traffic on specific ip to specific interface mimiseh Cisco 3 06-05-2005 09:14 PM
How do you make sure a frameset is loaded? I'm trying to open a frameset in a new window which shows a specific html page in a specific frame ck388 Javascript 1 09-24-2003 08:32 PM



Advertisments