keohler

Run Program Without Transfering Focus

5 posts in this topic

Good Evening,

I'm updating a script that while running updates messages on the users screen. Here is what we currently have:

_Log('Status Update Here', 'True')

Func _Log($Message, $Show)

Local $LogFileName = 'The Log File Name Would go Here' ;The name of the log file

Local $MessageCommand = 'The On Screen Message App Name and Path go Here' ; The on screen message app

Local $Now

If $Show == 'True' Then

$Command = StringFormat('%s "%s"', $MessageCommand, $Message) ; create the message command to be run

Run($Command) ; Run the command

EndIf

If StringLen($Message) > 1 Then ; If the message isn't blank

$Now = _Now() ;Get current Time and Date

$Command = StringFormat('cmd.exe /c Echo %s - %s 1>>%s', $Now, $Message, $LogFileName) ;create the string to go in the log file

RunWait($Command, '', @Sw_Hide) ; Run the command to write the string to the log

EndIf

EndFunc

Is there any way to run the command in red without transfering focus to it? Our users would like to have the messages updated but not have it take focus away from what they are doing.

Any help would be greatly appreciated. I have a lot of experience with WinBatch but I am very new to AutoIT. overall, I am very impressed and glad we made the move.

Thank you!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

sooo, this is a command prompt you do/don't want to display?

I've looked up some stuff recently, and found that you can conditionally create a vbs file, that calls a bat file through powershell, and doing that stops the cmd from displaying (so no loss of focus)...probably easier ways to do so though.

Here is the contents of the vbs:

command = "powershell.exe -nologo -command C:Automationnew.bat"

set shell = CreateObject("WScript.Shell")

shell.Run command,0

edit: on another read through, this is probably isn't what you need.

In your script, prior to the 'run', you can get the '[active]' window, using wingethandle, and then after the run command, you can make the handle returned active through winactivate

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

orelse very simple

use the macro @SW_SHOWNOACTIVATE when creating the window

Hope it Helps :)

Example

Run ('Notepad.exe',@WorkingDir,@SW_SHOWNOACTIVATE)

Br

PXL


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

PhoenixXL, your siggestion worked perfectly. I modified the Message App from @SW_Show to @SW_ShowNoActive so that anytime it is called, it does not take the focus. Thank you for the assistance, it is greatly appreciated!

Share this post


Link to post
Share on other sites

Hello,

I'm trying to to the following 

 $iPID = Run(@ProgramFilesDir & '\Mozilla Firefox\firefox.exe "http://google.com"', '', @SW_SHOWNOACTIVATE
or
 $iPID = Run(@ProgramFilesDir & '\Mozilla Firefox\firefox.exe "http://google.com"', '', @SW_MINIMIZE

But Firefox still takes over the focus. 
Is it correct approach?  (I'd like to open Firefox without changing focus. So if user is typing mail in Outlook he can go on with it) 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now