Jump to content

Script not working Via Psexec


Recommended Posts

Hi all very new to AutoIT so I wrote up a small script to open a program, enter a password, submit and close the program. The script works 100% when I execute it on the local pc. I am unable to get it to run when attempting it remotely. I use psexec and the .exe can be seen in the task manager on the target machine but it just stays there forever. Any Ideas as to whats going on?

 

Here is the .au3 script 

; Script Start -

 

ShellExecute("D:\One\onemore\config\blah\blah.exe")

AutoItSetOption('MouseCoordMode', 0)

WinWait(Program – Some Program')

WinActivate(Program – Some Program')

MouseClick('primary', 153, 195, 1, 0)

Send('password')

MouseClick('primary', 294, 196, 1, 0)

WinWait(Program – Some Program)

MouseClick('primary', 634, 13, 1, 0)

Link to comment
Share on other sites

Link to comment
Share on other sites

1 minute ago, Nine said:

Probably the winwait is waiting forever.  Put a timeout to see if this is the case, and an error handling after to ensure you got it right.

Ill give that a whirl, how would I do the error handling?

Link to comment
Share on other sites

Ok I updated the script with timeouts and it works locally. When I attempt to run via ansible using the win_psexec module(interactively or not) I get a false positive. I know its not working because when you submit the last click its supposed to  make a log entry to show a successful login. Any ideas?

 

Updated au3

ShellExecute("D:\One\Onemore \config\blah\blah.exe")
AutoItSetOption('MouseCoordMode', 0)
WinWait("[CLASS:someprogram]", "", 5)
WinActivate(someprogram)
MouseClick('primary', 153, 195, 1, 0)
Send('password')
MouseClick('primary', 294, 196, 1, 0)
WinWait("[CLASS:someprogram]", "", 5)
MouseClick('primary', 634, 13, 1, 0)

 

Edited by Jos
added codebox
Link to comment
Share on other sites

I don't know if you have already done this, but do you use the -i parameter in the psexec command which starts your executable?

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Yes here is my playbook for ansible, return code 0 and it says it’s a success but a false positive due to there begin no long entry on the program. 

---

- hosts: all

  gather_facts: yes

 

  tasks:

    - name: Execute ODT HeartbeatTest

      win_psexec:

        command: D:\Blah.exe \i

        elevated: yes

 

Link to comment
Share on other sites

  • 11 months later...

@NitroMatt Does your application installer support silent installation?  If you can run it where it doesn't require interaction would be best (if the UI) isn't displayed, or if you are scripting the install, using ControlClick functions may be more reliable.

Link to comment
Share on other sites

It doesn't unfortunately, AutoIT was a last resort to package this particular app. Manually running the complied .exe and it runs as expected, the application installs as per the steps in the .au3 file I built.

Problem seems to be invoking the complied installer via Ansible. Can see the compiled installer and the application installer are running in task manager when the required Ansible command runs, just no UI appears so the application install never finishes.

In Ansible have tried win_shell and win_command. Also tried calling the compiled .exe from a PowerShell script and from a .bat but no joy.

Link to comment
Share on other sites

  • 2 weeks later...

the "interactive" switch for PSEXEC is "/i" not "\i" iirc ...

On 3/31/2021 at 10:25 PM, Rumdada said:

 

        command: D:\Blah.exe \i

        elevated: yes

 

Maybe this article of Marc Russinovich https://www.itprotoday.com/windows-server/psexec-explainer-mark-russinovich might be of some help?

 

I'd like to mention to populate your autoit script with local log file writing to see, what's going on:

 

#include <Date.au3>


$Counter = 0

$LOG="C:\temp\my-log-file.txt"
$hLOG=FileOpen($LOG,2+8)

$hLOG=FileWriteLine($hLOG,@ScriptFullPath)
$Counter+=1
;some lines of code
Sleep(2000)
FileWriteLine($hLOG,"Log " & $Counter & @TAB & _NowCalc() & @TAB & @UserName & "\" & @LogonDomain & "@" & @ComputerName)
$Counter+=1
;some lines of code
Sleep(2000)
FileWriteLine($hLOG,"Log " & $Counter & @TAB & _NowCalc() & @TAB & @UserName & "\" & @LogonDomain & "@" & @ComputerName)
$Counter+=1
;some lines of code
Sleep(2000)
FileWriteLine($hLOG,"Log " & $Counter & @TAB & _NowCalc() & @TAB & @UserName & "\" & @LogonDomain & "@" & @ComputerName)
$Counter+=1
;some lines of code
Sleep(2000)
FileWriteLine($hLOG,"Log " & $Counter & @TAB & _NowCalc() & @TAB & @UserName & "\" & @LogonDomain & "@" & @ComputerName)
$Counter+=1
;some lines of code

FileWriteLine($hLOG,"Log " & $Counter & @TAB & _NowCalc() & @TAB & @UserName & "\" & @LogonDomain & "@" & @ComputerName)
$Counter+=1
Sleep(1000);some lines of code

FileWriteLine($hLOG,"Log " & $Counter & @TAB & _NowCalc() & @TAB & @UserName & "\" & @LogonDomain & "@" & @ComputerName)
$Counter+=1
Sleep(5000);some lines of code

FileWriteLine($hLOG,"Log " & $Counter & @TAB & _NowCalc() & @TAB & @UserName & "\" & @LogonDomain & "@" & @ComputerName)
FileWriteLine($hLOG,"------- EOF -----------")

FileClose($hLOG)

 

assuming that you have a folder named "C:\TEMP" on the destination system, and the compiled script is on your local machine at c:\temp\Logging-sample.exe, run PSEXEC using this line:

psexec \\REMOTEHOSTNAME -ih -c c:\temp\Logging-sample.exe -w c:\temp

PsExec v2.2 - Execute processes remotely
Copyright (C) 2001-2016 Mark Russinovich
Sysinternals - www.sysinternals.com


Logging-sample.exe exited on wx-0111 with error code 0.

At the local console of the remote machine follow up the process and the content of the log file:

C:\WINDOWS\system32>tasklist /fi "imagename eq logging-sample.exe"

Abbildname                     PID Sitzungsname       Sitz.-Nr. Speichernutzung
========================= ======== ================ =========== ===============
Logging-sample.exe           81752 Console                    1        10.704 K

C:\WINDOWS\system32>tasklist /fi "imagename eq logging-sample.exe"
INFORMATION: Es werden keine Aufgaben mit den angegebenen Kriterien ausgeführt.

C:\WINDOWS\system32>cd \temp

C:\temp>start .\my-log-file.txt

 

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

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...