aarellan

Commands not executing after "ShellExecute"

15 posts in this topic

#1 ·  Posted

Hi all,

New member/AutoIT user here. I'm trying to create a simple automation script that will launch a setup file I've created for Kaspersky. When I run the script below, the ShellExecute function runs as intended and brings up my setup file, but does not proceed with any further commands. I've noticed that after my setup file pops up, the script terminates itself shortly afterwards (no Script Pause, it just exits). I've referenced help documentation on AutoIT's site for these commands (WinWaitActive and ControlClick), and it seems like I have the syntax correct. I obtained the information in the commands using the WindowInfo tool. What am I doing wrong here?

2017-07-12_11-00-03.bmp

Share this post


Link to post
Share on other sites



#2 ·  Posted

Welcome,

Please put the code you like to show in a CodeBox (<>) with cut&Paste in stead of adding an image as that makes it much harder to help.
If the code just ends without any errors it means the WinWaitActive(s) were successful and ControlSend(s) were performed.

Why aren't you using the Silent option for the installer in the first place as that should be much less error prone? 
Isn't the installer asking for Admin level or are you shelling the script at that level already?

Jos

 


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#3 ·  Posted

Hi Jos,

Thanks for the tip about the CodeBox, didn't realize that was an option:

#RequireAdmin
ShellExecute  ("setup.exe", "", "\\bbna-kasp\KLSHARE\PkgInst\Install Endpoint Security (10.3.0.6294) and Network Agent (10.4.343)")
WinWaitActive ("Installing Kaspersky Lab applications", "")
ControlClick ("Button1", "Start installation", 6)
WinWaitActive ("Installing Kaspersky Lab applications", "Close", 2)
ControlClick ("Button1", "Close", 2)
Exit

I've tried to utilize a silent option with the setup installer, but I can't get that to work either. That's why I wanted to try out AutoIT to automate the mouse clicks I need.

It doesn't seem like any of the commands besides ShellExecute are being performed. When my installation window pops up, the "Start installation" button is not clicked, even though I specified that step immediately afterwards. In its current configuration, shouldn't the script wait until my installation window is active, then proceed to click the button I specified? Or did I code that portion wrong?

The installer does require administrative privileges by default, I just read a tip from another post that said including this line may resolve my command execution problems, but it doesn't. When I remove this line, the same issue occurs. 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Well, your ControlClick() statements are wrong for sure now I look at them. The first 2 parameters should be Title and Text, which are missing!

Jos

Edited by Jos
1 person likes this

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#5 ·  Posted

Ahh, that was the problem. I had the title confused with the name of the button I was referencing. I changed that to my installation window title and it worked like a charm. Thanks!

Share this post


Link to post
Share on other sites

#6 ·  Posted

Hi, 
I have similar problem. Looks like I cannot attach my code to correct window.

#include <MsgBoxConstants.au3>

Func Example ()

   ;$HWND_Installer = WinWait("Installer Language", "Please select a language.", 10)
   $HWND_Installer = WinGetHandle("Installer Language", "Please select a language.")

   $btnOK = ControlGetHandle($HWND_Installer, "", "Button1")
   ControlClick ( $HWND_Installer, "", $btnOK)
   ControlClick ("Installer Language", "Please select a language.", $btnOK)

   ;MsgBox (0, "Installer", "$HWND_Installer = " & $HWND_Installer & @CRLF & "$btnOK = " & $btnOK)

   WinClose($HWND_Installer)
   WinClose("Installer Language", "Please select a language.")

EndFunc   ;==>Example

Example()

I ran my installer before calling this function, and it is already displayed on the desktop. When I de-comment MsgBox fragment, it correctly displays hWnd variables for my installer, the same I can see with AutoIt Info tool.
But ControlCLick does not work, as well as WinClose (tried with hWnd and title as you can see from code). Please help. I attach my screen with installer window.

Installer.png

Share this post


Link to post
Share on other sites

Yes. (If I understand your question correctly).
I run program and script with the same user on PC.

Share this post


Link to post
Share on other sites

Here is my call of ShellExecute before trying to ControlClick(). Nothing special:
ShellExecute ("Installer.exe", @ScriptDir )

Share this post


Link to post
Share on other sites

#10 ·  Posted

What about you show the whole script as you have now just posted bits and pieces which don't make it clear to me?
You could very well have some sort of timing error, meaning the application is still starting when you perform already functions for it.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#11 ·  Posted

Here it is: 
 

#include <MsgBoxConstants.au3>

Func Example ()
   Local $iPID = ShellExecute ("Installer.exe", @ScriptDir )

   $HWND_Installer = WinWait("Installer Language", "Please select a language.", 10)
   ;$HWND_Installer = WinGetHandle("Installer Language", "Please select a language.")

   $btnOK = ControlGetHandle($HWND_Installer, "", "Button1")
   ControlClick ( $HWND_Installer, "", $btnOK)
   ControlClick ("Installer Language", "Please select a language.", $btnOK)

   ;MsgBox (0, "Installer", "$HWND_Installer = " & $HWND_Installer & @CRLF & "$btnOK = " & $btnOK)

   WinClose($HWND_Installer)
   WinClose("Installer Language", "Please select a language.")

EndFunc   ;==>Example

Example()

 

Share this post


Link to post
Share on other sites

#12 ·  Posted

I can also provide a link to download installer program if needed.

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Jos - I realized that you were right about administrative rights. 
Now I built .au3 file into .exe and called right-click > Run as administrator - it works. Buttons are clicked and window closes. 

When asking a question, I just used F5 button (Tools > Go) in SciTE editor to run. Is it possible to run the script with administrative rights without building it into EXE?

Edited by Elena

Share this post


Link to post
Share on other sites

#15 ·  Posted

Super, it works! Thank you.

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