# Setting Focus on Console Window

**URL:** <https://www.ruby-forum.com/t/setting-focus-on-console-window/131528>\
**Category:** Ruby\
**Created:** [March 11, 2008, 12:46am UTC](https://www.ruby-forum.com/t/setting-focus-on-console-window/131528 "2008-03-11T00:46:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hiriumi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/76d3ee/32.png) [@hiriumi](https://www.ruby-forum.com/u/hiriumi)\
**Post date:** [March 11, 2008, 12:46am UTC](https://www.ruby-forum.com/t/setting-focus-on-console-window/131528/1 "2008-03-11T00:46:15Z")

</div>

Hello,  
I’m having an issue with having a focus on the Ruby invoked console  
window on Windows platform when I start the process from one of the  
Scheduled Tasks.

I have a Ruby script that gets kicked off by Scheduled Task. So the  
Run command looks like this: C:\ruby\bin\ruby.exe D:\Temp\HelloRuby.rb

Now when I right click on the scheduled task and choose Run, the  
console window doesn’t have the focus. I looked for ways to set the  
focus on the console window using kernel32 and stuff, but I haven’t  
been able to find a solution.

Does anyone know how best I can solve this problem?

TIA

---

<div class="post-metadata">

**Author:** ![hiriumi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/76d3ee/32.png) [@hiriumi](https://www.ruby-forum.com/u/hiriumi)\
**Post date:** [March 11, 2008, 7:07pm UTC](https://www.ruby-forum.com/t/setting-focus-on-console-window/131528/2 "2008-03-11T19:07:05Z")

</div>

require ‘win32ole’  
wsh = WIN32OLE.new(‘WScript.Shell’)  
wsh.AppActivate(“name of the window”)

I am not sure I understood your question 100% , but if I am ok with 50%  
It may help you.

-ronnie.

---

<div class="post-metadata">

**Author:** ![hiriumi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/76d3ee/32.png) [@hiriumi](https://www.ruby-forum.com/u/hiriumi)\
**Post date:** [March 26, 2008, 12:27am UTC](https://www.ruby-forum.com/t/setting-focus-on-console-window/131528/3 "2008-03-26T00:27:47Z")

</div>

Ah, that’s cool. I never thought of using WSCript.Shell. Thanks!

On Mar 11, 11:06 am, Rodrigo B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
