Jump to content

[Run] Manage Process Hidden


rmassip
 Share

Recommended Posts

Hi all,

I would like to know if it is possible to manage a program in the background, that is, the same actions (click, send, ...) that you would do with AutoIt, but without the user seeing it.

I have seen that with the "Run" function you can indicate the flag @SW_HIDE so that the process is not shown.

I have made a POC with the 'notepad' example.
Without adding the @SW_HIDE flag (in second line) it works correctly:
1) open notepad
2) write text
3) save it to a file

But adding the @SW_HIDE, it waits for the notepad screen (obviously), in the line 5, WinWaitActive ("[CLASS: Notepad]").

Is there a way to interact with an open program in @SW_HIDE?

thank you very much!!

 

; Run Notepad
Local $iPID = Run("notepad.exe","" ), @SW_HIDE )

; Wait for the Notepad to become active. The classname "Notepad" is monitored instead of the window title
WinWaitActive("[CLASS:Notepad]")

; Now that the Notepad window is active type some special characters
Send("Sending some special characters:{ENTER 2}")

; Do it the first way
Send("First way: ")
Send("{!}{^}{+}{#}")
Send("{ENTER}")

; Do it the second way (RAW mode, notice the second parameter of Send is 1)
Send("Second way: ")
Send("!^+#", 1)

Send("{ENTER}{ENTER}Finished")

; Finished!

; Save File
Send("!A{DOWN}G{ENTER}")
Sleep(500)
Send("file.txt{ENTER}")

 

Link to comment
Share on other sites

  • Moderators

Welcome to the forum. Take a look at the Control* Commands in the Help File. If you grab the element that you want to interact with on the GUI, and use ControlClick, ControlSend, etc. rather than just clicks and sends, it won't matter if the window is visible or not.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Thank you very much for the answers! 😄

I have tried  @JLogan3o13 's solution, and it works roughly. I have managed to send invisible notepad, the problem is the applications that do not have clear controls hehe 

I leave the code here in case it works for someone:

#include <AutoItConstants.au3>

; Run Notepad
;Local $iPID = Run("notepad.exe","")
Local $iPID = Run("notepad.exe","", @SW_HIDE )


; Wait for the Notepad to become active. The classname "Notepad" is monitored instead of the window title
;WinWaitActive("[CLASS:Notepad]")
Local $hWnd = WinWait("[CLASS:Notepad]")

ConsoleWrite("*** Handler: " & $hWnd)

; Now that the Notepad window is active type some special characters
ControlSend($hWnd, "", "Edit1", "Sending some special characters:{ENTER 2}")


; Do it the first way
ControlSend($hWnd, "", "Edit1", "First way: ")
ControlSend($hWnd, "", "Edit1", "{!}{^}{+}{#}")
ControlSend($hWnd, "", "Edit1", "{ENTER}")

; Do it the second way (RAW mode, notice the second parameter of Send is 1)
ControlSend($hWnd, "", "Edit1", "Second way: ")
ControlSend($hWnd, "", "Edit1", "!^+#", 1)

ControlSend($hWnd, "", "Edit1", "{ENTER}{ENTER}Finished")

; Finished!

; Save File
ControlSend($hWnd, "", "Edit1", "!A{DOWN}G{DOWN}{ENTER}")   ;Menú navigate (spanish letters, english  maybe F-S)
Sleep(2000)

Local $hWndSave = WinWait("[CLASS:#32770]")                 ;Save As Diaglog class Win10
Sleep(2000)
ControlSend($hWndSave, "", "Edit1","file_9.txt{ENTER}")

;Close
WinClose("[CLASS:Notepad]")

 

Thanks also to @JockoDundee for this idea, it is very original!
I have to do something similar, because when I load data, a "PD" (pending) appears in the application within a yellow box. Currently I am solving it with a PixelSearch in a bucle, but if I make the windows invisible, I am afraid that it will not work for me, so your idea even being a "workaround" may work for me hehe

Local $ aCoord = PixelSearch (0, 300, 20, 320, 0xFFFF00, "", "", $ hWnd) ;PD Yellow

Thanks for the help! I'm still rookie but I already have my first scripts, AutoIt looks very good 🤓

PD.png

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...